Jump to content

Cube Texture reflection size


gamefan
 Share

Recommended Posts

Great post - lots to learn here...

This is one of those days and this topic in particular by which my understanding of several processes in BJS has taken a leap in understanding how to manage reflections efficiently. I have loads of work to do, yet I find myself spending time I don't have to reconcile the many Playground examples posted here today.

I just hope I save enough time to actually get my work done.

DB

Link to comment
Share on other sites

This is the current computation:

https://github.com/BabylonJS/Babylon.js/blob/7317ed822e3e2d52a44966fa4d2fdc3b0a91291a/src/Shaders/ShadersInclude/reflectionFunction.fx#L42

So you suggest to replace it by this, correct?

vec3 viewDir = worldPos.xyz - vEyePosition;

mat4 reflectionMatrix = mat4(-1.,0.,0.,0.,0.,-1.,0.,0.,0.,0.,-1.,0.,0.,0.,0.,-1.);

vec3 coords = reflect(normalize(worldPos.xyz * 3.141592653589793 * length(viewDir) *.1 -
vEyePosition.xyz),worldNormal.xyz);

return vec3(reflectionMatrix * vec4(coords, 0));

So what is 0.1 here?

Link to comment
Share on other sites

Wow, I am really glad a lot is happening here.. Too bad my understanding of the babylonjs internals is very little. I hope to learn very soon.

And I think its going to work for probes as well, adam got it working in his playgrounds. Nice :D

Link to comment
Share on other sites

11 hours ago, Deltakosh said:

where is the LocalCorrect in DefaultShader

 float3 viewDirWS = normalize(input.viewDirInWorld);
     float3 normalWS = normalize(input.normalInWorld);
     float3 reflDirWS = reflect(viewDirWS, normalWS);
     // Get local corrected reflection vector.
      float3 localCorrReflDirWS = LocalCorrect(reflDirWS, _BBoxMin, _BBoxMax,
                                                      input.vertexInWorld, _EnviCubeMapPos)
     // Lookup the environment reflection texture with the right vector.
    reflColor = texCUBE(_Cube, localCorrReflDirWS);

it is not Exactly what i append but very close to that

in localCorrect change the world pos and cube Map Pos at last with control min and max 

and after result it change ViewDirection i dont know about _BBoxMin and _BBoxMax (BindingBOX ? )

but we r not correct that

we have computeReflectionCoords this maybe calculate that but i know this not have Distance  parameters because we don't send any parameter about that

we just have ' vec4(vPositionW,1.0) '     ' normalW '

 // Find the ray intersection with box plane
    float3 invOrigVec = float3(1.0,1.0,1.0)/origVec;
    float3 intersecAtMaxPlane = (bboxMax - vertexPos) * invOrigVec;
    float3 intersecAtMinPlane = (bboxMin - vertexPos) * invOrigVec;
    // Get the largest intersection values (we are not intersted in negative values)
    float3 largestIntersec = max(intersecAtMaxPlane, intersecAtMinPlane);
    // Get the closest of all solutions
   float Distance = min(min(largestIntersec.x, largestIntersec.y), largestIntersec.z);
    // Get the intersection position
    float3 IntersectPositionWS = vertexPos + origVec * Distance;
    // Get corrected vector
    float3 localCorrectedVec = IntersectPositionWS - cubemapPos;
    return localCorrectedVec;

 

Link to comment
Share on other sites

Hello,

The unity way is one  good trade off perf vs quality for local reflections and the one used in a few engines for local cube map. This works nicely without magic numbers.

http://www.babylonjs-playground.com/#1NP9BY#19

This would nevertheless require to be in another #define to avoid the cost of the computation in none local reflection and also be applied to refraction.

Hope that could help,

 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...