Jump to content
  • Advertisement
Sign in to follow this  
Revelation60

Problems with GL_EXT_stencil_two_side

This topic is 3855 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi, I'm trying to implement two sided stencil tests for my shadows into my engine. To do that I altered some code:
 glEnable(GL_CULL_FACE);
    glEnable(GL_DEPTH_TEST);
    glDisable(GL_LIGHTING);
    glShadeModel(GL_FLAT);
    glDepthMask(0);
    glDepthFunc(GL_LESS);

	 if (HasTwoSidedStencilExtension)
	{
			//Enable 2 sided stencil
				glEnable(GL_STENCIL_TEST_TWO_SIDE_EXT);

				glDisable(GL_CULL_FACE); // disable cull facing, important!
	
				//Increment(with wrapping) for back face depth fail
				glActiveStencilFaceEXT(GL_BACK);
				glStencilFunc(GL_ALWAYS, 0, ~0);
				glStencilMask(~0);
				glStencilOp(GL_KEEP, GL_INCR_WRAP_EXT, GL_KEEP);

				//Decrement(with wrapping) for front face depth fail
				glActiveStencilFaceEXT(GL_FRONT);
				glStencilFunc(GL_ALWAYS, 0, ~0);
				glStencilMask(~0);
				glStencilOp(GL_KEEP, GL_DECR_WRAP_EXT, GL_KEEP);



				//Draw the shadow volume
				DrawShadowsForEveryObject(GameScene, lp);

				glDisable(GL_STENCIL_TEST_TWO_SIDE_EXT);

	}
	else
	{
    
    glColorMask(0, 0, 0, 0);
    glStencilFunc(GL_ALWAYS, 0, ~0);

    glCullFace(GL_FRONT);
    glStencilOp(GL_KEEP, GL_INCR, GL_KEEP);
    //DrawShadow(o, f, lp, true);
	DrawShadowsForEveryObject(GameScene, lp);

    glCullFace(GL_BACK);
    glStencilOp(GL_KEEP, GL_DECR, GL_KEEP);
    //DrawShadow(o, f, lp, true);
	DrawShadowsForEveryObject(GameScene, lp);

	}

glStencilFunc(GL_EQUAL, 0, ~0);
glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP);

glEnable(GL_STENCIL_TEST);


glDepthFunc(GL_LEQUAL);
glDepthMask(GL_FALSE);
glColorMask(1, 1, 1, 1);

GameScene.DrawScene();

Because GL_EXT_stencil_two_side only takes over the drawing of the shadow volume, I haven't altered any other part of the code. The above change gives incorrect results: I can see the whole shadow volume, even the parts in the open. I haven't got a clue where to look for the problem. I've tried everything. Note that my hardware does support both GL_EXT_stencil_two_side and GL_EXT_stencil_wrap. The normal z-fail routine works like a charm. Have you got any ideas?

Share this post


Link to post
Share on other sites
Advertisement
It's not visible in this snippet, but the stencil test is on and it should be on after the shadow volumes are rendered, because when I draw the scene, the stencil should function as a mask.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!