Sign in to follow this  
nbertoa

[D3D12] Depth Buffer problem (maybe)

Recommended Posts

Hi, community.

 

I have a bug with Screen Space Ambient Occlusion and I suspect is the depth buffer information I use.

 

Depth Stencil View Format is DXGI_FORMAT_D24_UNORM_S8_UINT

Depth Stencil Shader Resource View Format is DXGI_FORMAT_R24_UNORM_X8_TYPELESS

Then its values should be between [0, 1]

 

I made a test to check if depth buffer is sampled correctly. This is the pixel shader (geometry is a full-screen quad). I disabled depth test.

struct Input {
	float4 mPosH : SV_POSITION;
};

Texture2D<float> DepthTexture : register(t0);

struct Output {
	float4 mColor : SV_Target0;
};

Output main(const in Input input){
	Output output = (Output)0;

	const int3 screenCoord = int3(input.mPosH.xy, 0);
	const float depthNDC = DepthTexture.Load(screenCoord);
	output.mColor = float4(depthNDC, depthNDC, depthNDC, 1.0f);
	
	return output;
}

Near Z is 1.0f

Far Z is 2000.0f

so I expect to get total white (1.0f, 1.0f, 1.0f) when the object is at 2000.0f Z and total black (0.0f, 0.0f, 0.0f) when object is at 1.0f Z

 

I recorded the following video, and if I modify Far Z to something like 500.0f or 5000.0f, I get the same black-white gradient results than the video.

That is why I think something is wrong.

 

https://www.youtube.com/watch?v=J6ZEoElU_Qo

 

Thoughts? Am I missing something?

Share this post


Link to post
Share on other sites
Yeah my statement was a little fast, i was just saying we do not store linear depth in a dept buffer. We store z/w to be precise, if you look at the projection matrix, you will find that w ends to be a z, while z is a mixture of scale and bias of z against near and far.

For the we clear at 1.f, it is because of the projection and a dept test set as less or equal.

It is possible to clear at 0.f, using a test set as greater while using afloating point depth buffer.

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