PDA

View Full Version : Depth sorting problem



Syslock
10-18-2001, 10:19 AM
I've encountered a strange problem when depth sorting objects and
I can't figure out what's going on. I use a simple call to qsort()
to sort objects based on their center points. When I don't sort,
the objects are rendered with no problems. However, when I do
sort, there are alot of z-buffer artifacts (tiny black specs) all
over my model. I though it might have to do with toggling
glDepthMask from FALSE to TRUE when rendering translucent objects,
so I removed all translucent objects and commented out the glDepthMask
toggling, and I still got the same problem with sorting solid objects
only. I know my zbuffer is setup fine. What the heck is going on?

I just hoping someone else has came across the same problem before.

Syslock
10-20-2001, 02:43 PM
Any suggestions?

I have a 16-bit zbuffer that is fixed at znear=1 and zfar=1000
which renders ok. Objects in the scene are typically less
than 100 units or so. Qsort() sorts all objects, solid and
translucent, from back to front.

I don't see what is wrong with this setup.

Kaos
10-20-2001, 03:27 PM
Have you tried making your own sorting method for the faces. Also y do you want to sort the faces in the first place?

DFrey
10-20-2001, 05:21 PM
The proper rendering order is as follows:

1. Farthest triangles e.g. background, sky, etc.
2. Solid triangles with depth testing and depth writing enabled
3. Transparent triangles with depth testing enabled, but depth writes disabled (masked)
4. Nearest triangles e.g. foreground, text, etc.

Note, for step 1 you can disable both depth testing and depth writes, however, if your scene has no transparent triangles, you might get a performance boost if you do this step as step 3.5 with depth testing enabled.
For step 2, it would be best if the solid triangles were presorted in nearest to farthest order, however how much performance you gain from this will of course vary, so you may want to try both sorting them and not sorting them to see the performance difference, if any.
For step 3, the transparent triangles should be sorted from farthest to nearest, unless then blending being used is commutative, in which case the order doesn't matter, normally the order will matter however.


[This message has been edited by DFrey (edited 10-20-2001).]

Syslock
10-22-2001, 12:25 PM
DFrey:

It worked!

I sorted the solid objects from nearest to farthest, and the
translucent/transparent objects from farthest to nearest,
instead of sorting everything one particular way.

Why changing the sorting order of solid objects worked, I still
don't understand. It shouldn't matter, as far as I know, but
it did.