Advice on Heavy Stencil Buffer Usage

Started by
2 comments, last by Kitasia 16 years, 10 months ago
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]
Advertisement
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

<hr align="left" width="25%" />
Jack Hoxley <small>[</small><small> Forum FAQ | Revised FAQ | MVP Profile | Developer Journal ]</small>

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]
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!

This topic is closed to new replies.

Advertisement