Sign in to follow this  
Grasshopper

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="http://msdn.microsoft.com/en-us/library/windows/desktop/bb205599(v=vs.85).aspx"]depth bias renderstate (D3DRS_DEPTHBIAS)[/url] in Dx 9 or use the [url="http://msdn.microsoft.com/en-us/library/windows/desktop/cc308048(v=vs.85).aspx"]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:

[code]
biasedPos = pos + (vectorToCamera.normalize() * biasValue)
[/code]

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