Shadow buffer

This site has some example
http://wiki.vrmedia.it/index.php?title=Shadow_Mapping

The C++ code


glMatrixMode(GL_TEXTURE);
glLoadIdentity();  // clear things up
glTranslate(0.5, 0.5, 0.5); // we have to clamp values in the [0.0, 1.0] range, not [-1.0, 1.0]
glScale(0.5, 0.5, 0.5);
glMultMatrix(light_mat_proj); // now multiply by the matrices we have retrieved before
glMultMatrix(light_mat_modelview);
 
// finally, multiply by the *inverse* of the *current* modelview matrix
var s_mat_m = glGet(GL_MODELVIEW_MATRIX);
if (! InvertMatrix(&s_mat_m))
   Quit("Singular view matrix!"); // this should not happen
 
glMultMatrix(s_mat_m);
glMatrixMode(GL_MODELVIEW);

and the VS shader


[VERTEX SHADER]
varying vec4 shadowTexCoord;
void main (void)
{
   // vertex calculation
   gl_Position = ftransform();
   
   // shadow texture coordinates generation
   shadowTexCoord = gl_TextureMatrix[0] * gl_ModelViewMatrix * gl_Vertex;
}

Why are they computing InvertMatrix(&s_mat_m)
and then in the shader
shadowTexCoord = gl_TextureMatrix[0] * gl_ModelViewMatrix * gl_Vertex;

Isn’t it simpler to not apply the inverse in the C++ and in the shader

shadowTexCoord = gl_TextureMatrix[0] * gl_Vertex;

good question :slight_smile:

They also say:


light_mat_modelview = glGet(GL_MODELVIEW_MATRIX);

so


glMultMatrix(light_mat_modelview);
var s_mat_m = glGet(GL_MODELVIEW_MATRIX);
InvertMatrix(&s_mat_m);
glMultMatrix(s_mat_m);

would also be redundant, but it says

Please note that light_mat_proj and light_mat_modelview are always the same if the light does not move; in that case you do not need to retrieve them at every frame.

So I guess the values for modelviewmatrix are not the same when the functions/shaders are called.

N.

So I guess they end up with a identity matrix.

Looks like it, maybe they wrote it this way for the sake of clarity…

N.

This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.