Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

WickedMystic

Depth buffer problem

This topic is 6927 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Heyaz, I am currently working on a 3D space shooter engine in OpenGL. I have already implemented front-end backface culling, quaternion rotations etc etc.. and everything is going just great, but I have stumbled upon the following problem: The Z-buffer.... Viewing the ships up close: everything works fine, but when viewed from a distance some parts that are farther away are showing through parts that are closer. I know its due to the Z-buffer being only 16 bit. Setting the far-clipping plane in the perspective transform closer solves it but then I get ships just ''popping'' up out of nowhere, not nice either. So whats the best way to solve this? Sort the faces from back to front before rendering them? And whats the most efficient way to sort them? Will calculating a BSP for each ship work? Or do I have to resort to slower quicksort or radixsort(how do you do radixsort on floating point numbers?) Any tips would be appreciated. WickedMystic

Share this post


Link to post
Share on other sites
Advertisement
I noticed this in my current project when running on those blasted ATI Rage128's. To fix it, set your near clipping plane back a bit. I was using 0.1 for it, but when you set it back it magically gets better.

Pythius

EDIT: By setting it back, I mean increasing the actual value. Try different values and see what happens. -P

Edited by - Pythius on 5/7/00 6:17:57 PM

Share this post


Link to post
Share on other sites
Yay!! That worked fine Thanks.. I am using 5.0f for near- and 2000.0f for the far clipping plane. Its perfect now, the fighters dont just pop up from out of nowhere now and the Z-buffer problem is fixed.

But I still wonder. What if I start including those Bad-Ass HUGE capital ships that still have to be visible from very far away? I would have to increase the far clipping plane again, resulting in Z-buffer problems again as I cant really increase the near clipping plane any further...

Anyway thanks!!

WickedMystic

Share this post


Link to post
Share on other sites
To get the best result from your z-buffer you should keep the distance between the near plane and far plane as small as possible. If nothing ever gets closer to the viewer than 10 units, set the near plane to 10, and the same goes for the far plane.

Unfortunately the z-buffer has the disadvantage that most of the values are concentrated at the nearplane, making the accuracy near the far plane less than good. If you use w-buffering instead the depth values are more evenly spaced between the two planes. giving better accuracy near the far plane while still keeping enough accuracy near the near plane. Not all cards support w-buffering though so you should fall back on z-buffering if it doesn''t.



- WitchLord

Share this post


Link to post
Share on other sites
I was just browsing through the Freespace 2 website and I read somewhere in a ''bugfix of the day'' that they actually are using BSP trees for every ship. Hmm, sounds interesting. I wouldn''t even have to use Z-buffering that way since the faces would be drawn in the correct order anyway, right?

I thought BSP trees were only used for static objects like Terrain in a Flightsim or the maps in for example Quake etc.

Oh well, I guess I will give it a go and try it out, never done BSP''s before though :/

WickedMystic

Share this post


Link to post
Share on other sites
That is a actually a very good solution. Each ship''s form is usually static so you can sort it''s triangles in a BSP-tree without trouble. You would of course need one BSP-tree per ship model.

Note: This solution is not that good with organic life forms such as characters in Quake since they are animated and the BSP tree would have to be recalculated each frame.

- WitchLord

Share this post


Link to post
Share on other sites
Maybe you can mix the two Versions, using the Z-Buffer for short Distances, where it is important to have no Visual Error''s. Then sort the far away Objects (BSP or simple sort)
and render them first without Z-Buffer. If you get any Problems cause of multiple overlapping or not correctly sorted triangles, it isn''t htat bad, cause of the great Distance.

Lars

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!