I've been working on a translucency system for my deferred renderer, inspired by the translucency support present in "inferred rendering", which works by interleaving samples using a screen-door pattern.
In my system, I'm first rendering the opaque objects to the G-buffer as usual, and then rendering translucent objects using a similar stippling pattern scheme to inferred rendering.
The stipple pattern changes depending on the number of layers that are present per pixel, in order to maximize the resolution of the closest layer:
#Layers 0 1 2 3 4+ Pattern: B|B B|1 B|2 B|3 4|3 -+- -+- -+- -+- -+- B|B 1|1 1|1 2|1 2|1
B = background. 1 = closest layer to viewer, 2 = 2nd closest layer, etc.
i.e. If there's only 1 layer over the opaque scene, 3/4 pixels are overwritten with that translucent data, and 1/4 retains the background.
If there's 4 or more layers, then the first 4 layers each get 1/4 pixels, and the 5th layer onwards are discarded.
The "closest layer" is determined by rendering order -- translucent objects are sorted to be drawn from front-to-back (instead of the typical back-to-front order), and it's assumed in the stippling scheme that the first object to write to a pixel is the first layer, etc.
I then perform lighting on the G-Buffer as usual.
After lighting, the pixels in each 2x2 block are sorted into layers, the 2nd/3rd/4th layers are blurred appropriately (to simulate translucent scattering), and then the layers are composited into the final rendering.
The obvious downside is a loss of resolution in areas of the screen containing translucent objects.
If there's only 1 layer, this loss is minimal (1/4 of pixels are missing on the closest layer), but if there's 3+ layers, the loss is more extreme (3/4 pixels missing). I use FXAA to minimize the resulting aliasing artefacts.
The other obvious downside is that you start discarding whole layers when more than 4 triangles overlap.
The rendering order in the below image is actually unsorted (instead of the ideal order of front-to-back) to demonstrate the per-2x2-quad sorting. As long as the first 4 layers are drawn first (with small errors in ordering), then the sorting stage actually fixes most artefacts, with the main artefact being non-ideal resolution distribution for the 2-layer case.
As you can see, it's working pretty well for me, and the performance beats forward rendering due to less pixels being shaded (forward rendering will shade every pixel on every layer). Plus the ability to very easily get blurred transmission is very cool (and was a feature my artists wanted from the beginning).
However, it's all very ad-hoc and quickly thrown together, so I'm trying to research similar solutions that are out in the wild. I feel there's probably improvements to be made in both my stippling / stencil-routing step, and in my reconstruction filter.
So far I've only found:
- Inferred rendering (the original inspiration), but it uses an additional geometry pass instead of a screen-space reconstruction filter.
- Stencil-routed A-buffers and K-buffers - similar but using MSAA instead of whole pixels. Seems like a good idea
- DX11 per-fragment linked-list methods.
- Basic deferred stippling methods, either with no reconstruction filter at all, or a simple averaging reconstruction filter.
If you know of other techniques like this, please share
Edited by Hodgman, 11 September 2013 - 11:42 PM.