PDA

View Full Version : Shadow Volumes problem



__bob__
01-09-2015, 06:27 AM
Hi all, i try to work with sadow volumes. I use openGL state like this :



init:
glEnable (GL_DEPTH_TEST);
glEnable (GL_STENCIL_TEST);

glDisable(GL_CULL_FACE);
glDisable(GL_DEPTH_CLAMP);
glDepthFunc(GL_LEQUAL);
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
glClearDepth(1.0f);
glClearStencil(0);
....

render function

glClearColor(0.0,0.0,0.0,0.0);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT |GL_STENCIL_BUFFER_BIT);

for (unsigned int i = 0;i < collector->nodes.size();i++)
collector->nodes[i]->render(SVDiff); // ambiant rendering

glStencilOpSeparate(GL_FRONT, GL_KEEP, GL_KEEP, GL_INCR_WRAP);
glStencilOpSeparate(GL_BACK, GL_KEEP, GL_KEEP, GL_DECR_WRAP);
glStencilFunc (GL_ALWAYS, 0, ~0);
glClear(GL_STENCIL_BUFFER_BIT);
glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE);
glDepthMask(GL_FALSE);

for (unsigned int i = 0;i < collector->nodes.size();i++)
collector->nodes[i]->render(SVShad);// render of shadow volumes in the stencil buffer

glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
glDepthMask(GL_TRUE);
glClear(GL_DEPTH_BUFFER_BIT);
glStencilOpSeparate(GL_FRONT, GL_KEEP, GL_KEEP, GL_KEEP);
glStencilOpSeparate(GL_BACK, GL_KEEP, GL_KEEP, GL_KEEP);
glStencilFunc (GL_EQUAL, 0, ~0);

for (unsigned int i = 0;i < collector->nodes.size();i++)
collector->nodes[i]->render(SVMat);//spec and diff rendering



As result i obtain a good shadow but shadow volumes are still visible.



Any idea?

Dark Photon
01-09-2015, 06:23 PM
Even aside from your visible shadow volumes, it doesn't appear certain from your picture that shadow volumes are working properly yet.

In any case, typically shadow volumes are rendered to the stencil buffer only (i.e. with color and depth writes disabled). Try that.