Sign in to follow this  
LuckyPinecone

zbuffer scaling problems

Recommended Posts

I'm working on a simple game engine and I have noticed that when I scale an object either very small or very large, the Z buffer will not work correctly with those objects and the objects will not render with correct depth (parts of the mesh object from the opposite side showing through). Also if I use a different scale for world dimensions the z buffer performs incorrectly. For example if I were using 1 unit = 1 kilometer (.001 = 1 meter) the z buffer will be much less effective because only a small range of numbers within the buffer's potential range are ever IN the buffer so the buffer is effectively fewer bits of data. What I want to do is change the scale of the buffer so that it works correctly when the scale of the world is different. I'm honestly not even sure if this is possible, but I'd love to be able to do it if i can. Thanks for any help you can give me. -LP

Share this post


Link to post
Share on other sites
This is a "feature" of the Z-buffer. There's only a finite range of values that you can define using the Z-buffer. There was some magic numbers floating around; something like "90% of the Z-buffer depth range is used in the first 10% of the scene".

If you're trying to draw large depth ranges, there's a couple of things you can try (No doubt others will list some other ideas):
  • Increase the distance of the near clip plane (See above; the further the near clip plane, the better the depth values)
  • Split your world up into segments, and screw about with Z-buffer between segments to "make it work".

    Bringing another question into this thread; Whatever happened to the W-buffer? The W-buffer used to be a linear version of the Z buffer, and was generally something you'd enable whenever possible. However, I haven't heard it mentioned in about 2 years. Did it just die in favour of the "normal" Z-buffer, or was it just rejected outright?

    Share this post


    Link to post
    Share on other sites
    You were right about the near clipping plane, steve. I (accidentally) had it set to the equivalent of half a centimeter in the game world scale! I got it fixed by setting the near plane to a meter.

    I then tied the near plane to the mouse wheel and wrote some code to display the distance of the zn in the bottom corner. The optimal distance was about .7 meters. I set it to .7 permanently.

    Anyway thanks for the tip, steve.

    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