Sign in to follow this  

Advice on Heavy Stencil Buffer Usage

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

Hello! I'm kinda working on a 2D(ish) game and seem to be having trouble on a stencil buffer method. I end up stencilling a lot of objects with a lot of different objects so I often have to clear the stencil buffer and it really takes it's toll on the performance (drops to about 50 frames from 90 frames rendering only 4 entities consisting of 130 triangles). I was hoping the stencil buffer had some sort of thing where I can input values per layer and only show things with matching values. After further research I don't think it's possible if not severely limited. Any advice offered would be greatly appreciated! [help]

Share this post


Link to post
Share on other sites
dropping from 90fps down to 50fps for just 4 objects is entirely based on your stencil buffer usage?

That sounds like you're either using the SB in a bad way or you're just trying to do stuff with it that it wasn't really designed for.

Could you provide some pseudo code and/or description of what you're trying to achieve and how you're going about it? Might well be that we can suggest a better way of getting the same results...

hth
Jack

Share this post


Link to post
Share on other sites
Why certainly! This isn't the exact code but I think it's enough to get the picture. Took out a couple of irrelevant things.


public static void DrawLimb(Limb limb, bool stencilling)
{

//Stencil
if (limb.IsStencilled)
{
if (!stencilling) { device.Clear(ClearOptions.Stencil, Vector4.Zero, 1.0f, 0); }
device.RenderState.StencilFunction = CompareFunction.Always;

//Root
device.RenderState.ColorWriteChannels = ColorWriteChannels.Alpha;
device.RenderState.StencilEnable = true;
device.RenderState.StencilPass = StencilOperation.Replace;
device.RenderState.StencilFail = StencilOperation.Replace;
device.RenderState.StencilDepthBufferFail = StencilOperation.Replace;

//Draw Stencil before drawing Limb
DrawLimb(limb.stencilLimb, true);

device.RenderState.ColorWriteChannels = ColorWriteChannels.All;
device.RenderState.StencilFunction = CompareFunction.Equal;
device.RenderState.StencilPass = StencilOperation.Replace;
device.RenderState.StencilFail = StencilOperation.Keep;
device.RenderState.StencilDepthBufferFail = StencilOperation.Keep;
}

//Draw

device.DrawUserPrimitives<Vertex>(PrimitiveType.TriangleStrip, limb.vert, 0, limb.vert.Length - 2);

//Clean Up
if(limb.IsStenciled) {device.RenderState.StencilEnable = false;}

}








Note: I'm sure it's not the drawing of the stencil. Still moved slow after commenting it out. One more thing. I'm estimating the stencil buffer is cleared about 8 or 12 times per entity.

[Edited by - AntiGuy on May 20, 2007 6:17:42 PM]

Share this post


Link to post
Share on other sites
Ha HA [lol]!

It seems I've solved my problems yet again! [smile] Well not really! I got the idea from someone named Centurion (sp?) on this topic

It seems stencil clearing the area I'm about to use instead of clearing the entire buffer was the proper method. How could I be so stupid as to not think of that!

Anyway thanks for the help jolly ol' jeff!

Share this post


Link to post
Share on other sites

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