Search Unity

Resolved Subsurface Scattering shader

Discussion in 'Shaders' started by NarberalTools, Aug 4, 2021.

  1. NarberalTools

    NarberalTools

    Joined:
    Jul 8, 2019
    Posts:
    63
    Hello! I have a problem. I found the SSS code, but it doesn't work as Filament shows. What's wrong?
    https://github.com/google/filament/...84d65/shaders/src/shading_model_subsurface.fs
    Code (CSharp):
    1. void SubSurfaceScattering_half(
    2. real3 Albedo,
    3. half3 mainLightColor,
    4. half3 mainLightDir,
    5. real3 ViewDirWS,
    6. real3 NormalWS,
    7. half3 SubsurfaceColor,
    8. half Thickness,
    9. half SubsurfacePower,
    10. out real3 Out)
    11. {
    12.     ViewDirWS = normalize(ViewDirWS);
    13.     Thickness = saturate(Thickness);
    14.     half NdotL = saturate(dot(NormalWS, mainLightDir));
    15.  
    16.     real scatterVoH = saturate(dot(ViewDirWS, -mainLightDir));
    17.     real forwardScatter = exp2(scatterVoH * SubsurfacePower - SubsurfacePower);
    18.     real backScatter = saturate(NdotL * Thickness + (1.0h - Thickness)) * 0.5h;
    19.     real subsurface = lerp(backScatter, 1.0h, forwardScatter) * (1.0h - Thickness);
    20.  
    21.     Out = Albedo + SubsurfaceColor * (subsurface * 0.3184h);
    22. }
     
    Last edited: Aug 4, 2021