Sign in to follow this  
dnaxx

Stencil buffer and depth

Recommended Posts

hello! I am using the stencil buffer for shadows. It works, but shadows that are occluded by another object, are drawn through this object. I am using this code for the shadows:
	glDisable(GL_LIGHTING);
	glDisable(GL_DEPTH_TEST);
	glDisable(GL_TEXTURE_2D);

	glEnable(GL_BLEND);
	glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

	glEnable(GL_STENCIL_TEST);
	glStencilFunc(GL_GREATER, 1, ~0);
	glStencilOp(GL_KEEP, GL_KEEP, GL_REPLACE);

	glColor4f(0,0,0,0.5);
	
	// - transform matrix to shadow mode
	// - draw shadow casting object (==shadow)
	// disable blending, reset other options from above and continue to draw scene

And here is a sample of the "shadow problem" (the shadow casting object is behind the mountain but it's shadow shines through): One solution would be to do something like occulision culling, but I would prefer an easier solution ;). thank you,

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this