summaryrefslogtreecommitdiff
path: root/VRCSDK3AvatarsLegacy/Assets/Avatars/Auri/materials/OptimizedShaders/nails/Includes/CGI_PoiMatcap.cginc
blob: e37315b86d06b199e8c4d186b9d7e90ada0bf931 (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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
#ifndef MATCAP
    #define MATCAP
    
    #if defined(PROP_MATCAP) || !defined(OPTIMIZER_ENABLED)
        UNITY_DECLARE_TEX2D_NOSAMPLER(_Matcap); float4 _Matcap_ST;
    #endif
    #if defined(PROP_MATCAPMASK) || !defined(OPTIMIZER_ENABLED)
        POI_TEXTURE_NOSAMPLER(_MatcapMask);
    #endif
    float _MatcapMaskInvert;
    float _MatcapBorder;
    float4 _MatcapColor;
    float _MatcapIntensity;
    float _MatcapReplace;
    float _MatcapMultiply;
    float _MatcapAdd;
    float _MatcapEnable;
    float _MatcapLightMask;
    float _MatcapEmissionStrength;
    float _MatcapNormal;
    float _MatcapHueShiftEnabled;
    float _MatcapHueShiftSpeed;
    float _MatcapHueShift;
    
    #ifdef COLOR_GRADING_HDR_3D
        #if defined(PROP_MATCAP2) || !defined(OPTIMIZER_ENABLED)
            UNITY_DECLARE_TEX2D_NOSAMPLER(_Matcap2);float4 _Matcap2_ST;
        #endif
        #if defined(PROP_MATCAP2MASK) || !defined(OPTIMIZER_ENABLED)
            POI_TEXTURE_NOSAMPLER(_Matcap2Mask);
        #endif
        float _Matcap2MaskInvert;
        float _Matcap2Border;
        float4 _Matcap2Color;
        float _Matcap2Intensity;
        float _Matcap2Replace;
        float _Matcap2Multiply;
        float _Matcap2Add;
        float _Matcap2Enable;
        float _Matcap2LightMask;
        float _Matcap2EmissionStrength;
        float _Matcap2Normal;
        float _Matcap2HueShiftEnabled;
        float _Matcap2HueShiftSpeed;
        float _Matcap2HueShift;
    #endif
    
    void blendMatcap(inout float4 finalColor, float add, float multiply, float replace, float4 matcapColor, float matcapMask, inout float3 matcapEmission, float emissionStrength
    #ifdef POI_LIGHTING
    , float matcapLightMask
    #endif
    #ifdef POI_BLACKLIGHT
    , uint blackLightMaskIndex
    #endif
    )
    {
        #ifdef POI_LIGHTING
            if (matcapLightMask)
            {
                matcapMask *= lerp(1, poiLight.rampedLightMap, matcapLightMask);
            }
        #endif
        #ifdef POI_BLACKLIGHT
            if(blackLightMaskIndex != 4)
            {
                matcapMask *= blackLightMask[blackLightMaskIndex];
            }
        #endif
        
        finalColor.rgb = lerp(finalColor.rgb, matcapColor.rgb, replace * matcapMask * matcapColor.a * .999999);
        finalColor.rgb *= lerp(1, matcapColor.rgb, multiply * matcapMask * matcapColor.a);
        finalColor.rgb += matcapColor.rgb * add * matcapMask * matcapColor.a;
        matcapEmission += matcapColor.rgb * emissionStrength * matcapMask * matcapColor.a;
    }
    
    void applyMatcap(inout float4 finalColor, inout float3 matcapEmission)
    {
        float4 matcap = 0;
        float matcapMask = 0;
        float4 matcap2 = 0;
        float matcap2Mask = 0;
        
        // Both matcaps use the same coordinates
        half3 worldViewUp = normalize(half3(0, 1, 0) - poiCam.viewDir * dot(poiCam.viewDir, half3(0, 1, 0)));
        half3 worldViewRight = normalize(cross(poiCam.viewDir, worldViewUp));
        
        // Matcap 1
        half2 matcapUV = half2(dot(worldViewRight, poiMesh.normals[float(1)]), dot(worldViewUp, poiMesh.normals[float(1)])) * float(0.43) + 0.5;
        
        #if defined(PROP_MATCAP) || !defined(OPTIMIZER_ENABLED)
            matcap = UNITY_SAMPLE_TEX2D_SAMPLER(_Matcap, _MainTex, TRANSFORM_TEX(matcapUV, _Matcap)) * float4(1,1,1,1);
        #else
            matcap = float4(1,1,1,1);
        #endif

        matcap.rgb *= float(1);
        #if defined(PROP_MATCAPMASK) || !defined(OPTIMIZER_ENABLED)
            matcapMask = POI2D_SAMPLER_PAN(_MatcapMask, _MainTex, poiMesh.uv[float(0)], float4(0,0,0,0));
        #else
            matcapMask = 1;
        #endif
        
        if (float(0))
        {
            matcapMask = 1 - matcapMask;
        }
        
        
        if(float(0))
        {
            matcap.rgb = hueShift(matcap.rgb, float(0) + _Time.x * float(0));
        }
        
        blendMatcap(finalColor, float(0), float(0), float(0), matcap, matcapMask, matcapEmission, float(1)
        #ifdef POI_LIGHTING
        , float(0)
        #endif
        #ifdef POI_BLACKLIGHT
        , _BlackLightMaskMatcap
        #endif
        );
        
        
        // Matcap 2
        #ifdef COLOR_GRADING_HDR_3D
            half2 matcapUV2 = half2(dot(worldViewRight, poiMesh.normals[float(1)]), dot(worldViewUp, poiMesh.normals[float(1)])) * float(0.43) + 0.5;
            #if defined(PROP_MATCAP2) || !defined(OPTIMIZER_ENABLED)
                matcap2 = UNITY_SAMPLE_TEX2D_SAMPLER(_Matcap2, _MainTex, TRANSFORM_TEX(matcapUV2, _Matcap2)) * float4(1,1,1,1);
            #else
                matcap2 = float4(1,1,1,1);
            #endif
            matcap2.rgb *= float(1);
            #if defined(PROP_MATCAP2MASK) || !defined(OPTIMIZER_ENABLED)
                matcap2Mask = POI2D_SAMPLER_PAN(_Matcap2Mask, _MainTex, poiMesh.uv[float(0)], float4(0,0,0,0));
            #else
                matcap2Mask = 1;
            #endif
            if (float(0))
            {
                matcap2Mask = 1 - matcap2Mask;
            }
            
            
            if(float(0))
            {
                matcap2.rgb = hueShift(matcap2.rgb, float(0) + _Time.x * float(0));
            }
            
            blendMatcap(finalColor, float(0), float(0), float(0), matcap2, matcap2Mask, matcapEmission, float(0)
            #ifdef POI_LIGHTING
            , float(0)
            #endif
            #ifdef POI_BLACKLIGHT
            , _BlackLightMaskMatcap2
            #endif
            );
        #endif
    }
    
#endif