Open utterances-bot opened 3 years ago
Hi Matt, thank you for your great writeup. I have a little issue with the section of "Applying To Ambient Lighting", I'm wondering how to generate SH coefficients for a spherical gaussian in runtime? I mean how to do the integral of a diffusion profile(represented by spherical gaussian) and SH probe? Could you explain more about it? Thank you so much.
Hey there! I have not any extensive work in terms of figuring out a good fit or approximation to generate SH coefficients from an arbitrary SG lobe. In the article I suggested following Ravi's work for approximating a Torrance-Sparrow NDF as SH coefficients using an exponential, which is probably a good start for approximating the normalized SG lobe that you would use for sub-surface scattering. Once you've done that, you can convolve it with your SH probe lighting with a simple multiply.
I would try something like this to start:
float3 l0Scatter = 1.0f;
float3 l1Scatter = exp(-Square(ScatterAmt * 1.0f));
float3 l2Scatter = exp(-Square(ScatterAmt * 2.0f));
SH9Color ambientSH = SampleSHProbe();
ambientSH.c[0] *= l0Scatter;
ambientSH.c[1] *= l1Scatter;
ambientSH.c[2] *= l1Scatter;
ambientSH.c[3] *= l1Scatter;
ambientSH.c[4] *= l2Scatter;
ambientSH.c[5] *= l2Scatter;
ambientSH.c[6] *= l2Scatter;
ambientSH.c[7] *= l2Scatter;
ambientSH.c[8] *= l2Scatter;
// Do the usual SH diffuse calculations
Approximating Subsurface Scattering With Spherical Gaussians
https://therealmjp.github.io/posts/sss-sg/