XNAInfo blogs
Ramblings about XNA, .NET and stuff

Logarithmic Depth Buffer

February 20, 2010 14:28 by Rim

I came across an excellent discussion of setting up a logarithmic depth buffer in Cameni's Journal. I heard of those before, but I was surprised to find implementing them is as easy as adding only one simple line of code to your vertex shader:

output.Position.z = log(C*output.Position.z + 1) / log(C*Far + 1) * output.Position.w;

The C constant allows you to define the resolution you want at the near plane and Far is the value you use for the far plane. More details can be found in the journal linked above. I happened to be tinkering on a model of our solar system with a bunch of stars surrounding us (from Hipparcos data) to scale. The lightyear distances for the stars and the AU distances within the system were a source of woes with the depth buffer, but using this simple line made my z-fighting stars play nice.


Tags:
Categories: Frontpage | Ramblings
Actions: E-mail | Permalink | Comments (0) | Comment RSSRSS comment feed

Related posts