Dynamic Environment Mapping

Used some time to implement a GLSL shader that handles Dynamic Cube Mapping.
I’m using a FBO to render the scene to a CubeMap texture, and then a shader maps the CubeMap as a texture on whatever comes trough the shader.
The shader combines the CubeMap, a Color Map and a Normal Map in order to create the final output.
The shader takes a reflection parameter( float ) that is used to lerp between the colormap and the reflection map.
The vertex shader:

vView =vec3( vEye – (gl_ModelViewMatrix * gl_Vertex));

The pixel shader:
vec3 norm = texture2D(NormalMap, texCoords.st);
norm = (norm * 2.0) – 1.0;
vReflection = reflect(vView, norm);
gl_FragColor = lerp(textureCube(CubeMap, vReflection), texture2D(ColorMap,texCoords.st),r);
Next im going to implement a few light algorithms so the Color Map looks more real.
This entry was posted in Graphics. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.