Shadow buffer

This site has some example

The C++ code

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

and the VS 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);


var s_mat_m = glGet(GL_MODELVIEW_MATRIX);

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.


So I guess they end up with a identity matrix.

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


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