Jump to content
  • Advertisement
Sign in to follow this  
mede

OpenGL Environment Cube Map Problem

This topic is 2865 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi
I try to use a dynamic created cube map for reflection lookup in the per pixel
shader. I read a lot of stuff in the Internet but I still have a Problem.

The reflection on a sphere always show the reflection looking from origin to Z+ direction, independent on the camera position and direction ??? see pictures.




I created the the cubemap using the following code from openglwiki
which seams to work.

openglwiki

before rendering the scene I render the 6 faces (+X-X+Y-Y+Z-Z) in WORLD SPACE.

here the lines in the vertex shader

m_normal = normalize(gl_NormalMatrix * gl_Normal);
m_eyeVec = gl_ModelViewMatrix * gl_Vertex;
...
gl_Position = ftransform();



and fragment shader

uniform samplerCube environmentTex;
...
vec3 normal = normalize(m_normal);
...
vec3 refVec = normalize(reflect(m_eyeVec, normal));
vec3 color = textureCube(environmentTex, refVec).rgb;

Share this post


Link to post
Share on other sites
Advertisement
You need to keep the normal, eyeVec, and refVec in world space, not in view space.

If your cubemap is defined in world space (such that, for example: the top of the cube always corresponds to world space 'up'), then you need to access it with a world space vector. You're putting your eye-space reflection vector into the cubemap, so it's a mismatch and you get bogus results.

Either do all the calculations in worldspace, or transform the refVec by the inverse view matrix to put it in worldspace before you access the cubemap.

Share this post


Link to post
Share on other sites
hm I changed this...
Now the reflection is right if I move the camera, but if I rotate the sphere itself
the reflection also rotates which for sure not should be the case...

Share this post


Link to post
Share on other sites
Hi,

As I recall, this is because in OpenGL, the gl_NormalMatrix represents the transpose of the inverse modelview matrix. The view component is throwing the issue.

Try multiplying the normal by a uniform matrix representing ONLY the object's rotation.

-G

Share this post


Link to post
Share on other sites
I pass now the inverse of the camera view matrix to the shader and transform the reflection vertex back to world space. this seams to be a good solution.

If I use Normalmapping is there another solution, than passing the inverse tangentspace transformation to the fragmentshader and transform reflection vertex first back to camera space and then world space ???

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!