Thanks for the care. But I guess I bad explained. This is how I do shadowing: I enlight the lit geometry even if my code snippets didn’t make it realize it goes this way.
In fact, I realized that shadow2DProj always return a null vec4. And I was pretty sure gl_TexCoord[0] was well initialized. So I have something wrong somewhere.
Using gl_Vertex for calculating the tex coords wouldn’t be of help for me just because the vertices aren’t set in world space, they have to be transformed by the modelview matrix. This is why the texture matrix contains the invert of the visualisation matrix (not the invert of the modelview as I stippled on my last post).
Here are more codes:
// in the rendering loop, shader has been set to be used before:
glMatrixMode (GL_MODELVIEW);
glLoadIdentity();
gluLookAt (4,4,4,0,0,0,0,1,0);
glGetFloatv (GL_MODELVIEW_MATRIX, &view_matrix[0][0]);
InvertMatrix (view_matrix, inv_view_matrix);
glLightfv (GL_LIGHT0, GL_POSITION, l_pos);
glLightfv (GL_LIGHT0, GL_AMBIENT, l_amb);
glLightfv (GL_LIGHT0, GL_DIFFUSE, l_dif);
glLightfv (GL_LIGHT0, GL_SPECULAR, white);
glEnable (GL_LIGHT0);
glEnable (GL_LIGHTING);
glEnable (GL_TEXTURE_2D);
glBindTexture (GL_TEXTURE_2D, shadow_map_tex);
glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_COMPARE_MODE_ARB, GL_COMPARE_R_TO_TEXTURE);
glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_COMPARE_FUNC_ARB, GL_LESS);
glTexParameteri (GL_TEXTURE_2D, GL_DEPTH_TEXTURE_MODE_ARB, GL_INTENSITY);
glMatrixMode (GL_TEXTURE);
glLoadIdentity();
glTranslatef (.5,.5,.5);
glScalef (.5,.5,.5);
glMultMatrixf (bias_matrix);
glMultMatrixf (light_projection_matrix);
glMultMatrixf (light_view_matrix);
glMultMatrixf (&inv_view_matrix[0][0]);
glMatrixMode (GL_MODELVIEW);
RenderScene();
{...}
RenderScene contains all the rendering geometry, including some transformations.
Also, I tested the texture coordinates in the fragment shader with something like this:
gl_FragColor = gl_TexCoord[0]/gl_TexCoord[0]/q;
And it appears to be well calculated: red on the right, green on the top and getting blue when going far. But sometimes, specially when it goes out of the light projection, values can be more than 1 or less than 0. I actually think this is not a problem.
I guess I miss some point somewhere but I still haven’t been able to find where and what it could be.
Notes: I changed the way to do it since my first post here. In fact I’m now trying to do it in two passes only, so now all what I have is a all black scene.