summaryrefslogtreecommitdiff
path: root/VRCSDK3AvatarsLegacy/Assets/Avatars/Auri/materials/OptimizedShaders/332c2ca0/Includes/CGI_PoiDecal.cginc
blob: 5b5b102165e2924ba670b5f4d8256877583670b6 (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
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
#ifndef POI_DECAL
    #define POI_DECAL
    
    
    #if defined(PROP_DECALMASK) || !defined(OPTIMIZER_ENABLED)
        POI_TEXTURE_NOSAMPLER(_DecalMask);
    #endif
    
    #if defined(PROP_DECALTEXTURE) || !defined(OPTIMIZER_ENABLED)
        POI_TEXTURE_NOSAMPLER(_DecalTexture);
    #endif
    float4 _DecalColor;
    fixed _DecalTiled;
    float _DecalBlendType;
    half _DecalRotation;
    half2 _DecalScale;
    half2 _DecalPosition;
    half _DecalRotationSpeed;
    float _DecalEmissionStrength;
    float _DecalBlendAlpha;
    float _DecalHueShiftEnabled;
    float _DecalHueShift;
    float _DecalHueShiftSpeed;
    
    #ifdef GEOM_TYPE_BRANCH_DETAIL
        #if defined(PROP_DECALTEXTURE1) || !defined(OPTIMIZER_ENABLED)
            POI_TEXTURE_NOSAMPLER(_DecalTexture1);
        #endif
        float4 _DecalColor1;
        fixed _DecalTiled1;
        float _DecalBlendType1;
        half _DecalRotation1;
        half2 _DecalScale1;
        half2 _DecalPosition1;
        half _DecalRotationSpeed1;
        float _DecalEmissionStrength1;
        float _DecalBlendAlpha1;
        float _DecalHueShiftEnabled1;
        float _DecalHueShift1;
        float _DecalHueShiftSpeed1;
    #endif
    
    #ifdef GEOM_TYPE_FROND
        #if defined(PROP_DECALTEXTURE2) || !defined(OPTIMIZER_ENABLED)
            POI_TEXTURE_NOSAMPLER(_DecalTexture2);
        #endif
        float4 _DecalColor2;
        fixed _DecalTiled2;
        float _DecalBlendType2;
        half _DecalRotation2;
        half2 _DecalScale2;
        half2 _DecalPosition2;
        half _DecalRotationSpeed2;
        float _DecalEmissionStrength2;
        float _DecalBlendAlpha2;
        float _DecalHueShiftEnabled2;
        float _DecalHueShift2;
        float _DecalHueShiftSpeed2;
    #endif
    
    #ifdef DEPTH_OF_FIELD_COC_VIEW
        #if defined(PROP_DECALTEXTURE3) || !defined(OPTIMIZER_ENABLED)
            POI_TEXTURE_NOSAMPLER(_DecalTexture3);
        #endif
        float4 _DecalColor3;
        fixed _DecalTiled3;
        float _DecalBlendType3;
        half _DecalRotation3;
        half2 _DecalScale3;
        half2 _DecalPosition3;
        half _DecalRotationSpeed3;
        float _DecalEmissionStrength3;
        float _DecalBlendAlpha3;
        float _DecalHueShiftEnabled3;
        float _DecalHueShift3;
        float _DecalHueShiftSpeed3;
    #endif
    
    float2 decalUV(float uvNumber, float2 position, half rotation, half rotationSpeed, half2 scale)
    {
        float2 uv = poiMesh.uv[uvNumber];
        float2 decalCenter = position;
        float theta = radians(rotation + _Time.z * rotationSpeed);
        float cs = cos(theta);
        float sn = sin(theta);
        uv = float2((uv.x - decalCenter.x) * cs - (uv.y - decalCenter.y) * sn + decalCenter.x, (uv.x - decalCenter.x) * sn + (uv.y - decalCenter.y) * cs + decalCenter.y);
        uv = remap(uv, float2(0, 0) - scale / 2 + position, scale / 2 + position, float2(0, 0), float2(1, 1));
        return uv;
    }
    
    inline float3 decalHueShift(float enabled, float3 color, float shift, float shiftSpeed)
    {
        
        if (enabled)
        {
            color = hueShift(color, shift + _Time.x * shiftSpeed);
        }
        return color;
    }
    
    inline float applyTilingClipping(float enabled, float2 uv)
    {
        float ret = 1;
        
        if(!enabled)
        {
            if(uv.x > 1 || uv.y > 1 || uv.x < 0 || uv.y < 0)
            {
                ret = 0;
            }
        }
        return ret;
    }
    
    void applyDecals(inout float4 albedo, inout float3 decalEmission)
    {
        
        #if defined(PROP_DECALMASK) || !defined(OPTIMIZER_ENABLED)
            float4 decalMask = POI2D_SAMPLER_PAN(_DecalMask, _MainTex, poiMesh.uv[float(0)], float4(0,0,0,0));
        #else
            float4 decalMask = 1;
        #endif
        
        float4 decalColor = 1;
        float2 uv = 0;
        
        // Decal 0
        #if defined(PROP_DECALTEXTURE) || !defined(OPTIMIZER_ENABLED)
            uv = decalUV(float(0), float4(0.5,0.5,0,0), float(0), float(0), float4(1,1,0,0));
            decalColor = POI2D_SAMPLER_PAN(_DecalTexture, _MainTex, uv, float4(0,0,0,0)) * float4(1,1,1,1);
        #else
            decalColor = float4(1,1,1,1);
        #endif
        decalColor.rgb = decalHueShift(float(0), decalColor.rgb, float(0), float(0));
        decalColor.a *= applyTilingClipping(float(0), uv) * decalMask.r;
        albedo.rgb = lerp(albedo.rgb, customBlend(albedo.rgb, decalColor.rgb, float(0)), decalColor.a * float(1));
        
        decalEmission += decalColor.rgb * decalColor.a * float(0);
        
        #ifdef GEOM_TYPE_BRANCH_DETAIL
            // Decal 1
            #if defined(PROP_DECALTEXTURE1) || !defined(OPTIMIZER_ENABLED)
                uv = decalUV(float(0), float4(0.5,0.5,0,0), float(0), float(0), float4(1,1,0,0));
                decalColor = POI2D_SAMPLER_PAN(_DecalTexture1, _MainTex, uv, float4(0,0,0,0)) * float4(1,1,1,1);
            #else
                decalColor = float4(1,1,1,1);
            #endif
            decalColor.rgb = decalHueShift(float(0), decalColor.rgb, float(0), float(0));
            decalColor.a *= applyTilingClipping(float(0), uv) * decalMask.g;
            albedo.rgb = lerp(albedo.rgb, customBlend(albedo.rgb, decalColor.rgb, float(0)), decalColor.a * float(1));
            decalEmission += decalColor.rgb * decalColor.a * float(0);
        #endif
        #ifdef GEOM_TYPE_FROND
            // Decal 2
            #if defined(PROP_DECALTEXTURE2) || !defined(OPTIMIZER_ENABLED)
                uv = decalUV(float(0), float4(0.5,0.5,0,0), float(0), float(0), float4(1,1,0,0));
                decalColor = POI2D_SAMPLER_PAN(_DecalTexture2, _MainTex, uv, float4(0,0,0,0)) * float4(1,1,1,1);
            #else
                decalColor = float4(1,1,1,1);
            #endif
            decalColor.rgb = decalHueShift(float(0), decalColor.rgb, float(0), float(0));
            decalColor.a *= applyTilingClipping(float(0), uv) * decalMask.b;
            albedo.rgb = lerp(albedo.rgb, customBlend(albedo.rgb, decalColor.rgb, float(0)), decalColor.a * float(1));
            decalEmission += decalColor.rgb * decalColor.a * float(0);
        #endif
        #ifdef DEPTH_OF_FIELD_COC_VIEW
            // Decal 3
            #if defined(PROP_DECALTEXTURE3) || !defined(OPTIMIZER_ENABLED)
                uv = decalUV(float(0), float4(0.5,0.5,0,0), float(0), float(0), float4(1,1,0,0));
                decalColor = POI2D_SAMPLER_PAN(_DecalTexture3, _MainTex, uv, float4(0,0,0,0)) * float4(1,1,1,1);
            #else
                decalColor = float4(1,1,1,1);
            #endif
            decalColor.rgb = decalHueShift(float(0), decalColor.rgb, float(0), float(0));
            decalColor.a *= applyTilingClipping(float(0), uv) * decalMask.a;
            albedo.rgb = lerp(albedo.rgb, customBlend(albedo.rgb, decalColor.rgb, float(0)), decalColor.a * float(1));
            decalEmission += decalColor.rgb * decalColor.a * float(0);
        #endif
        
        albedo = saturate(albedo);
    }
    
#endif