PDA

View Full Version : trying to implement stencil shadows



robert
02-09-2002, 11:45 PM
Hi, i am trying to implement stencil shadows using the increment/decrement approach.. but i am having problems.. It doesn't work http://www.opengl.org/discussion_boards/ubb/smile.gif.

Here is the code and i realize that it is probably completely wrong but any help would be much appreciated http://www.opengl.org/discussion_boards/ubb/smile.gif




glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
glEnable(GL_CULL_FACE);
// Render scene normally
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();

// Render scene normally
glEnable(GL_LIGHTING);
TheCam.Update(); // set up glulookat to look at (0,0,0)
DrawScene();

glDisable(GL_LIGHTING);
glDepthMask(GL_FALSE);

// Render scene and increment stencil buffer when depth test passes
glCullFace(GL_BACK);
glColorMask(GL_FALSE,GL_FALSE,GL_FALSE,GL_FALSE);
glStencilOp(GL_KEEP,GL_KEEP,GL_INCR);
glStencilMask(1);
glStencilFunc(GL_ALWAYS,0,1);
glEnable(GL_STENCIL_TEST);


glLoadIdentity();
gluLookAt(lightPosition[0],lightPosition[1],lightPosition[2]+.5,0,0,0,0,1,0);
DrawScene();

// Render scene and decrement stencil buffer when depth test passes
glStencilOp(GL_KEEP,GL_KEEP,GL_DECR);
glCullFace(GL_FRONT);
glStencilFunc(GL_ALWAYS,0,1);

glLoadIdentity();
gluLookAt(lightPosition[0],lightPosition[1],lightPosition[2]+.5,0,0,0,0,1,0);
DrawScene();

// Reder only when stencil == 0
glCullFace(GL_BACK);
glDisable(GL_STENCIL_TEST);
glColorMask(GL_TRUE,GL_TRUE,GL_TRUE,GL_TRUE);
glStencilOp(GL_KEEP,GL_KEEP,GL_KEEP);
glStencilFunc(GL_EQUAL,0,0);

glDepthMask(GL_TRUE);
glLoadIdentity();
DrawScene();

sunnyfounder
02-10-2002, 02:25 AM
After reading your codes, I get nothing wrong.So I think that maybe the error is not in these codes.Several months ago, when I studied using Stencil Buffer,I made a mistake that I fogot tell opengl to prepare stencil buffer for me.If you had the same mistake,you should check the codes which you use to initialize opengl.Good Luck http://www.opengl.org/discussion_boards/ubb/smile.gif

okapota
02-10-2002, 06:06 AM
you should draw shadow volumes to the stencil buffer, not the scene.

robert
02-10-2002, 11:28 AM
Ok I will try your ideas when i get home [ http://www.opengl.org/discussion_boards/ubb/smile.gif]
Thanks for you help.