Page 1 of 1

Automatic Z-Depth Algorithm

Posted: 29 Aug 2017, 06:54
by SatoriLotus
How much performance cost would there be for the engine to automatically calculate z-depth for alpha transparency and filter accordingly?

This would make things like translucent glassware and gems possible.

Re: Automatic Z-Depth Algorithm

Posted: 29 Aug 2017, 14:14
by Chris
What do you mean by "automatically calculate z-depth for alpha transparency and filter accordingly"? Depending on the mesh's depth test setting, the Z depth value is calculated so it can be skipped if needed, and depending on the mesh's depth write setting, said value is written to the Z buffer.

Re: Automatic Z-Depth Algorithm

Posted: 29 Aug 2017, 15:17
by SatoriLotus
Chris wrote: 29 Aug 2017, 14:14 What do you mean by "automatically calculate z-depth for alpha transparency and filter accordingly"? Depending on the mesh's depth test setting, the Z depth value is calculated so it can be skipped if needed, and depending on the mesh's depth write setting, said value is written to the Z buffer.
This link could probably explain what I mean better:
https://blender.stackexchange.com/quest ... y-viewport

and here's an in-game example of the limitation at work:
Spoiler: Show

Re: Automatic Z-Depth Algorithm

Posted: 29 Aug 2017, 16:00
by AnyOldName3
When you're using the regular Z-buffer algorithm to draw stuff, it assumes that you can ignore things behind other things, which doesn't work for translucent materials. You can extend it so that you render everything without transparency normally, and then sort all the transparent objects by their depth using another algorithm. This can be complicated as parts of one object can be in front of something while others are behind, in which case the object needs splitting. Anything behind the z-buffer depth of a pixel from earlier can be discarded, and the rest is rendered from back to front on top of the other stuff. If you only have a couple of translucent objects, this isn't terribly performance intensive, but if everything might be, then you're totally screwed as the z-buffer algorithm is what GPUs are geared towards, and it's a lot simpler and faster than the alternatives.