summaryrefslogtreecommitdiff
path: root/VRCSDK3AvatarsLegacy/Assets/Avatars/Auri/materials/OptimizedShaders/body/Includes/CGI_PoiIridescence.cginc
blob: 364e7c704e98761adef3311b38ee99fa925b4d8b (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
76
77
#ifndef POI_IRIDESCENCE
    #define POI_IRIDESCENCE
    #if defined(PROP_IRIDESCENCERAMP) || !defined(OPTIMIZER_ENABLED)
        UNITY_DECLARE_TEX2D_NOSAMPLER(_IridescenceRamp); float4 _IridescenceRamp_ST;
    #endif
    #if defined(PROP_IRIDESCENCEMASK) || !defined(OPTIMIZER_ENABLED)
        UNITY_DECLARE_TEX2D_NOSAMPLER(_IridescenceMask); float4 _IridescenceMask_ST;
    #endif
    #if defined(PROP_IRIDESCENCENORMALMAP) || !defined(OPTIMIZER_ENABLED)
        UNITY_DECLARE_TEX2D_NOSAMPLER(_IridescenceNormalMap); float4 _IridescenceNormalMap_ST;
    #endif
    float _IridescenceNormalUV;
    float _IridescenceMaskUV;
    float _IridescenceNormalSelection;
    float _IridescenceNormalIntensity;
    float _IridescenceNormalToggle;
    float _IridescenceIntensity;
    fixed _IridescenceAddBlend;
    fixed _IridescenceReplaceBlend;
    fixed _IridescenceMultiplyBlend;
    float _IridescenceEmissionStrength;
    
    //global
    #if defined(PROP_IRIDESCENCENORMALMAP) || !defined(OPTIMIZER_ENABLED)
        float3 calculateNormal(float3 baseNormal)
        {
            
            float3 normal = UnpackScaleNormal(UNITY_SAMPLE_TEX2D_SAMPLER(_IridescenceNormalMap, _MainTex, TRANSFORM_TEX(poiMesh.uv[_IridescenceNormalUV], _IridescenceNormalMap)), _IridescenceNormalIntensity);
            return normalize(
                normal.x * poiMesh.tangent +
                normal.y * poiMesh.binormal +
                normal.z * baseNormal
            );
        }
    #endif
    void applyIridescence(inout float4 albedo, inout float3 IridescenceEmission)
    {
        float3 normal = poiMesh.normals[_IridescenceNormalSelection];
        
        #if defined(PROP_IRIDESCENCENORMALMAP) || !defined(OPTIMIZER_ENABLED)
            // Use custom normal map
            
            if (_IridescenceNormalToggle)
            {
                normal = calculateNormal(normal);
            }
        #endif
        
        float ndotv = dot(normal, poiCam.viewDir);
        
        #if defined(PROP_IRIDESCENCERAMP) || !defined(OPTIMIZER_ENABLED)
            float4 iridescenceColor = UNITY_SAMPLE_TEX2D_SAMPLER(_IridescenceRamp, _MainTex, 1 - abs(ndotv));
        #else
            float4 iridescenceColor = 1;
        #endif
        
        #if defined(PROP_IRIDESCENCEMASK) || !defined(OPTIMIZER_ENABLED)
            float4 iridescenceMask = UNITY_SAMPLE_TEX2D_SAMPLER(_IridescenceMask, _MainTex, TRANSFORM_TEX(poiMesh.uv[_IridescenceMaskUV], _IridescenceMask));
        #else
            float4 iridescenceMask = 1;
        #endif
        #ifdef POI_BLACKLIGHT
            if(_BlackLightMaskIridescence != 4)
            {
                iridescenceMask *= blackLightMask[_BlackLightMaskIridescence];
            }
        #endif
        
        
        albedo.rgb = lerp(albedo.rgb, saturate(iridescenceColor.rgb * _IridescenceIntensity), iridescenceColor.a * _IridescenceReplaceBlend * iridescenceMask);
        albedo.rgb += saturate(iridescenceColor.rgb * _IridescenceIntensity * iridescenceColor.a * _IridescenceAddBlend * iridescenceMask);
        albedo.rgb *= saturate(lerp(1, iridescenceColor.rgb * _IridescenceIntensity, iridescenceColor.a * _IridescenceMultiplyBlend * iridescenceMask));
        
        IridescenceEmission = saturate(iridescenceColor.rgb * _IridescenceIntensity) * iridescenceColor.a * iridescenceMask * _IridescenceEmissionStrength;
    }
    
#endif