Presently my engine is set up to use deferred shading. My pixel shader output struct is as follows:

struct GBuffer
float4 Depth : DEPTH0;      //depth render target
float4 Normal : COLOR0;     //normal render target
float4 Diffuse : COLOR1;    //diffuse render target
float4 Specular : COLOR2;   //specular render target

This works fine for flat surfaces, but I'm trying to implement relief mapping which requires me to manually write to the depth buffer to get correct silhouettes. MSDN suggests doing what I'm already doing to output to my depth render target - however, this has no impact on z culling. I think it might be because XNA uses a different depth buffer for every RenderTarget2D. How can I address these depth buffers from the pixel shader?

  • \$\begingroup\$ When using multiple render targets, there is still only one depth/stencil buffer. I'm not sure how XNA handles this - uses the depth buffer of the first render target, perhaps? But at the API/hardware level there is definitely only one depth/stencil bound at a time, no matter how many color render targets are bound. \$\endgroup\$ – Nathan Reed Oct 31 '13 at 20:35
  • \$\begingroup\$ blogs.msdn.com/b/shawnhar/archive/2010/03/26/… "Note: when using MRT, the depth format is controlled by the first rendertarget." Thanks for pointing that out, I guess it must just use the depth buffer from the first render target or something. I'm still not sure how to write to it though, since writing to DEPTH0 writes to the surface of the depth rendertarget and not its depth buffer. \$\endgroup\$ – DocSeuss Oct 31 '13 at 20:50
  • \$\begingroup\$ I'm not sure what you mean by "the surface of the depth render target and not its depth buffer"? Writing to DEPTH0 should work the same way for MRT as for regular rendering. \$\endgroup\$ – Nathan Reed Oct 31 '13 at 22:34

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.