Sampling the depth buffer in a shader in DX11

Started by
12 comments, last by Zao 6 years, 9 months ago

Thanks guys, this will do for now.


By the way: What you're doing with that clip() should be possible with the depth buffer directly, no need to bind it as SRV. Draw your full screen quad with a fixed z at that threshold value and use a depth comparison of greater or greater-equal. Or set z to 1 and the comparison to equal (if your depth was cleared to 1 initially).

True, but when I started I was not sure if I wanted to mask pixels out or only include them with a smaller alpha, so I thought this would be more flexible, though, perhaps not as efficient as your approach.

Advertisement
It's still possible to bind the depth as both DSV and SRV in this case. You tag the DSV as read-only with Flags = D3D11_DSV_READ_ONLY_DEPTH (and D3D11_DSV_READ_ONLY_STENCIL) and configure the DSS for reading only, too. IIRC needs feature level 10.1. Search for smooth particles, they do something alike.

As this is the primary web search hit for the subject, any non-zero flags like the read-only depth/stencil ones in a DSV desc require feature level 11_0 or greater, the debug runtime returns invalid arg and issues a diagnostic:


D3D11 ERROR: ID3D11Device::CreateDepthStencilView: A non-zero Flags field (0x1) is not valid, unless the GetFeatureLevel returns D3D_FEATURE_LEVEL_11_0 or greater. [ STATE_CREATION ERROR #2097153: CREATEDEPTHSTENCILVIEW_INVALIDFLAGS]
D3D11 ERROR: ID3D11Device::CreateDepthStencilView: Returning E_INVALIDARG, meaning invalid parameters were passed. [ STATE_CREATION ERROR #148: CREATEDEPTHSTENCILVIEW_INVALIDARG_RETURN]

 

To make it is hell. To fail is divine.

This topic is closed to new replies.

Advertisement