Jump to content

  • Log In with Google      Sign In   
  • Create Account


Stencil Buffer


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
2 replies to this topic

#1 Matthew Meeks   Members   -  Reputation: 210

Like
0Likes
Like

Posted 05 February 2013 - 08:45 PM

I'm having issues understanding how stencil buffers work.  I used them a few times in XNA but there appears to be many differences.  The comparison test always seems to pass and the objects are always drawn.

 

Here are my depth states:

DepthStencilStateDescription dsStateDesc = new DepthStencilStateDescription()
            {
                IsDepthEnabled = true,
                IsStencilEnabled = false,
                DepthWriteMask = DepthWriteMask.All,
                DepthComparison = Comparison.Less
            };

            DepthState = DepthStencilState.FromDescription(Device, dsStateDesc);

            //===

            DepthStencilStateDescription dsaStateDesc = new DepthStencilStateDescription()
            {
                IsDepthEnabled = true,
                IsStencilEnabled = true,
                FrontFace = new DepthStencilOperationDescription()
                {
                    Comparison = Comparison.Greater,
                    FailOperation = StencilOperation.Keep,
                    PassOperation = StencilOperation.Increment,
                    DepthFailOperation = StencilOperation.Zero
                },
                BackFace = new DepthStencilOperationDescription()
                {
                    Comparison = Comparison.Always,
                    FailOperation = StencilOperation.Keep,
                    PassOperation = StencilOperation.Increment,
                    DepthFailOperation = StencilOperation.Zero
                },
                StencilWriteMask = 0,
                StencilReadMask = 1,
                DepthWriteMask = DepthWriteMask.All,
                DepthComparison = Comparison.Less
            };

            addDepthState = DepthStencilState.FromDescription(Device, dsaStateDesc);

            //===

            DepthStencilStateDescription dscStateDesc = new DepthStencilStateDescription()
            {
                IsDepthEnabled = true,
                IsStencilEnabled = true,
                FrontFace = new DepthStencilOperationDescription()
                {
                    Comparison = Comparison.Equal,
                    FailOperation = StencilOperation.Keep,
                    PassOperation = StencilOperation.Keep,
                    DepthFailOperation = StencilOperation.Keep
                },
                BackFace = new DepthStencilOperationDescription()
                {
                    Comparison = Comparison.Equal,
                    FailOperation = StencilOperation.Keep,
                    PassOperation = StencilOperation.Keep,
                    DepthFailOperation = StencilOperation.Keep
                },
                StencilReadMask = 1,
                StencilWriteMask = 1,
                DepthWriteMask = DepthWriteMask.All,
                DepthComparison = Comparison.Less
            };

            compareDepthState = DepthStencilState.FromDescription(Device, dscStateDesc);

 

When I draw:

  • Clear the depth/stencil buffer
  • set the first depth state
  • draw the world
  • set the second depth state
  • draw the cube to render the second view point on
  • set the third depth state
  • draw the world from the second view point

 

If this helps these are the XNA depth states I'm trying to mimic:

        DepthStencilState addIfPortal = new DepthStencilState()
        {
            StencilEnable = true,
            StencilFunction = CompareFunction.Always,
            StencilPass = StencilOperation.Increment

        };
        DepthStencilState checkPortal = new DepthStencilState()
        {
            StencilEnable = true,
            StencilFunction = CompareFunction.Equal,
            ReferenceStencil = 1,
            StencilPass = StencilOperation.Keep
        };

 

I appreciate any help and thanks for your patience smile.png



Sponsor:

#2 qorthos   Members   -  Reputation: 165

Like
0Likes
Like

Posted 06 February 2013 - 09:16 AM

Are you setting your DepthStencilView with device.OutputMerger.SetTargets() ?



#3 Matthew Meeks   Members   -  Reputation: 210

Like
0Likes
Like

Posted 06 February 2013 - 01:15 PM

Yes I am






Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS