• Advertisement
Sign in to follow this  

DX9: Is there a way to render a depth buffer?

This topic is 4291 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

I would like to render the contents of a depth buffer to a render target as a grayscale image. Is this possible to do in DX9? Any pointers? Thanks!

Share this post


Link to post
Share on other sites
Advertisement
I had posted a similar thread in the DirectX forum. Some suggestions were made but I could not get anything to work (except for OpenGL where glReadPixels makes it trivial). Folks seem to confirm that it is not possible to get this information out of DirectX. I gave up on getting depth buffer information into a render target. Instead, I switched to generating the depth itself in a shader (duplicating what the rasterizer is going to produce anyway). The Cg programs are


void VS_ProjectedDepth
(
in float4 modelPosition : POSITION,
out float4 clipPosition : POSITION,
out float depth : TEXCOORD0,
uniform float4x4 modelViewProjectionMatrix)
{
clipPosition = mul(modelPosition,modelViewProjectionMatrix);
depth = clipPosition.z/clipPosition.w;
}

void PS_ProjectedDepth
(
in float depth : TEXCOORD0,
out float4 pixelColor : COLOR)
{
pixelColor.rgb = depth;
pixelColor.a = 1.0f;
}



You create your render target to have format D3DFMT_A8R8G8B8, set the render target, and render the scene in the standard way.

Share this post


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

  • Advertisement