Glass panes in a greenhouse intersect, and seen from inside they blend in the wrong order even when sorted per object; why, and what do order-independent transparency techniques trade to fix it?
answer
- one order per object, many per pixel
- each pane wins on one side
- triangles blend in index order
- passes, memory or accuracy
- coverage exact, colour averaged
basics
~20 sPer-object sorting picks one order for a whole mesh, but intersecting panes are each in front on different pixels, so no object order is right. Order-independent transparency resolves order per pixel: depth peeling costs passes, per-pixel lists cost memory, weighted blending approximates.
solid answer
~50 sSorting by object distance picks one order for every pixel two panes share, but where panes cross, pane A is nearer on one side of the intersection line and pane B on the other, so part of the overlap always blends in the wrong order, and the error flips as the centre-based sort flips. Self-overlapping meshes fail the same way, because triangles inside one draw blend in index order. Cheap fixes are splitting meshes at intersections, drawing a convex shell's back faces before its front faces, or sorting triangles. The general fix is order-independent transparency. **Depth peeling** extracts one layer per geometry pass: exact up to its pass count, costly in passes. **Per-pixel linked lists** store every fragment in one pass and sort per pixel: exact, but memory depends on content. **Weighted blended OIT** makes the blend commutative with depth-based weights: one pass and fixed memory, but it averages layers instead of ordering them.
code
pseudocode · 16 lines// Pass 1: transparent surfaces in any order; depth test on, depth writes off.
// accumTarget: RGBA 16-bit float, cleared to (0, 0, 0, 0), blend dst = dst + src
// revealTarget: one channel, cleared to 1, blend dst = dst * (1 - src)
function accumulate(premulRgb, alpha, viewDepth):
w = clamp(alpha * depthWeight(viewDepth), 0.01, 3000) // larger when nearer
write accumTarget <- (premulRgb * w, alpha * w)
write revealTarget <- alpha
// Pass 2: full-screen composite over the opaque image
function resolve(pixel):
reveal = revealTarget[pixel] // product of (1 - alpha) over all layers
if reveal > 0.9999:
return opaque[pixel] // no transparent surface covers this pixel
acc = accumTarget[pixel]
avgColour = acc.rgb / max(acc.a, 0.00001) // weighted average of straight colour
return avgColour * (1 - reveal) + opaque[pixel] * revealgo deeper
Recall that sorting happens per object, so two objects that cross cannot both be in the right order everywhere.
Explain why intersecting and self-overlapping meshes defeat per-object sorting, and list the cheap fixes: splitting, back faces before front faces, and per-triangle sorting.
Compare depth peeling, per-pixel lists and weighted blending by passes, memory and accuracy, size a list buffer at a resolution, and say where weighted blending's average shows.
Decide whether content rules and mesh splitting carry the project or an order-independent technique is worth its memory and tuning, given what crosses at run time.
## Why per-object sorting fails for intersecting panes Per-object sorting draws each object whole, in one order, so it silently assumes one object is in front of the other at every pixel they share. Two panes that cross in an X break that assumption: on one side of the intersection line pane A is nearer, on the other side pane B is. Whichever is drawn first, part of the overlap blends in the wrong order. From inside a greenhouse, where panes meet at every frame and roof edge and many overlap in view, the error shows as tint that flips as the camera moves, because the centre-based sort itself flips. **Self-overlap** fails the same way. Triangles within one draw are blended in the order the index data lists them, so a curved glass shape can show its far wall over its near wall from some angles. ## Fixes that keep ordinary sorted blending - **Split geometry** where it intersects, so each piece has one consistent order; this costs art and tooling time. - **Back faces, then front faces:** for a convex closed shell, drawing it twice, first culling front faces and then culling back faces, gives the correct order within that shell. - **Per-triangle sorting** of a few transparent meshes each frame; correct for triangles that do not intersect, costly for large meshes, and still wrong where triangles cross. - **Content rules:** keep transparent objects apart, or make crossing effects additive so order stops mattering. ## Order-independent transparency Order-independent transparency (**OIT**) resolves order per pixel instead of per object. Three families cover most practice. **Depth peeling.** The transparent geometry is rendered several times. Assuming depth grows away from the camera, each pass keeps only the nearest fragment that is farther than the layer the previous pass peeled, using that layer's depth as a second depth test. Pass k therefore yields the k-th nearest layer at every pixel, and the layers are composited in order. It is exact for as many layers as there are passes and needs only a few screen-sized targets, but it costs **one full pass over the transparent geometry per layer**, and the passes run one after another because each needs the previous result. Dual depth peeling peels the nearest and farthest remaining layers in each pass, roughly halving the pass count. **Per-pixel linked lists.** 1. Clear a per-pixel **head pointer** image to empty. 2. Render all transparent geometry once. Each fragment atomically allocates a node from one large buffer, stores its colour, alpha and depth, and links itself in as its pixel's new head. 3. A full-screen resolve walks each pixel's list, sorts its fragments by depth and composites them with the over operator. It is exact and single-pass, but **memory depends on content**. At 2560 x 1440, which is 3,686,400 pixels, an average of four fragments per pixel with 12-byte nodes (packed colour, depth and a next index) needs about 177 MB of nodes plus about 14.7 MB of head pointers, and a view down a row of panes can hold many times the average. The node buffer is sized ahead of time, so overflow drops fragments, and sorting long lists per pixel is slow and uneven across neighbouring pixels. Fixed-size per-pixel arrays, often called **k-buffers**, bound memory by keeping only the nearest few fragments. **Weighted blended OIT.** This family gives up exact ordering to make the blend **commutative**. Each fragment adds its premultiplied colour times a weight into an accumulation target and multiplies a **revealage** target by `(1 - alpha)`. The weight grows for nearer and more opaque fragments. A resolve divides the accumulated colour by the accumulated weighted alpha and composites that average over the opaque image, using revealage as the share of background still visible. It costs one pass and fixed memory, a 16-bit float colour target plus a one-channel target, and needs no sort. Its **coverage is exact**: the product of `(1 - alpha)` does not depend on order, so the background is hidden by the right amount. Its **colour is a weighted average**, so it fails wherever order is visible: - two surfaces at similar depths with very different colours, which get similar weights; - a nearly opaque front pane that should hide the one behind it; - a weight curve tuned for one depth range used across another, or weights large enough to overflow 16-bit floats. It suits smoke, particles and many faint layers better than a few vivid, nearly opaque panes. ## Choosing | Technique | Geometry passes | Memory | Exact? | Breaks when | |---|---|---|---|---| | Sorted blending | 1 | nothing extra | per object only | meshes intersect or self-overlap | | Depth peeling | one per layer | a few screen targets | up to N layers | many layers (cost) or more than N (dropped) | | Per-pixel lists | 1 plus resolve | content-dependent | yes | the node buffer overflows; long sorts | | Weighted blended | 1 plus resolve | two screen targets | no | similar depths, vivid opaque layers | For a greenhouse, splitting panes where they cross and sorting per object is often enough, because the glass is static and its intersections are known when the level is built. When transparent surfaces must cross at run time, the choice is between exact but costly, peeling or lists budgeted by layer count, and cheap but approximate, weighted blending with weights tuned to the scene.
- How do you choose the weight function in weighted blended OIT?The weight should grow for nearer fragments so they dominate the colour average, and grow with alpha so faint fragments count less. It is a tuned function of view depth, such as an inverse power, clamped to a range so 16-bit float accumulation neither overflows nor flushes to zero. A curve tuned for a room-sized depth range misbehaves across a landscape, so the range is a per-content setting.
- When is depth peeling still a reasonable choice?When exact order matters for a few layers and the transparent geometry is cheap to draw several times: a handful of glass panes, a model viewer, a high-quality capture. Its cost is layers times transparent geometry, and each pass needs the previous layer's depth, so passes cannot overlap. Dual depth peeling roughly halves the pass count by peeling the nearest and farthest layers together.
- Sorting by object centre more carefully will fix intersecting panes.
- Weighted blended OIT produces the exact over result in one pass.
- Per-pixel linked lists need a small, fixed amount of memory per pixel.
- Depth peeling costs one extra pass however many layers overlap.
- Turning depth writes back on for glass resolves the intersection order.