Jump to content
  • Advertisement
Sign in to follow this  
danromeo

How do I access a RenderTarget2D depth buffer in a custom shader in XNA 4?

This topic is 2616 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hey.

How do I access a RenderTarget2D depth buffer in a custom pixel shader XNA 4? For depth based fog, for example.

If [font="Consolas"][font="Consolas"]float4 PixelShader(float2 TexCoord : TEXCOORD0, float4 Position : TEXCOORD1) :COLOR0

[/font][/font]Would it be the .z component of Position? Or do I need to pass it in the pipline with a custom vertex declaration?

THANKS

Share this post


Link to post
Share on other sites
Advertisement
You can't access a depth buffer in XNA. But it doesn't sound like you want to access the depth buffer, it sounds like you want to compute a fog factor as you're rendering geometry. You can compute a fog factor in a variety ways, including the distance from the camera to the surface or the view-space Z value. Either way you should compute that in your vertex shader, pass it to your pixel shader, and then compute the fog factor in your pixel shader.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!