im trying to get the typical depth shadow working but seems this test is causing problems:
//Enable shadow comparison
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_MODE_ARB, GL_COMPARE_R_TO_TEXTURE_ARB);
//Shadow comparison should be true (ie not in shadow) if r<=texture
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_FUNC_ARB, GL_LEQUAL);
//Shadow comparison should generate an INTENSITY result
glTexParameteri(GL_TEXTURE_2D, GL_DEPTH_TEXTURE_MODE_ARB, GL_INTENSITY);
when i turn it on, my scene goes black, im wondering how to turn the parameters off or back to default after i finished with them? when i comment out the code, all i get is a projected depth texture as expected
It might be that your problem is with the setup of your Texture matrix (or glPolygonOffset()) and that the test is identifying everything in your scene as being in shadow.
Try using glPolygonOffset() (which you are probably already using) and changing the values to relatively extreme values to see if that improves things (I used something like glPolygonOffset ( 3.0f, 7.0f ) ).
To turn the comparison off you use glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_MODE_ARB, GL_NONE);
You call this before you do your lighting render (ie. After you have done your “ambient” only render).
i do:
pass 1, render from light, (render back faces)
pass 2, render scene (im currently just doing this with no lighting) and no projective texture
pass 3, render scene with projective texture (with 50% white)
now, on pass 3, if i set the depth comparison to on before, and turn it off after, but seems nothing is rendered (there is no colour difference) :-/ if i dont do the depth pass, i get a projected texture as expected
i assumed i didnt have to do polygon offset when rendering back faces, but ill give it a shot
ug polygon offset goes in when rendering from lights im guessing?
edit:
glPolygonOffset didnt seem to have any effect, i’ve uploaded a demo, left click turns on the depth test, clicing again turns it off
no im not using them, i couldnt get it working, so tried via GLSL but it doesnt like the way i generate the texture coords…crashes my pc
texture matrix is:
given a world matrix for the light, invert it
glMatrixMode(GL_TEXTURE);
glLoadIdentity();
glTranslatef(0.5, 0.5, 0.0);
glScalef(0.5, 0.5, 1.0);
glFrustum(xmin, xmax, ymin, ymax, znear, zfar);
// not sure if this is right?
glTranslatef(light.GetPosition()[0], light.GetPosition()[1], light.GetPosition()[2]);
glMultMatrixf((GLfloat *) inverseLightWorldMat);
glMatrixMode(GL_MODELVIEW);
actually, in that demo i had an extra translation before by -1 in Z right before translating by lights position,
this fixed the problem of nothing seeming to be projected onto the sphere, but now it seems the sphere gets most of the projected texture projected on to it, plus it looks as if the prjected texture is rotating the opposite way as on the cube?
fudging the initial scale to about 0.3, 0.3, 1.0 fixed the projection on the sphere but i shouldnt have to do this, obviously something is wrong…
if you d/l the zip again, i have included shadowmap2.exe right clicking changes initial scale from 0.3 to 0.5, and you can see how it looks as if the proj. texture is rotating the opposite way on the sphere