Sign in to follow this  

Direct3D custom z testing.

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
You can set the [url=""]depth bias renderstate (D3DRS_DEPTHBIAS)[/url] in Dx 9 or use the [url=""]DepthBias member of the D3D11_RASTERIZER_DESC1[/url] 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

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