Skip to main content
GameDev.net gamedev.net
🔒 Locked

Direct3D custom z testing.

Started by Grasshopper Sep 27, 2012 at 4:34 PM 1 replies 1.3k views
Original Post
Grasshopper
Grasshopper
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?
turch
turch
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.
MJP
MJP
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.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.