Direct3D custom z testing.
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?
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:
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.
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.
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.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement