PDA

View Full Version : shadow volumes



Poons
05-08-2003, 07:47 AM
im implementing shadow volumes. but the problem is the shadows dont appear.

first i create the shadow volume which is stored in dList.

Insel is my terrain on which the shadow should appear.

then i use the following code snippet to render the scence.

does anybody know what im making wrong?


glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);

Insel->configRendering();
Insel->render();
Insel->recoverContext();

//glColorMask(GL_FALSE,GL_FALSE,GL_FALSE,GL_FALSE);
//glDepthMask(GL_FALSE);

glEnable(GL_STENCIL_TEST);
//glDepthMask(GL_FALSE);
glStencilFunc(GL_ALWAYS,0,0);

glStencilOp(GL_KEEP,GL_KEEP,GL_INCR);
glCullFace(GL_BACK);
glCallList(dList);

glStencilOp(GL_KEEP,GL_KEEP,GL_DECR);
glCullFace(GL_FRONT);
glCallList(dList);

glDepthMask(GL_TRUE);
glColorMask(GL_TRUE,GL_TRUE,GL_TRUE,GL_TRUE);
//glCullFace(GL_BACK);
glDepthFunc(GL_LESS);
glStencilOp(GL_KEEP,GL_KEEP,GL_KEEP);

//glStencilFunc(GL_EQUAL,1,1);
glDisable(GL_LIGHTING);

/*
glEnableClientState(GL_VERTEX_ARRAY);
glVertexPointer(3,GL_FLOAT,0,Insel->terrainData);
glDisable(GL_TEXTURE_2D);
glColor3f(0.0f,0.0f,0.0f);
for (int i=0;i<Insel->width-1;i++)
{
glDrawElements(GL_TRIANGLE_STRIP,Insel->width*2,GL_UNSIGNED_INT,Insel->indexes+i*Insel->width*2);
}
glDisableClientState(GL_VERTEX_ARRAY);
Insel->configRendering();
Insel->render();
Insel->recoverContext();*/

glStencilFunc(GL_EQUAL,0,1);

Insel->configRendering();
Insel->render();
Insel->recoverContext();

glDepthFunc(GL_LESS);
glDisable(GL_STENCIL_TEST);

i`m glad about every suggestion!

Poons

dorbie
05-08-2003, 01:35 PM
You should disable depth and color writes when drawing the stencil volume (you have the right calls there but it's commented out). If you don't disable depth writes on the volume the second terrain pass and parts of your stencil volume rendering will fail the depth test. By definition all fragments inside the shadow volume would fail the depth test and no shadowing will occur.

Apart from that it looks OK, but I just skimmed.

[This message has been edited by dorbie (edited 05-08-2003).]

Poons
05-09-2003, 12:13 AM
i have commented it out to see if the shadow volume is correct. i have forgotten to comment it in http://www.opengl.org/discussion_boards/ubb/wink.gif but when i disable it, the shadow does not appear.

thanks, for looking over the code.

Poons