Jump to content

View more

Image of the Day

雑魚は多めにして、爽快感重視にしつつ・・・(´・ω・`)
早いとこ、ベースを作って、完成にもっていかないとね。
タイトルもまだ迷ってるだよなぁ。 
#indiedev  #indiegame #screenshotsaturday https://t.co/IwVbswGrhe
IOTD | Top Screenshots

The latest, straight to your Inbox.

Subscribe to GameDev.net Direct to receive the latest updates and exclusive content.


Sign up now

Stencil Buffer

4: Adsense

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   

218
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



#2 qorthos   Members   

168
Like
0Likes
Like

Posted 06 February 2013 - 09:16 AM

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



#3 Matthew Meeks   Members   

218
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.