Sign in to follow this  
danromeo

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

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"][size="2"][font="Consolas"][size="2"]float4 PixelShader(float2 TexCoord : TEXCOORD0, float4 Position : TEXCOORD1) :COLOR0

[/size][/font][/size][/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
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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this