summaryrefslogtreecommitdiff
path: root/VRCSDK3AvatarsLegacy/Assets/Avatars/Auri/materials/OptimizedShaders/body/Includes/CGI_PoiSubsurfaceScattering.cginc
blob: fe4836eebe0d5bbec68cdcc5312da9e376566fac (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#ifndef SUBSURFACE
    #define SUBSURFACE
    /*
    float _SSSThickness;
    half4 _SSSColor;
    float _SSSPointLightDirectionality;
    float _SSSNormalOffset;
    float _SSSStrength;
    float _SSSExponent;
    float _SSSNDotL;
    float _SSSConstant;
    
    #if defined(PROP_SSSTHICKNESSMAP) || !defined(OPTIMIZER_ENABLED)
        POI_TEXTURE_NOSAMPLER(_SSSThicknessMap);
    #endif
    
    half3 calculateSubsurfaceScattering(const float4 albedo)
    {
        #if defined(PROP_SSSTHICKNESSMAP) || !defined(OPTIMIZER_ENABLED)
            float thicknessMap = 1 - POI2D_SAMPLER_PAN(_SSSThicknessMap, _MainTex, poiMesh.uv[float(0)], float4(0,0,0,0));
        #else
            float thicknessMap = 1;
        #endif
        
        half4 translucencyColor = float4(1,0,0,1);
        float3 lightDir = poiLight.direction;
        
        #ifdef FORWARD_BASE_PASS
            half tLitDot = saturate(dot((poiLight.direction + poiMesh.normals[1] * _SSSNormalOffset), -poiCam.viewDir));
        #else
            float3 lightDirectional = normalize(_WorldSpaceLightPos0.xyz - poiCam.worldPos);
            lightDir = normalize(lerp(poiLight.direction, lightDirectional, _SSSPointLightDirectionality));
            half tLitDot = saturate(dot((poiLight.direction + poiMesh.normals[1] * _SSSNormalOffset), -poiCam.viewDir));
        #endif
        
        tLitDot = exp2(-_SSSExponent * (1 - tLitDot)) * _SSSStrength;
        float NDotL = abs(dot(poiLight.direction, poiMesh.normals[1]));
        tLitDot *= lerp(1, NDotL, _SSSNDotL);
        
        half translucencyOcclusion = lerp(1, thicknessMap, _SSSThickness);
        half translucencyAtten = (tLitDot + _SSSConstant * (NDotL + 0.1)) * translucencyOcclusion;
        
        return translucencyAtten * albedo.rgb * translucencyColor.rgb * poiLight.lightMap * poiLight.color;
    }
    */
    
    float _SSSThicknessMod;
    float _SSSSCale;
    float _SSSPower;
    float _SSSDistortion;
    float4 _SSSColor;
    float _EnableSSS;
    
    #if defined(PROP_SSSTHICKNESSMAP) || !defined(OPTIMIZER_ENABLED)
        POI_TEXTURE_NOSAMPLER(_SSSThicknessMap);
    #endif
    
    float3 calculateSubsurfaceScattering()
    {
        #if defined(PROP_SSSTHICKNESSMAP) || !defined(OPTIMIZER_ENABLED)
            float SSS = 1 - POI2D_SAMPLER_PAN(_SSSThicknessMap, _MainTex, poiMesh.uv[float(0)], float4(0,0,0,0));
        #else
            float SSS = 1;
        #endif
        half3 vLTLight = poiLight.direction + poiMesh.normals[0] * float(1);
        half flTDot = pow(saturate(dot(poiCam.viewDir, -vLTLight)), float(5)) * float(0.25);
        #ifdef FORWARD_BASE_PASS
            half3 fLT = (flTDot) * saturate(SSS + - 1 * float(0));
        #else
            half3 fLT = poiLight.attenuation * (flTDot) * saturate(SSS + - 1 * float(0));
        #endif
        
        return fLT * poiLight.color * float4(1,0,0,1) * poiLight.attenuation;
    }
#endif