the Twarchive

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

Thew
@AmazingThew

Finally made a Cool Thing at work that I can show off!

Subsurface scattering in Unity/URP, using image-based diffusion profiles

Thew
@AmazingThew

I inherited an unfinished screenspace SSS project from a former coworker, and ended up needing to totally redesign the diffusion/sampling stuff

this is why I was yelling about importance sampling a few weeks ago lol

Thew
@AmazingThew

"image-based diffusion profiles" is a really cool-sounding way to say "I literally took a photo of my actual arm and used it to drive the scattering math"

Thew
@AmazingThew

Approach was basically: Take skin photo, do a bunch of photoshop layer math to subtract out ambient lighting and divide out skin tone, and then use the resulting gradient as a description of how each channel should be scattered

Thew
@AmazingThew

generate sample points, with their positions distributed by importance-sampling the image luminance and also some cool spiral stuff, and then randomizing the orientation via Ye Olde Blue Noise

Easy to describe but an UNBELIEVABLE headache to actually implement

Thew
@AmazingThew

Had to figure out how distribute points in fibonacci spirals whose density corresponds to an arbitrary radial image

I'm not remotely the first person to do this (it's basically how Unreal's Spiral Blur works, for example), but it was a giant pain to work out from principles lol

Thew
@AmazingThew

Here's a cool gif zooming the radius up and down

I should note: importance-sampling the diffusion profile in a spiral isn't a novel invention here; HDRP's SSS does it, and it's useful in lots of other applications

the novelty part is "what if I just used a pic of my arm lol"

Thew
@AmazingThew

Since the profile's just an image, you can just use photoshop or whatever to edit the colors lol. Or just take a pic of somebody else's arm. Unscientific and a bit inconvenient, but neat

Or just use totally arbitrary gradients, in case you need like, iridescent RGB gamer skulls

Thew
@AmazingThew

look at my cube

Thew
@AmazingThew

also the more rts this gets the more I'm like, oh wait maybe taking a photo of my own skin and then demonstrating it by applying it straight onto to a character with significantly darker skin is........ I dunno maybe questionable optics lol

Thew
@AmazingThew

no one's yelling at me or anything, but please don't read anything deeper into this than "that is the nicest-looking face model I have on hand for screenshots"

I'm aware SSS behavior isn't one-size-fits-all and you usually need to tune it for different skin colors

Thew
@AmazingThew

look at my waxen skull