Jump to content
  • Advertisement
Sign in to follow this  

Direct3D custom z testing.

This topic is 2062 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 want to write one pixel depth value to the z-buffer but test against another value with a offset added. This is to overcome objects that are z fighting against the terrain. I want to write the normal depth value to the z-buffer but have a offset added when testing agains the terrain z values. Is there any easy way to do this?

Share this post


Link to post
Share on other sites
Advertisement
You can set the depth bias renderstate (D3DRS_DEPTHBIAS) in Dx 9 or use the DepthBias member of the D3D11_RASTERIZER_DESC1 in Dx 11


Alternatively, in the vertex shader you can add a vector pointing towards the camera to offset the location:


biasedPos = pos + (vectorToCamera.normalize() * biasValue)


Or you can slightly push out your near and far clip planes, which will cause everything rendered after to be slightly closer (z-wise) than everything rendered before.

Edit: brain fart. Edited by turch

Share this post


Link to post
Share on other sites
You can't have differen values for testing and writing. The easiest thing to do would be to have a z-only pass, then render your geometry again with depth biasing and depth writes disabled.

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.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!