Reputation: 4731
If I want to clear an entire depth/stencil view in Direct3D 11, I can easily call ID3D11DeviceContext::ClearDepthStencilView
.
Direct3D 11.1 adds support for clearing rectangular portions of render target views using ID3D11DeviceContext1::ClearView
.
But I see no way to clear only a portion of a depth/stencil view in Direct3D 11, short of rendering a quad over the desired area? This seems like an odd regression from Direct3D 9, where this was trivially easy. Am I missing something, or is this really not supported?
Upvotes: 1
Views: 2915
Reputation: 8824
There is an excellent reason at removing the partial clears in the API. First, it is always possible to emulate them by drawing quads with proper render states, and second, all GPUs have fast clear and resolve hardware. Using them in the intend logic greatly improve performance of the rendering.
With the DX11 clear API, it is possible to use the fast clear and the latter GPU optimisation. A depth buffer fast clear also prepare for an early depth test ( prior to pixel shading, because yes, the real depth test is post pixel shading ), and some bandwidth optimisation on access to the depth buffer will rendering. If you clear with a quad, you lost all that and draw cost will rise.
Upvotes: 0
Reputation: 170
There is no such function that can clear only a part of depth/stencil view. This is my way to solve the problem:
AlphaTest
, only the pixel whose alpha is 1.AlphaBlend
,set BlendOP
to Add
,set SrcBlend
factor to 0,set DestBlend
factor to 1. StencilTest
and DepthTest
to Always
, set StencilRef
to the value you want to clear.Upvotes: 2