0
\$\begingroup\$

I'm using SlimDX 11 in my managed Direct3D application. I would like to implement deferred shading. I'm having trouble when I try to set a depth stencil surface and multiple render targets at the same time. Here is my code:

// depth stencil view
DepthStencilView dsv = GetD3D11DepthStencilView();

// array of 3 render target views
RenderTargetView[] rtv = GetPositionDiffuseEmissiveRenderTargetViewArray();

// device context
DeviceContext context = GetD3D11DeviceContext();

context.OutputMerger.SetTargets(dsv, rtv);


EDIT:
// create depth stencil state
context.OutputMerger.DepthStencilState = DepthStencilState.FromDescription(GetDevice(), new DepthStencilStateDescription()
            {
                IsDepthEnabled = true,
                DepthComparison = Comparison.Less,
                DepthWriteMask = DepthWriteMask.All,
                IsStencilEnabled = false,
                //StencilReadMask = 0xff,
                //StencilWriteMask = 0xff,
                //BackFace = new DepthStencilOperationDescription()
                //{
                //    Comparison = Comparison.Always,
                //    DepthFailOperation = StencilOperation.IncrementAndClamp,
                //    FailOperation = StencilOperation.DecrementAndClamp,
                //    PassOperation = StencilOperation.Keep
                //},
                //FrontFace = new DepthStencilOperationDescription()
                //{
                //    Comparison = Comparison.Always,
                //    PassOperation = StencilOperation.Keep,
                //    DepthFailOperation = StencilOperation.IncrementAndClamp,
                //    FailOperation = StencilOperation.Keep
                //}
            });

// clear depth stencil
context.ClearDepthStencilView(dsv, DepthStencilClearFlags.Depth, 1.0f, 0);
// draw as usual
...

When I set the depth stencil and render targets all at one time then nothing is rendered to the screen. When I set only the render targets everything renders normally...Why might this occur?

\$\endgroup\$
  • \$\begingroup\$ Please show where you Clear() the render target and depth stencil views. Please also show where you create the DepthStencilState you are using and where you set it as current. \$\endgroup\$ – Jon Mar 8 '16 at 21:44
  • \$\begingroup\$ @Jon I have added Clear() and create DepthStencilState \$\endgroup\$ – P. Avery Mar 8 '16 at 22:02
  • \$\begingroup\$ If you switch IsDepthEnabled to false, does it render normally? \$\endgroup\$ – Jon Mar 8 '16 at 22:11
  • \$\begingroup\$ @Jon yes it does render normally... \$\endgroup\$ – P. Avery Mar 8 '16 at 22:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.