Jump to content

Cube Texture reflection size


Recommended Posts

Hi again forum,

From the many great features I have learned, I think that render target texture is the best thing I have come across yet. The ability to produce dynamic live reflections is really awesome. But there is one thing that bugs me. And yes, I have a playground too :)


You will see I have added a cube to the reflection and refraction playground. While the reflection in the sphere looks realistic, in the cube it doesn't. As you will move the camera away from cube, the size of the clouds don't change. It always renders the same amount of texture(the sizes of the meshes in the renderList don't change) regardless of where the camera is from the mesh. Compare that to a mirrorTexture , once you have the mirrorPlane defined, the reflection is lifelike. Moving away and close to mirror gives accurate results. Is there some setting to have the cube texture behave like that on a cube?

Link to comment
Share on other sites

@Deltakosh  Dynamic cube maps are those generated by reflection probes?

I am using them but the distance issue is there on them too. Using mirrors is alright for planes but for complex geometry it becomes really difficult. If the cube maps some how gave mirror like results it would be the NEXT LEVEL. B)

Link to comment
Share on other sites

@Deltakosh May be I will better be able to explain with another playground. Allow me some time to make one. Currently caught up in work. What I want is that complex geometries(like cube) and not just planes have real time true to size reflections with probes(cubeTexture). I am not sure if this is even theoretically possible, but any result close enough would also do. Currently cubeTexture is the best thing I can see for doing this, but it doesn't scale based on mesh's distance from camera.

@NasimiAsl Great. I am eager to see the results.

Link to comment
Share on other sites

22 hours ago, gamefan said:

I am eager to see the results.

@gamefan http://www.babylonjs-playground.com/#1NP9BY#10

see this and say is that your wanted result or not

** this is not final answer




description : new Reflect Shader  : i comment with [new changes] all i change

vec3 direction = normalize(
     wpos /*world position*/ 
     * 3.141592  /* [new changes] PI */
     *length(camera-wpos) /*  [new changes]  append this part for control zoom in reflect */
     *0.01 /* [new changes] i dont know why this is 0.01 :) i try some number and find this  */

vec3 coords = reflect(direction,nrm) ;
vec3 cubeUV = vec3(refMat*vec4(coords,0.));
result = textureCube(cubeRef_0,cubeUV,0.);

about "0.01"  this is very lovely parameter it work same as perspective of reflect i think if we can find any relation between camera fav and this it can be make a reality result

Link to comment
Share on other sites

@Deltakosh I have a playground: http://www.babylonjs-playground.com/#1NP9BY#13

There are two large cubes one with reflection probe and one with mirror Textures. Its difficult to explain in words. The reflection (or at least perceived) in cube with probe reflection, gets bigger and bigger as the camera moves away from the mesh. I think whatever cubeTexture is doing here ,it should be doing the inverse. Try to see the reflection of small cubes on both the large ones.

@NasimiAsl I think this is close. Still not exactly like mirror but convincing. I have created a plane mirror beside the mesh you made for compare. Can I use this with cubeTexture made from probes?

And by the way your playground is so Disco. :D

Link to comment
Share on other sites


See The Result : 

a:  http://www.babylonjs-playground.com/#1NP9BY#15  when you zoom with mouse reflect don't be changed 

b: http://www.babylonjs-playground.com/#1NP9BY#16  this is Old Version of Reflection zoom and look the Box reflect 

My changset :

BABYLON.Effect.ShadersStore["defaultPixelShader"] =
    "vReflectionUVW=computeReflectionCoords(vec4(vPositionW*3.141592653589793*length(vEyePosition - vPositionW)*0.01,1.0),normalW)");


i think this fix Mirror Wrong size Problem 



Link to comment
Share on other sites


wait i need test more :)


http://www.babylonjs-playground.com/#KA93U#150    : mirror sample 

vReflectionUVW= vec3(mat4(-1.,0.,0.,0.,0.,-1.,0.,0.,0.,0.,-1.,0.,0.,0.,0.,-1.)*vec4( reflect(normalize(vPositionW.xyz*3.141592*length(vPositionW-vEyePosition)*0.13  -vEyePosition.xyz),normalW.xyz ) ,0.))

** where  are computeReflectMatrix Uniform in DefaultPixelShader? 

**  and i don't know about last parameter yet it is close to  0.13 for mirror in this sample why


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.

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.


  • Recently Browsing   0 members

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