Environment Cube Map Problem

Started by
3 comments, last by mede 13 years, 4 months ago
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;
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.

[size=2]My Projects:
[size=2]Portfolio Map for Android - Free Visual Portfolio Tracker
[size=2]Electron Flux for Android - Free Puzzle/Logic Game
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...
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

[size="1"]And a Unix user said rm -rf *.* and all was null and void...|There's no place like 127.0.0.1|The Application "Programmer" has unexpectedly quit. An error of type A.M. has occurred.
[size="2"]

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 ???

This topic is closed to new replies.

Advertisement