Jump to content
  • Advertisement
Sign in to follow this  
supmagc

DepthStencilBuffer in HLSL

This topic is 3393 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've just stumbled upon a presentation of the deferred renderer pipeline in killzone2, and it occured to me, that they are directly using the depth-buffer as depth-texture. So I tried to do the same thing to measure some performance over default rendertargets, but somehow I'm unable to retrieve any value besides 1 from the buffer. Creation of depth-buffer-texture:
IDirect3DTexture9 *pTex;
HR(GetDevice()->CreateTexture(GetWidth(), GetHeight(), 1, D3DUSAGE_DEPTHSTENCIL, D3DFMT_D24S8, D3DPOOL_DEFAULT, &pTex, NULL));
pTex->GetSurfaceLevel(0, &m_pSurface);
Next I set this surface as the active DepthStencilSurface
HR(GetDevice()->GetDepthStencilSurface(&m_pBackup));
And I send the texture itself to my postprocessing-shader Corresponding HLSL-code to display the Depth--buffer on screen:
texture2D Depth : TEXTUREDEPTH;
sampler2D DepthSampler {
	TEXTURE = <Depth>;
};

float4 PixelShader(...) : COLOR {
	return float4(tex2D(DepthSampler, In.Tex).x, 0, 0, 1);
}
Anbody knows/sees what's going wrong here ? Reference to KZ2-presentation: http://www.guerrilla-games.com/publications/dr_kz2_rsx_dev07.pdf

Share this post


Link to post
Share on other sites
Advertisement
The KZ2 devs can do this because their game runs on a console, and they have access to low-level stuff like this. D3D9 doesn't expose any such functionality. The only think you can do with a depthstencil surface in legal, valid D3D9 is set it as the current depthstencil surface for the device (unless it's lockable, but that's slow as hell so you wouldn't want to do that).

Nvidia and ATI both have "extensions" (more like driver hacks) that allow limited access to hardware depth buffers, but they're really aimed at shadow mapping. You wouldn't be able to use it for depth reconstruction.

In practice it's not much of a big deal, anyway. You typically render depth out with the rest of G-Buffer so it's not like you could take advantage of double-speed depth-only rendering, and it also lets you use linear depth if you want to avoid precision issues associated with using post-projection z/w.

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!