Sign in to follow this  

Clearing the stencil buffer

This topic is 4729 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

I'm trying to render stencil based shadow volumes, but for some reason I cannot clear the stencil buffer; Every time I try to call this: device.Clear(ClearFlags.Stencil, Color.Black, 1.0f, 0); It crashes with "Error in the application." I can see that without the clear it SORT of works, but the shadows are visible somehow: As you can see, the teapots seem to shade each other, but not the 'ground', at least not correctly. Also, when you look through the shadow of one teapot at another teapot that is not in the shadow, it appears shaded. I just followed the example at http://www.gamedev.net/columns/hardcore/shadowvol/page2.asp but instead of extruding the edges, I'm using a shader that extrudes vertices not facing the light. Can anyone shed some light on the situation (Bad pun, I know:P)

Share this post


Link to post
Share on other sites
Suppose I did do something silly like that... How would I go about creating a depthstencil with stencil support.

Feeling a bit lost here, looking through the initialization in the code provided by that tutorial, and I'm not seeing anything I dont have relating to stencils.


//Set up stencil modes
device.RenderState.StencilEnable = false;
device.RenderState.StencilZBufferFail = StencilOperation.Keep;
device.RenderState.StencilFail = StencilOperation.Keep;
device.RenderState.ReferenceStencil = 0x1;
device.RenderState.StencilMask = unchecked((int)0xffffffff);//int.MaxValue;
device.RenderState.StencilWriteMask = unchecked((int)0xffffffff);//int.MaxValue;

device.RenderState.CounterClockwiseStencilFunction = Compare.Always;
device.RenderState.CounterClockwiseStencilZBufferFail = StencilOperation.Keep;
device.RenderState.CounterClockwiseStencilFail = StencilOperation.Keep;
device.RenderState.CounterClockwiseStencilPass = StencilOperation.Decrement;

Share this post


Link to post
Share on other sites
Quote:

Suppose I did do something silly like that... How would I go about creating a depthstencil with stencil support.


When you create your device you possibly have something like this for the presentation parameters:

presentParams.EnableAutoDepthStencil = true;
presentParams.AutoDepthStencilFormat = DepthFormat.D16;

To have a stencil buffer, you may replace that with the following:

presentParams.EnableAutoDepthStencil = true;
presentParams.AutoDepthStencilFormat = DepthFormat.D24S8;

Notice it's now D24S8, meaning 24 bits depth buffer and 8 bits for stencil. The point is, your format has to include stencil in it. See the documentation for "DepthFormat Enumeration" for a list of all the ones which include a stencil buffer.

-Mezz

Share this post


Link to post
Share on other sites
Ok, I guess this is progress: the stencil clear call is no longer causing a crash.

However, I can still see the shadow volumes (like the above picture) Only with more buggy looking artifacts than before.

Share this post


Link to post
Share on other sites
Ok! I think I finally am getting closer, the 'final optimization' from the tutorial: combining the Z fill pass and the ambient pass into one seems to help.

But some things are still screwed up. The Teapots dont shade correctly, I'm thinking it has to do with it not being closed or something.

Share this post


Link to post
Share on other sites

This topic is 4729 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.

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