Jump to content
  • entries
    232
  • comments
    1463
  • views
    961074

Z-Buffering issues

Sign in to follow this  
Ysaneya

359 views

I partially solved the Z-Buffering issues. One of the problems when rendering a planet, is that (unless you're cheating), its dimensions are so big that you get Z-fighting very quickly. Today, i tackled the problem by reworking the piping system, and adjusting the ZNear/ZFar values for each planet. It looks like this:

- sort planets from back to front
- for each planet:
- duplicate the camera, set znear/zfar to match planet
- clear the z and stencil buffers, but not the color buffer
- render the ground
- render the atmosphere
- render the clouds and the rest

Remarks:
1. The znear value is set to the closest distance between the camera and the atmosphere. If the camera is inside the atmosphere, it is set to a constant.
2. The zfar value is set to the longest distance between the camera and the atmosphere (basically, the symetrical point on the other side of the planet).
3. Since the znear/zfar change for every planet, the zbuffer values become obsolete between many planets, and rendering has to be done from back to front.
4. By rendering the ground first, early-rejection of the atmosphere or cloud pixels can happen.
Sign in to follow this  


6 Comments


Recommended Comments

I don't know how it will mess with your atmosphere blending, but you could eliminate some overdraw (if it becomes a problem) by doing a front to back ordering and using the stencil buffer.

Maybe that's not worth the effort/overhead. Just a thought :)

Share this comment


Link to comment
Nice solution, but i'm wondering what impact it will have when you come to render other elements such as spaceships and asteroids?

I expect these can be worked into the same system, although whilst sorting front to back shouldn't be too much of a strain, losing rendering by batches might be.

I guess a potential solution is to continue to divide up space into zones. So a planet has a near/far zone, and the space between two planets is a zone (own near/far) (by zones i mean in camera space, not world space). At least that way all elements within a zone (between planets) can be batched.


Anyway really just wanted to say how much I enjoy checking out your progress, but isn't it time for another interplanetary movie to show off planet textures?

Share this comment


Link to comment
There is a possible solution to the z-fighting problem that does not require clearing the z-buffer all the time.
You can set the depth range for each planet differently.
Here's an example where you have 2 planets to render.

For the planet that is further away set
glDepthRange(0.5f,1.0f);
and the zNear/zFar as you do it now.

For the planet that is closer to you set
glDepthRange(0.0f,0.5f);
and again the zNear/zFar as you do it now.

That way, you only use 1 bit precision, so 23 bits are left which should be enough.

You can also record all z-ranges prior to rendering and assign a depth range to each z-range that balances the precision for all objects (also spaceships). That way, you don't need any z-clear and the z-values are always meaningful.



Share this comment


Link to comment
Quote:
Nice solution, but i'm wondering what impact it will have when you come to render other elements such as spaceships and asteroids?


They will normally be rendered with the closest planet's range, and if it is already too far away, in a separate pass too.

Quote:
Anyway really just wanted to say how much I enjoy checking out your progress, but isn't it time for another interplanetary movie to show off planet textures?


Oh i don't think so, i haven't made enough progress since the last time. My previous movie is only two weeks old! You don't want me to post a new movie every week do you ? :)

Quote:
That way, you only use 1 bit precision, so 23 bits are left which should be enough.


Lutz: that's an interesting idea. But your example works for 2 planets. Let's say you have to display 20 planets (like in the Jupiter system): are you going to split the z-range in 20 segments ? To solve that kind of problem with z-clear, i was thinking of determining the planet's area in screen-space, and only clear that part of the screen.

Share this comment


Link to comment
Quote:

Lutz: that's an interesting idea. But your example works for 2 planets. Let's say you have to display 20 planets (like in the Jupiter system): are you going to split the z-range in 20 segments ? To solve that kind of problem with z-clear, i was thinking of determining the planet's area in screen-space, and only clear that part of the screen.


The 2-planets example was just to give the rough idea. In a real scenario, the idea has to be worked out a bit.

Considering the 20 bodies Jupiter system -- If you want to make it real (i.e. the proportions of all bodies and the distances to each other), then the bodies are either as small as dots (so you don't really need z-buffering) or there are at most 3 or 4 visible (with a moderate field of view).

So you'd have to check how many planets are larger than a spot and only for those do the depth range stuff.

You could even make an own z-range for the "dot-bodies" and draw them all into this z-range (call it "infinity-range" - that would even fit to the name of your engine ;-).

Share this comment


Link to comment
It seems like the far-plane only ever needs to be as far away as the center of the planet, since the front half of the planet always obscures the back half.

Share this comment


Link to comment

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
  • Advertisement
×

Important Information

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

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!