Question about the depth buffer in open gl

Hi there,

This might be a clewbie question, but what is the depth buffer for?
I thought it would be so that I wouldn’t have to do depth sorting by hand, but I also found out that when I want to use blending (don’t we all?) I had to do depth sorting anyway to make it appear right.
So what does it do then? ???

Thanks,
Erik

  1. Clear z buffer & enable
  2. Render all solid objects with depth buffer enabled, in any order.
  3. Disable z writing, but leave z testing enabled.
  4. Render all transparent objects in rough back-to-front order.

Sorting per-poly is usually overkill, so a rough sort is usually sufficient. Note that depending on your blending mode, sorting may or may not have a large effect…

[quote]Sorting per-poly is usually overkill
[/quote]
… but sometimes not even sufficient. Then even splitting of polygons (e.g. when they intersect) might be necessary before sorting them.

That’s why you poke your artists and get them to define convex hulls :wink:

Cas :slight_smile:

[quote]… but sometimes not even sufficient. Then even splitting of polygons (e.g. when they intersect) might be necessary before sorting them.
[/quote]
Is that only for blended polygons, or also for opaque polygons?

[quote]That’s why you poke your artists and get them to define convex hulls
[/quote]
You lost me ::slight_smile:

[quote]Is that only for blended polygons, or also for opaque polygons?
[/quote]
If you’ve got a depth buffer in use, then this is only for transparent polys. Depth buffer will handle this for you on a per-pixel level, so all will be well (assuming you’ve got a reasonable combination of z-buffer depth, near plane and far plane).

Convex hulls are neat because you can render everything in it in any order, with backface culling, and not worry about overlapping polys. They’re also neat for pathfinding because any two points within can always be linked with a straight line. Convex hulls are very handy ;D

I guess then that convex hulls involves defining objects with triangles only?
If that does the trick then that’s pretty ingenious :smiley:

Here’s a very early demo of a game engine I’m working on with lots of transparency used:
http://www.mycgiserver.com/~movegaga/gldemo1.jnlp
(it’s now a windows only web start app using lwjgl).

Now, if you look carefully, you’ll notice that although every polygon (well, only quads atm) is depth-sorted (by hand), it still isn’t enough: You’ll see dark squares around the bouncing stars every now and then (when it occludes the far end of a wall quad). I guess I must even sort per vertex or something? Because in the cases the black blocks appear, the origins are well sorted, but the star should still be drawn after the wall it occludes even though the origin of the wall is closer. (hope I’m still making sense here)…
BTW If the wall is solid and not transparent, everything looks fine.

Or… is there a method of blending that doesn’t have this side effects?
(now doing gl.blendFunc(GL.SRC_ALPHA, GL.ONE); )

Thanks,
Erik

Oh, disregard that ‘sort per vertex’ suggestion. That makes no sense. :stuck_out_tongue: ::slight_smile:

I did not know, that javaplugin can download a native .dll files as well and then run it on the fly.

Your demo looked very good and run smooth on my machine, althought I did see a black squares once in a while as well.