Recently, I spent some time reading papers / UE4 shaders code / various web pages about skin shading models. It was very interesting and I've got some achievements which I want to share.
Sub Surface Scattering
Skin is translucent surface and usually rendered with shading models based on scattering theory.
Light enters at some point and travels inside of translucent tissue and comes out at other point. This looks simple but needs some tricks to work in real time renderer.
Diffusion Profile
All of proper skin shading models are based on this theory and data. It describes how light is scattered along the distance from incident point.
People measures data how much light is scattered using real skin.
![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhc8zg1pCzkGp7_s-13clX2WcCFaKL7sXyua9RXFqT7ZmrxqK3PlAHjR12C8_m_gCDPaxX1kE-wQKBPcCETc4uJCsy6MDrJ6Qe6NeGW3Up2ll7Q6v21fFSuaWC_2ekdPXTZ1aAdU5BlRzU/s1600/diffusion_img.png) |
Perpendicular laser on real skin |
![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgealQMaZLRb084xEIAiKN1GxQnGkMX2ZrFeDKRRt5Em0wrE4SRYkuQjvEAwylVydnHPl9iDr5Kq-2PdW8EniHKc0abNhf4qZsgr6NPx4o4Jll0-szmiu0xobbIPggWFfBVfSjiX6JjzQo/s1600/diffusion_curve.png) |
Different diffusion curve among color channel |
![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg8CqKkx9L7PK3XQHusrP7TLw9isU8VF0_LIHqq_1MB4WiPrlpd3Jn4eue7N2C56THiZd6JeAAmhFleKQkrj2YcpEHGTGs8KAS_wmmhftBLAMwtNuw3IQ8U7QjzqmfuExCQLI6AgeZkJHU/s1600/gaussian.png) |
Using Gaussian function to fit this curve |
![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg8UX-UhrR1j1arxQQ6qS8_TUf_DAEbBXI9X7kKxADMgWyhP5V1bSN_8MNHHkBoYqa3QtDKqgqlhMy7Y3rVZnZ8oeJn2RqELYVtPi6zrus3Dx6mg7DRs5nuJRI1h5XX4Ln7ECTc67y7-yg/s320/diffusion_profile_table.png) |
Actual fitted gaussian parameters |
And the curves are fitted to sum of gaussian functions. this fitted function is used to blur adjacent diffuse color pixels or to pre-integrate diffuse BRDF texture. I was curious that are there any measured data from asian or african american on the internet but got no success. What about some alien whose blood is blue? Maybe I should worry later about this.
Screen Space Sub Surface Scattering
Jorge Jimenez's method.
http://www.iryoku.com/sssss/
The core ideas is blurring diffuse irradiance in screen space using fitted gaussian kernel. Of course blur distance is adjusted according to depth and angle to be accurate.
This technique is well suited to deferred renderer and the quality is very good.
But some people would not agree this is the best method due to the low quality of low default diffuse irradiance and too much blur look. but this is still great skin rendering method.
I didn't do much research on this because UE4 version of this(SubSurfaceProfile) is perfect in my opinion.
Pre-Integrated Skin (Penner)
Another popular method is Penner's Pre-Integrated Skin.
https://www.slideshare.net/leegoonz/penner-preintegrated-skin-rendering-siggraph-2011-advances-in-realtime-rendering-course
The basic idea is to assume skin surface as circle and integrate diffusion profile according to two parameter(incicent angle and curvature of skin surface). He thinks that these two factors are most important parts of skin scattering.
This generates texture like below.
Actual hlsl shader code would be like,
float3 ScatteredLight = Texture2DSampleLevel(PreIntegratedBRDF, PreIntegratedBRDFSampler,
float2(saturate(dot(N, L) * .5 + .5), Curvature), 0).rgb;
|
U : indexed by cosine
V : indexed by r(curvature)
There are many other details in this technique, but the basic idea is like this.
UE4 version of Pre-Integrated Skin Shading model
The overal structure is same,
-Pre-integrated BRDF texture(index by cosine and curvature like parameter)
But there are several difference between UE4 version and original.
-Pre-Interated Skin BRDF is applied only on shadowed region.
Unshadewd region is shaded by default lit(this is incorrect and make skin too bright)
-BRDF texture doesn't have different diffusion profile among color channel(frequency)
![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg8ZcGXsoWRVmCqypNRw6cmf1ALV9Fb7nluZ5ZHqQ8ggUkecqNM07lVyWJZjOrOZSjtwcQan0ByJrjxBVmUHol4v1PO-8UOjD1RFuj0CGtmwSLc3wBytT6xQAcQlubyzIl0HRpTfwA-96E/s320/preintegrated-ue4.png) |
Texture tone is gray |
BRDF texture contains grayscale(same diffusion among color channel) and multiplied by subsurface color provided by artist.
Actually subsurface color by artist is not that bad idea. But it is very difficult to make realistic human skin using UE4's pre-integrated skin shading model.
I think this is why epic recommends SubSurfaceProfile model as high quality skin rendering.
By proper implementation according to oroginal paper, we can get below.
![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj3IWbOj-CUdkRNBbqtsibUrgzq_lk390CzxSomsi5Kc-NQwI5j4c3VaEmVEtDt0Kn2lOof8TgNruOv86ZOKKmZ_YxkLpd_N-QnSl0OrYuPyHtc2OpOG8rAKFdNPl_VsBDJb1vSJ5Eqo1s/s320/preintegrated-impl.png) |
My implementation |
Due to the limitation of deferred renderer, I could not implement normal bluring, It could look a little bit harsh with rough normal map. but it was ok with our art direction. (we could control our normal map).
Translucency
With these two methods, rendered human skin already looks like skin. But we need more.
Because skin is translucent tissue, incident lights actually transmit through thin parts.
And should have effects like below,
![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg7ueUscJxrjvD3JNiGe9_3SQkyd2GLCT2Inb3nSf0nUYHjVR-qfOrhv-3oNBSpJBrr4zd8eMWdaRxWxJDFTvQb48JahYjz2JOPqao9aFclb4l5sLSh7XVBgLZi5_dTvYlodBb0VxonWGs/s320/transmittance.png) |
light transmitted through thin ear. |
And Jorge Jimenez wrote paper about this.
The most important idea is calculating thickness from light incident point to actual shading point. With this thickness we could know how much light will transmit through.
We know these two points in shadow projection shader. (Shadow depth value and shaded world point)
Actually, UE4 is already calculating this transmittance value and define this as "Sub Surface Shadow Term". This term is usually multiplied to various subsurface lighting terms.(ex: TWO_SIDED_FOILAGE). But it seems that both of two skin shading models lacks this effect.
So I added translucency effect of Jorge Jimenez to Pre-Integrated skin shading model.
![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhhr4ohpiGVHRK4tgz2-0SK2N8t4tUpXL-6SkT0-bmWTFqpczPEimLBK4He70FAvVWiSxZ-D8YPEHp0f_Npg4m0AUNjfGPmi9WYutdBUMLD7Cvxk76DNnvggW1U48gQB9PasBjJ1S1bbTM/s320/transmittance2.png) |
With environment lighting |
Due to the shadow depth range precision issue, It seems that spot light is most accurate for calculating thickness(transmittance or sub surface shadow term). Point Light lacks this feature.
Skin BRDF with Indirect Lighting
All of the above methods are for direct lightings. Sometimes game characters could be in lighting conditions which have only indirect lighting(shadowed region). Then all of these fancy skin shading will disappear.
UE4 multiplies subsurface color to diffuse irradiance(from Spherical harmonics probe). It could be ok with that. But there is something we could do for this sad situation. The graphics programmers in Ready At Dawn suggest excellent technique for applying skin BRDF with indirect probe.
The idea is like this,
We use clamped cosine as transfer function which will be dotted with irradiance spherical harmonics probe. This is zonal harmonics coefficients projected to represent clamped cosine function.
The idea of RAD programmers is to use special zonal harmonics transfer function which is projected to represent diffuse skin BRDF. They explained their idea kindly in there paper.
http://blog.selfshadow.com/publications/s2013-shading-course/rad/s2013_pbs_rad_notes.pdf
I implemented this and below image is generated zonal harmonics coefficients indexed by curvature.
X axis is curvature and Y Axis are zonal harmonics order.
![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj-9bdyukbvor-59amuq5WUucPmQJ9yhyi3V5aRT5lt6tJJ_13SQYTLYpuHnL1OSPOU2VzQQ4Bwaiqe0LQ091FOPqHnfHDbxsaz06FV7CSrwz5dCeM8L_T2rdTcUMPRU0ACdSD11IHR31g/s1600/zh.png) |
First row : order 0, Second row : order 1, Third row : order 2
x axis : surface curvature
(with 30000 randome sample during monte carlo integration) |
And this is the result. The result was quite impressive.
You can compare with normal diffuse irradiance from light probe.
Lighting condition used.
![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEivYzWHxwXJusyHBoTWHX5cdnSdWIQWh0h0Nkn9MH2bURWnkSiTqckDSKeIeL826DplHuu8s9wTgLfr1WbLy9ATOMN8sUNzu6m78iSjnELVe06QUM5SLoQd79kKAMiX3YR7Cui-_HIlVTY/s320/env_lighting.png) |
Emissive sphere and 1 light probe(no direct light) |
3 zonal harmonics coefficients are projected using below generation code.
Order 0
_func = [this](double theta, double rInv)
{
float R = rInv * 255;
float radius = 2.0f * 1.f / ((R + 1) / (float)SizeX);
float cosTheta = FMath::Cos(theta);
auto BRDF = IntegrateDiffuseScatteringOnRing(cosTheta, radius);
return 0.28209479177 * BRDF.X *sin(theta);
};
D0R = 2 * PI * MonteCarloIntegral1D(0, PI / 2, NumMonteCarloSample, rInv);
Order 1
_func = [this](double theta, double rInv)
{
float R = rInv * 255;
float radius = 2.0f * 1.f / ((R + 1) / (float)SizeX);
float cosTheta = FMath::Cos(theta);
auto BRDF = IntegrateDiffuseScatteringOnRing(cosTheta, radius);
return 0.4886025119 * cos(theta) * BRDF.X * sin(theta);
};
D1R = 2 * PI * MonteCarloIntegral1D(0, PI / 2, NumMonteCarloSample, rInv);
Order 2
_func = [this](double theta, double rInv)
{
float R = rInv * 255;
float radius = 2.0f * 1.f / ((R + 1) / (float)SizeX);
float cosTheta = FMath::Cos(theta);
auto BRDF = IntegrateDiffuseScatteringOnRing(cosTheta, radius);
return 0.31539156525 * (3 * pow(cos(theta), 2) -1) * BRDF.X *sin(theta);
};
D2R = 2 * PI * MonteCarloIntegral1D(0, PI / 2, NumMonteCarloSample, rInv);
I used skin BRDF integration from this
link.
I think maybe there will be more advanced skin rendering technique later. But these are best for now.