the Twarchive

This is a record of a twitter thread, originally posted in 2022

Thew
@AmazingThew

well as long as we're still here, might as well show off some cool graphics work I've been doing at my Actual Job

Custom renderer for highly-scattering semitransparent materials in URP. Mainly meant for soft medical plastics, but also handles dirty/rough glass and acrylic nicely

Thew
@AmazingThew

More translucent surfaces scatter light through the back side

(fundamentally it's the same "render with reversed normals and add" approach other engines use for leaves/cloth/etc, but integrated into the rest of the shading math so it's modulated and tinted consistently)

Thew
@AmazingThew

Fun comparisons with the standard URP transparent shader. URP doesn't have tinting, refraction, scattering, or shadows, and we mostly make medical sims where nearly EVERYTHING is made of translucent plastic so we needed our own solution

Thew
@AmazingThew

notably I'm NOT trying to solve the order-independent transparency problem here. This is mainly for materials like milk-bottle plastic or frosted glass, which still mostly obscure what's behind them, so ZWrite is enabled

Handling the Glass Donut Nightmare Zone is future work lol

Thew
@AmazingThew

Translucent materials are blurry materials. Surfaces further from the interface are blurred less, so you need a variable-radius kernel that goes from 0 to, like, The Entire Screen

very tricky to do fast (can't use separable kernel, basically the bokeh problem at 2000px radius)

Thew
@AmazingThew

There are a lot of approaches you could take. I went with an adaptation of the spiral importance-sampling tech I was already using for subsurface scattering

Trades off noise for speed, but like, a TON of speed

Thew
@AmazingThew

importance sampling is a gigantic pain to figure out but it's like absurdly good at this lol

this is 20 samples with a blur radius of something like 600px

sure it's noisy and there's fireflies, but like, a separable blur would take 2400 taps and this is 20

Thew
@AmazingThew

Even dialing it all the way down to *one* sample per pixel still looks surprisingly good on typical materials. Works even better in motion since you can randomize the tap locations every frame (I cannot show you this because it OBLITERATES video compression lmao)

one tap blur!

Thew
@AmazingThew

Obviously with temporal reprojection tricks and/or a good denoiser you could smooth this out a whole lot

that's also on the Future Work list right now; would like to do it but I don't know when I'll have time

Thew
@AmazingThew

Also built a whole material inspector for it, so from the artists' perspective it works exactly like the regular URP shaders

conceptually it's split into an "exterior" layer that acts like a PBR surface coating, and an "interior" layer that controls scattering/tint/refraction

Thew
@AmazingThew

All the surface parameters work the same as URP Lit, with PBR maps, occlusion, normals, tiling details/masks, etc, and the translucency parameters can also be texture-driven

You can get a ton of realism by modulating the blur radius by roughness, so matte areas also scatter more

Thew
@AmazingThew

state of the art Moistened Orb Technology