PDA

View Full Version : Depth sorting question.



LostInTheWoods
04-02-2003, 09:52 AM
If I am rendering my objects from furthest to closest, with out my depth sorting on, then it will render MUCH faster, BUT, does the depth buffer still accumulate depths? Meaning, say i render a stage with lots of ground details so there is lots of bumps and such, can i render the ground, turn ON depth sorting, draw my characters, and them be placed correctly in the scene, or will they be drawn overtop of my current landscape?

JONSKI
04-02-2003, 02:05 PM
I've never done it, but I'm quite sure that you can write to the depth buffer without checking it for drawing your scene. With the depth buffer written, you may then enable depth testing for drawing geometry that has not been depth-sorted, so that the image appears correctly (assuming no z-fighting).


Use glDepthMask() to enable/disable writing to the depth buffer. In your case, you want it to always be enabled, and since it is enabled by default, just leave this function alone.

Use glEnable() and glDisable() on GL_DEPTH_TEST to toggle depth testing. In your case, you will want to disable it while rendering your nicely depth-sorted scene, and then enable it to draw your actors.

roffe
04-02-2003, 03:09 PM
Originally posted by LostInTheWoods:
If I am rendering my objects from furthest to closest, with out my depth sorting on, then it will render MUCH faster, BUT,
I would think rendering your objects front to back with depth testing on would be faster since it saves fill rate and expensive shading computations. But I might be talking out of my ass, since I havn't done any extensive testing myself.

rgpc
04-02-2003, 04:29 PM
Originally posted by roffe:
I would think rendering your objects front to back with depth testing on would be faster since it saves fill rate and expensive shading computations.

I believe you're right as I have seen frequent references to early z-culling - however there is a fundamental flaw in LostInTheWoods idea. If you render from furthest to closest without depth testing it will be MUCH slower than rendering from closest to furtherest WITH depth testing.

The reason being that _most_ cards/systems are fill rate bound these days and the amount of overdraw when rendering furtherest to nearest would be horrendous.

[This message has been edited by rgpc (edited 04-02-2003).]

dorbie
04-02-2003, 05:53 PM
Lost, I think you are confusing depth sorting with depth testing in the text of your post. To answer the question I think you are asking, yes you can write depth values without depth testing, and then depth test characters in the scene against those values. Just change your depth test using glDepthFunc(GL_ALWAYS). This is not much faster on modern hardware and as has been said already, an opposite sort will be faster with depth testing on thanks to coarse z testing on almost all modern hardware.

FYI the algorithm you are proposing is exactly what John Carmack did in his first Quake engine, initially in software, but I think the port to the OpenGL renderer also did it.