I've surveyed a number of order-independent transparency methods for my OpenGL engine, and at first I thought I would like to use weighted average blending, to maximize speed.
However, my engine uses deferred shading, and I need to take this into account when choosing a blending technique. Ideally I would like a technique that wouldn't ask me to implement forward shading to use for translucent objects.
There are a number of cases where I need to use transparency:
- Grass/Hair (anti-aliased cutouts)
- Glass (colorful blending)
- Objects that fade in and out
- Smoke/Clouds
- Water/Liquid (would involve refraction, I know that true OIT is impossible here)
- Sparks/Magic/Fire (don't need to be lit and can use additive blending, not worried about these)
I am willing to sacrifice image correctness for the sake of speed (Hence my initial choice of weighted average blending). I don't need every layer of translucent objects to be lit, but I would at least like for the front-most pixels to be properly lit.
I'm using OpenGL 3.x+ Core Context, so I would like to avoid anything that requires OpenGL 4.x (as lovely as it would be to use), but I can freely use anything that isn't available in OpenGL 2.x.
My question is: What is the best order-independent transparency technique for deferred shading?, and/or: what is the best way to light/shade a translucent object when using deferred shading?
P.S. is there a better way to render anti-aliased cutouts (grass/hair/leaves) that doesn't rely on blending? Pure alpha testing tends to produce ugly aliasing.
The way I do it :
See Morgan McGuire's blog for how to do compositing and how to construct your "transparent" framebuffers. Reconstruct transparent surfaces using your draw ID framebuffer and the Normals, I use a simple weighted average, with a weight corresponding to the current normal dot framebuffer's normal (a normal dot itself giving 1).
Downside :
Upside :
My weight function for Blended OIT (closer surfaces with the same opacity always get higher weight) :
My compositing function :
See this about "CameraSpaceDepth" and this about fp values
Here is the result for this model with a dirty hacked-together POC, you can see rough surfaces transmission :