Transparency Joshua Barczak CMSC 435 UMBC With help
Transparency Joshua Barczak* CMSC 435 UMBC *With help from others…
Stuff That’s Transparent Fake Volumetric Effect Fur Curtains Lacy Things Civilization V (Firaxis)
Light Shafts • Typical approach: – Transparent proxy geometry – Additively blended into scene – Scroll speckle texture over it to mimic floating dust
Stuff That’s Transparent Smoke/Fire Eyebrows Facade Beard Facade Civilization V (Firaxis)
Particles • Fire/Smoke/etc – Animated point masses – Transparent, screenaligned quads “Smoke” “Fire”
Stuff that’s Transparent Fake Volumetric Effect Tips of the hair This Stuff Smoke Fire Civilization V (Firaxis)
Stuff That’s Transparent Eyebrows Fake Volumetric Effect Facades Curtains Civilization V (Firaxis)… Don’t fire me guys…
Stuff That’s Transparent Eyebrows Facades Grass Civilization V (Firaxis)…This is fair use, right?
Foliage Behrendt et al. 2005
Foliage Overgrowth (Wolfire Games)
In a raytracer • Just shoot more rays… • Given opacity ‘a’ – Shade, weight color by ‘a’ – Fire additional ray in same direction, weight its color by 1 -a
In a rasterizer… • Draw back to front • At each fragment, given opacity a: – Weight its color by a – Weight background by (1 -a) – “Over” operator • Requires sorting
Order Dependence Right Wrong Everett 2001
Triangle Sorting • This is hard… Minimum Z won’t work… Maximum Z won’t work… Average Z won’t work…
Triangle Sorting • You can’t just use a comparison sort – “In. Front” is nontransitive… • In. Front(a, b) && In. Front(b, c) – BUT !In. Front(a, c) • QSort will break… c a b
Triangle Sorting (if you must) • Directed graph of overlap relationships – Topological sort gives drawing order
Triangle Sorting • Deal with cycles somehow: – Split geometry – Or: Give up and just break them
Triangle Sorting • Order doesn’t matter if triangle AABBs don’t overlap – Amax < Bmin || – Amin > Bmax – On each axis B A
Triangle Sorting • Overlap testing – If bounding boxes overlap, then… – S’ is “in front” S if: • All vertices of S are “outside” S’ – OR • All vertices of S’ are “inside” S
Triangle Sorting • Alternative: 2 D Test • Triangles are overlapping if and only if: – Vertex covers face • Interpolate Z in plane of “covered” face – OR – Edges intersect • Compute edge Zs at intersection point
Triangle Sorting • Spatial Partitioning – Avoid N^2 overlap tests – Only test pairs that share a cell – Collision detection…
Easy cases: Particles • Sorting Particles – Sort quads by cameraspace Z
Easy cases: Restricted View • Always above treeline: – Presort leaves bottom to top – Sort trees furthest to closest
Easy cases: Restricted View • Camera doesn’t rotate – Presort from top of screen to bottom during model placement Civilization V (Firaxis)
Easy cases: Convex • Draw backfaces, then frontfaces – And you might get away with it for nonconvex
Easy cases: Non-overlapping • Object-level sort will work if there is no AABB overlap – Sort meshes by center depth
Example: Car Windows • Draw opaque parts front to back – Z prime • Draw windows back to front – For each car, backfaces, then frontfaces
Order-Independent Transparency • Methods that let us draw in any order… • Sort at pixel level – Depth peeling – A buffers • Fake it – Alpha test – Stippling This is still very much an open problem…
Depth Peeling • Order-Independent Transparency – The hard way • One pass per depth layer – Each pass “peels” off frontmost layer Everett 2001
Depth Peeling // Clear rendertarget for each pixel p { color[p] = 0; alpha[p] = 1; } For i = 0 to depth_complexity { clear zbuffer; // // Rasterize again. . . zf is fragment z cf is fragment color af is fragment alpha for each fragment f in pixel p { // kill fragments from earlier layers if( i > 0 && zf <= prev_z[p] ) discard f; // this part is just ordinary z buffering if( zf < zbuffer[p] ) { zbuffer[p] = zf; layer_color[p] = cf; layer_alpha[p] = af; } } // composite this layer into the image for pixel p { prev_z[p] = zbuffer[p]; color[p] += alpha[p]*layer_color[p]*layer_alpha[p]; alpha[p] *= (1 -layer_alpha[p]); } } • Pro: – No sorting – Fixed memory overhead – Can choose to stop after first few layers • Con: – Outrageously expensive – Scales badly with depth complexity
A-Buffer • Linked list of fragments for every pixel – Color – Alpha – Depth • Store all fragments, sort/composite when done
A-Buffer • Pro: – Simple – Order-Independent • Con: – Unbounded memory! • How much depends on depth complexity – Linked list We are not pleased!
DX 11 OIT • A-Buffer insertion from pixel shader – Per-pixel head indices – Giant array of linked list nodes • See: – Nicolas Thibieroz Holger Gruen. “OIT and indirect illumination using dx 11 linked lists. ” Figure: Barta and Kovacs 2011
Alpha Testing • Kill pixel if alpha below threshold – On/Off transparency • Pro: – Order-independent – Cheap • Con: – Bilinear artifacts – Aliasing • Which MSAA won’t fix… Civilization V (Firaxis)
Distance Fields • A better alpha test… • Create “distance field” from mask image – Search for nearby texels • Threshold based on edge distance – Distance is linearly filterable Chris Greene, 2007
Screen Door Transparency • Stippling – Drop every other pixel • May work better if blurred away afterwards • Pro: – Simple – Cheap • Con: – Only one grey level
Alpha to Coverage • Subpixel screendoor A=1 – Turn off AA samples based on alpha • N opacity levels for N AA samples A=0. 75 – Order-independent – As cheap as alpha test and better looking – Works wonders for foliage A=0. 5 A=0. 25 Fully covered pixel @ 8 x. AA
Stochastic Transparency • Kill pixel with probability proportional to alpha – ZBuffer surviving pixels – Repeat numerous times and average results Enderton et. Al, 2010
Stochastic Transparency Enderton et. Al, 2010 Basic Stochastic See paper for noise reduction tricks… Depth Peeling
Refraction Because transparency just isn’t hard enough…
Refraction • Transmitted light is ‘bent’ Index of refraction (c/v) Speed of light in each medium Wikipedia
Raytraced Refraction • Calculate refracted ray direction Sunshine Lolly Pops – Next time… • Trace a new ray • Scale its color by 1 -a – For best results, use fresnel Everything is easy with raytracing…
Rasterized Refraction Newell 2004
Refraction Mapping • Render background to a texture • Rasterize refractive object • Compute refracted ray… – Sample texture at projected hit location …which we do not know… Hmm…
Refraction Mapping • …pick an arbitrary distance along the ray, and pretend that’s it… Whatever…
Rasterized Refraction In 2 D, projected ray turns into a UV offset It tends to be small You tend not to notice if its wrong… Newell 2004
Refraction Mapping • Improving it… – Sample old depth buffer, scale offset based on depth difference • Assume it hits the same thing…
Refraction Mapping • Still not perfect… – Can miss nearby objects
Refraction Mapping • Another option: – March along ray until occluded
Refraction Mapping • Another option: – March along ray until occluded
Refraction Mapping • Another option: – March along ray until occluded
Refraction Mapping • Another option: – March along ray until occluded
Refraction Mapping • This, too, is wrong… – But on a bumpmapped surface I doubt you’ll notice
Refraction Mapping • If you really want to fix it… – Render from multiple angles
Refraction Mapping • If you really want to fix it… – Render from multiple angles It’s still going to break…
- Slides: 55