Sign in to follow this  
Syranide

Transparency batching

Recommended Posts

Ok, I'm gonna say it out loud so you know, this is only theoretic to me right now, but I've been thinking about this for a day or so now, and I really want an answer (Currently reading a book about 3d game engine programming). Drawing opaque polygons is pretty much straight on, batch and render, batch and render (sort by texture and so on)... But how do you do when it comes to transparent polygons? They must be rendered from back to front... sure no problem, just sort the vertex buffer. But how do you do on let's say a 500 poly model? It doesn't sound sane to for each render of the model sort it back to front in regard to its rotation. (Just to be clear, not sorting would produce a transparent model, with lets say his hands shining through is body (behind his back), but in another direction, his body won't shine through his hands, because of his hands being drawn before the body). Let's take an example, you have ten windows, all with different textures, then you make 5 such sets (50 windows, 10 textures)... in order to make it work, you would need to sort the front to back right? ... But wouldn't that potentially mean you would change texture 50 times? For additive blending I figure it doesn't matter at all, as regardless of the order it would produce the same result... but common transparency doesn't allow that? How do you approach this problem? (Or have I overlooked some GPU functionality?) (I'm not looking for a scientific answer, just a general idea of how this is approached, or some link/tutorial, no in-depth information required) Thanks in advance!

Share this post


Link to post
Share on other sites
PErsonally, I've never understood what's so wrong about turning off depth writing, leaving depth reading on, and then rendering the translucent figure. I haven't tried it myself, but I just don't see any reason why it wouldn't work.

[Edited by - Cypher19 on June 28, 2005 9:09:29 AM]

Share this post


Link to post
Share on other sites
Many transparent objects have only one side, like windows, so you don't have to sort them per polygon; just sorting objects is enough.

For objects with only front and back side (like the body/hand example) you can sometimes use a trick called Carmack's reverse. Basically it renders the object twice with opposed culling settings. A drawback is that it does not work in all cases.

Sorting the polygons is usually the last resort (when all else fails) and normally is only done within one object at a time (i.e. you normally will not sort a bunch of polygons coming from different objects).

One GPU setting you've overlooked is the alpha reference value, which allows you to do some neet tricks without sorting. But it does not work for alpha blending; just for alpha transparency (i.e. on/off).

Cypher19: I'll assume you meant to leave depth reading on, since otherwise no correct Z-order would emerge?

There is probably a lot more to it, so anyone is invited to add to this. Greetz,

Illco

Share this post


Link to post
Share on other sites
It works for additive blending yes... but not for commonly transparent "sprites", let's take 90% transparency as an example.

Drawing RED before BLACK would produce "RED".
Drawing BLACK before RED would produce "BLACK".

(regardless of RED actually being ontop of BLACK)

Therefore, you must do it in order, meaning from back to front, or things won't start to make sense, you will see through the transparency when they are drawn in the wrong order (can be seen in GTA SA).

Share this post


Link to post
Share on other sites
Ok, I don't think you fully understood my point sadly.

(Little unclear about the model and glas)

What I mean is what you can see in many old games and GTA SA for example, where you have bushes with transparent edges... if these bushes are drawn before the buildings and trees behind, you will see through the entire world around the edges of the bush (go to hell einstein!) as the buildings and objects behind will be discarded due to the half transprent pixels being marked as "opaque" in the Z-buffer.

So, lining up 50 bushes requires them to be sorted back to front, but also the model itself. (Model as there could otherwise be minor artifacts within the bush if viewing from different angels)

"One GPU setting you've overlooked is the alpha reference value, which allows you to do some neet tricks without sorting. But it does not work for alpha blending; just for alpha transparency (i.e. on/off)."

Would that allow me to draw the bushes in any order e.g.? (without visual artifacts/failures)

Share this post


Link to post
Share on other sites
Such bushes would typically use the alpha reference value; no sorting required. Some models however do require per-poly sorting. You might also want to check out an article on either ATI or NVidia's site (can't remember) with a technique for alpha transparency without sorting. This article may also be useful as an introduction to common techniques used.

Share this post


Link to post
Share on other sites

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

Sign in to follow this