summaryrefslogtreecommitdiff
path: root/VRCSDK3AvatarsLegacy/Assets/Avatars/Auri/materials/OptimizedShaders/nails/Includes/CGI_PoiRGBMask.cginc
blob: d2cba7770903e9362d8a7d2be246d09caf2cfb1b (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
161
162
163
164
165
166
167
168
#ifndef POI_RGBMASK
    #define POI_RGBMASK
    #if defined(PROP_RGBMASK) || !defined(OPTIMIZER_ENABLED)
        UNITY_DECLARE_TEX2D_NOSAMPLER(_RGBMask); float4 _RGBMask_ST;
    #endif
    #if defined(PROP_REDTEXURE) || !defined(OPTIMIZER_ENABLED)
        UNITY_DECLARE_TEX2D_NOSAMPLER(_RedTexure); float4 _RedTexure_ST;
    #endif
    #if defined(PROP_GREENTEXTURE) || !defined(OPTIMIZER_ENABLED)
        UNITY_DECLARE_TEX2D_NOSAMPLER(_GreenTexture); float4 _GreenTexture_ST;
    #endif
    #if defined(PROP_BLUETEXTURE) || !defined(OPTIMIZER_ENABLED)
        UNITY_DECLARE_TEX2D_NOSAMPLER(_BlueTexture); float4 _BlueTexture_ST;
    #endif
    
    #ifdef GEOM_TYPE_MESH
        #if defined(PROP_RGBNORMALR) || !defined(OPTIMIZER_ENABLED)
        #endif
        #if defined(PROP_RGBNORMALG) || !defined(OPTIMIZER_ENABLED)
        #endif
        #if defined(PROP_RGBNORMALB) || !defined(OPTIMIZER_ENABLED)
        #endif
            POI_NORMAL_NOSAMPLER(_RgbNormalR);
            POI_NORMAL_NOSAMPLER(_RgbNormalG);
            POI_NORMAL_NOSAMPLER(_RgbNormalB);
        float _RgbNormalsEnabled;
    #endif
    
    float4 _RedColor;
    float4 _GreenColor;
    float4 _BlueColor;
    
    float2 _RGBMaskPanning;
    float2 _RGBRedPanning;
    float2 _RGBGreenPanning;
    float2 _RGBBluePanning;
    
    float _RGBBlendMultiplicative;
    
    float _RGBMaskUV;
    float _RGBRed_UV;
    float _RGBGreen_UV;
    float _RGBBlue_UV;
    float _RGBUseVertexColors;
    float _RGBNormalBlend;
    
    static float3 rgbMask;
    
    void calculateRGBNormals(inout half3 mainTangentSpaceNormal)
    {
        #ifdef GEOM_TYPE_MESH
            #ifndef RGB_MASK_TEXTURE
                #define RGB_MASK_TEXTURE
                
                if (float(0))
                {
                    rgbMask = poiMesh.vertexColor.rgb;
                }
                else
                {
                    #if defined(PROP_RGBMASK) || !defined(OPTIMIZER_ENABLED)
                        rgbMask = POI2D_SAMPLER_PAN(_RGBMask, _MainTex, poiMesh.uv[float(0)], float4(0,0,0,0)).rgb;
                    #else
                        rgbMask = 1;
                    #endif
                }
            #endif
            
            
            if(float(0))
            {
                
                if(float(0) == 0)
                {
                    
                    if(float(0) > 0)
                    {
                        half3 normalToBlendWith = UnpackScaleNormal(POI2D_SAMPLER_PAN(_RgbNormalR, _MainTex, poiMesh.uv[float(0)], float4(0,0,0,0)), float(0));
                        mainTangentSpaceNormal = lerp(mainTangentSpaceNormal, normalToBlendWith, rgbMask.r);
                    }

                    
                    if(float(0) > 0)
                    {
                        half3 normalToBlendWith = UnpackScaleNormal(POI2D_SAMPLER_PAN(_RgbNormalG, _MainTex, poiMesh.uv[float(0)], float4(0,0,0,0)), float(0));
                        mainTangentSpaceNormal = lerp(mainTangentSpaceNormal, normalToBlendWith, rgbMask.g);
                    }

                    
                    if(float(0) > 0)
                    {
                        half3 normalToBlendWith = UnpackScaleNormal(POI2D_SAMPLER_PAN(_RgbNormalB, _MainTex, poiMesh.uv[float(0)], float4(0,0,0,0)), float(0));
                        mainTangentSpaceNormal = lerp(mainTangentSpaceNormal, normalToBlendWith, rgbMask.b);
                    }

                    return;
                }
                else
                {
                    half3 newNormal = UnpackScaleNormal(POI2D_SAMPLER_PAN(_RgbNormalR, _MainTex, poiMesh.uv[float(0)], float4(0,0,0,0)), float(0) * rgbMask.r);
                    half3 normalToBlendWith = UnpackScaleNormal(POI2D_SAMPLER_PAN(_RgbNormalG, _MainTex, poiMesh.uv[float(0)], float4(0,0,0,0)), float(0) * rgbMask.g);
                    newNormal = BlendNormals(newNormal, normalToBlendWith);
                    normalToBlendWith = UnpackScaleNormal(POI2D_SAMPLER_PAN(_RgbNormalB, _MainTex, poiMesh.uv[float(0)], float4(0,0,0,0)), float(0) * rgbMask.b);
                    newNormal = BlendNormals(newNormal, normalToBlendWith);
                    mainTangentSpaceNormal = BlendNormals(newNormal, mainTangentSpaceNormal);
                    return;
                }
            }
        #endif
    }
    
    float3 calculateRGBMask(float3 baseColor)
    {
        //If RGB normals are in use this data will already exist
        #ifndef RGB_MASK_TEXTURE
            #define RGB_MASK_TEXTURE
            
            
            if (float(0))
            {
                rgbMask = poiMesh.vertexColor.rgb;
            }
            else
            {
                #if defined(PROP_RGBMASK) || !defined(OPTIMIZER_ENABLED)
                    rgbMask = POI2D_SAMPLER_PAN(_RGBMask, _MainTex, poiMesh.uv[float(0)], float4(0,0,0,0)).rgb;
                #else
                    rgbMask = 1;
                #endif
            }
        #endif
        #if defined(PROP_REDTEXURE) || !defined(OPTIMIZER_ENABLED)
            float4 red = POI2D_SAMPLER_PAN(_RedTexure, _MainTex, poiMesh.uv[float(0)], float4(0,0,0,0));
        #else
            float4 red = 1;
        #endif
        #if defined(PROP_GREENTEXTURE) || !defined(OPTIMIZER_ENABLED)
            float4 green = POI2D_SAMPLER_PAN(_GreenTexture, _MainTex, poiMesh.uv[float(0)], float4(0,0,0,0));
        #else
            float4 green = 1;
        #endif
        #if defined(PROP_BLUETEXTURE) || !defined(OPTIMIZER_ENABLED)
            float4 blue = POI2D_SAMPLER_PAN(_BlueTexture, _MainTex, poiMesh.uv[float(0)], float4(0,0,0,0));
        #else
            float4 blue = 1;
        #endif
        
        
        if(float(0))
        {
            float3 RGBColor = 1;
            RGBColor = lerp(RGBColor, red.rgb * float4(1,1,1,1).rgb, rgbMask.r * red.a * float4(1,1,1,1).a);
            RGBColor = lerp(RGBColor, green.rgb * float4(1,1,1,1).rgb, rgbMask.g * green.a * float4(1,1,1,1).a);
            RGBColor = lerp(RGBColor, blue.rgb * float4(1,1,1,1).rgb, rgbMask.b * blue.a * float4(1,1,1,1).a);
            
            baseColor *= RGBColor;
        }
        else
        {
            baseColor = lerp(baseColor, red.rgb * float4(1,1,1,1).rgb, rgbMask.r * red.a * float4(1,1,1,1).a);
            baseColor = lerp(baseColor, green.rgb * float4(1,1,1,1).rgb, rgbMask.g * green.a * float4(1,1,1,1).a);
            baseColor = lerp(baseColor, blue.rgb * float4(1,1,1,1).rgb, rgbMask.b * blue.a * float4(1,1,1,1).a);
        }
        
        return baseColor;
    }
    
#endif