PDA

View Full Version : Cubemap reflection mapping



Leadwerks
10-26-2007, 06:24 PM
I got my cubemaps set up so they work with a "skybox" style mapping mode. Then I attempted to do a reflection in the fragment shader. Here is the result:
http://www.leadwerks.com/post/cube3.png

As you can see, there is an odd vertical line where the cubemap gets flipped. This line moves with the camera.

I have packaged up the demo here:
http://www.leadwerks.com/post/cubetest.zip

If anyone can identity what is wrong with the shader, I would appreciate it. The section you should look at is line 91 of main.frag:

#ifdef LW_CUBEMAP

// Reflection
gl_FragColor = gl_FragColor * alpha + textureCube( cubemap, reflect( N,gl_TexCoord[2].xyz ) ) * (1.0 - alpha);

// Skybox (this works fine)
//gl_FragColor = gl_FragColor * alpha + textureCube( cubemap, gl_TexCoord[2].xyz ) * (1.0 - alpha);

#endif

It should be noted that I scale my modelview matrix by (0,0,-1) before doing anything, in order to switch the coordinate system to a left-handed one.

Leadwerks
10-27-2007, 01:01 PM
By copying some code from a generated ShaderGen shader, I was able to calculate the reflection vector in the vertex shader. It works perfectly. Thank you, 3DLabs.

There is still the matter of modulating the cubemap lookup by the bump vector, for EMBM, but the hard part is done.