lcy
2025-01-02 c867ea92cce28ea0ceb312ef8e2f8e7e0888b1d6
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
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
// Upgrade NOTE: replaced '_Object2World' with 'unity_ObjectToWorld'
// Upgrade NOTE: replaced '_World2Object' with 'unity_WorldToObject'
// Upgrade NOTE: replaced 'mul(UNITY_MATRIX_MVP,*)' with 'UnityObjectToClipPos(*)'
 
 
Shader "Character/Character,Dissolve"
{
    Properties
    {
        _TintColor ("Tint Color", Vector) = (1, 1, 1, 1)
        _MainTex ("Main Texture", 2D) = "white" { }
        _ChanTex ("Spec Texture", 2D) = "white" { }
        _CubeMap ("Cubemap", CUBE) = "white" { }
        _Dissolve ("Dissolve", Range(3, 0)) = 3
        
        [HideInInspector] _Hit ("Hidden Hit", Float) = 0
        [HideInInspector] _BaTi ("Hidden BaTi", Float) = 0
    }
    
    Subshader
    {
        
        Tags { "Queue" = "Geometry" "IgnoreProjector" = "True" "LightMode" = "ForwardBase" }
        
        Pass
        {
            AlphaTest Greater 0
            Cull Off
            Fog
            {
                Mode Off
            }
            
            CGPROGRAM
            
            #pragma target 3.0
            #pragma vertex vert
            #pragma fragment frag
            
            
            #pragma multi_compile_fwdbase
            #pragma multi_compile QUALITY_LOW QUALITY_MED QUALITY_HGH
            
            #pragma exclude_renderers flash
            
            #include "UnityCG.cginc"
            #include "SnxxzCG.cginc"
            
            #if !defined(SHADOWS_OFF)
                #include "AutoLight.cginc"
            #endif
            
            struct vertexInput
            {
                half4 vertex: POSITION;
                half3 normal: NORMAL;
                half4 tangent: TANGENT;
                half2 texcoord: TEXCOORD0;
            };
            
            struct vertShader
            {
                // basics
                half4 pos: SV_POSITION;
                half2 uv1: TEXCOORD0;
                
                // frag lighting
                #ifdef QUALITY_HGH
                    half3 spc: TEXCOORD2;
                    half3 rim: TEXCOORD3;
                    half shd: TEXCOORD4;
                    //half3 lgt : TEXCOORD5;
                    half3 ref: TEXCOORD6;
                #endif
                #ifdef QUALITY_MED
                    half3 spc: TEXCOORD2;
                    half3 rim: TEXCOORD3;
                    half shd: TEXCOORD4;
                    //half3 lgt : TEXCOORD5;
                #endif
                #ifdef QUALITY_LOW
                    half3 spc: TEXCOORD2;
                    half3 rim: TEXCOORD3;
                    half shd: TEXCOORD4;
                    //half3 lgt : TEXCOORD5;
                #endif
                
                #if !defined(SHADOWS_OFF)
                    SHADOW_COORDS(7)
                #endif
            };
            // assets
            uniform sampler2D _MainTex;
            uniform sampler2D _ChanTex;
            uniform samplerCUBE _CubeMap;
            uniform float _Dissolve;
            
            // properties
            uniform half _Hit;
            uniform half _BaTi;
            uniform fixed3 _TintColor;
            
            vertShader vert(vertexInput v)
            {
                vertShader o;
                
                // pos and uv tex coord
                o.pos = UnityObjectToClipPos(v.vertex);
                o.uv1 = v.texcoord;
                
                // frag lighting
                #ifdef QUALITY_HGH
                    half3 worldVertex = mul(unity_ObjectToWorld, v.vertex).xyz;
                    half3 worldNormal = normalize(mul(half4(v.normal, 0.0), unity_WorldToObject).xyz);
                    half3 lightDirect = normalize(_WorldSpaceLightPos0.xyz);
                    half dotprod = max(0, dot(v.normal, normalize(ObjSpaceViewDir(v.vertex))));
                    o.spc = pow(dotprod, 10) * _Gbl_Spc;
                    o.rim = pow(1 - dotprod, 2) * _Gbl_Rim;
                    o.shd = max(0, dot(worldNormal, lightDirect));
                    o.ref = reflect(normalize(worldVertex - _WorldSpaceCameraPos), worldNormal);
                #endif
                #ifdef QUALITY_MED
                    half3 worldVertex = mul(unity_ObjectToWorld, v.vertex).xyz;
                    half3 worldNormal = normalize(mul(half4(v.normal, 0.0), unity_WorldToObject).xyz);
                    half3 lightDirect = normalize(_WorldSpaceLightPos0.xyz);
                    half dotprod = max(0, dot(v.normal, normalize(ObjSpaceViewDir(v.vertex))));
                    o.spc = pow(dotprod, 10) * _Gbl_Spc;
                    o.rim = pow(1 - dotprod, 2) * _Gbl_Rim;
                    o.shd = max(0, dot(worldNormal, lightDirect));
                #endif
                #ifdef QUALITY_LOW
                    half3 worldNormal = normalize(mul(half4(v.normal, 0.0), unity_WorldToObject).xyz);
                    half3 lightDirect = normalize(_WorldSpaceLightPos0.xyz);
                    half dotprod = max(0, dot(v.normal, normalize(ObjSpaceViewDir(v.vertex))));
                    o.spc = pow(dotprod, 10) * _Gbl_Spc * 0.5;
                    o.rim = pow(1 - dotprod, 2) * _Gbl_Rim;
                    o.shd = max(0, dot(worldNormal, lightDirect));
                #endif
                
                // hit effect
                //half hit = max ( 0, _Hit * pow ( 1.0 - max ( 0, dot ( v.normal, normalize ( ObjSpaceViewDir ( v.vertex ) ) ) ), 4 ) ); // hit effect
                //half3 bati = _BaTi * half3(1,0,0) * sin ( _Time.z * 3 );
                
                // vertex lighting
                //o.lgt = inlineLights ( worldVertex ) + hit + bati * bati;
                //o.lgt = hit + bati * bati;
                
                #if !defined(SHADOWS_OFF)
                    TRANSFER_SHADOW(o);
                #endif
                
                return o;
            }
            
            fixed4 frag(vertShader i): SV_Target
            {
                
                // textures
                fixed3 outcolor = tex2D(_MainTex, i.uv1).rgb;
                fixed outalpha = _Dissolve - outcolor.r - outcolor.g - outcolor.b;
                
                // channels
                #ifndef QUALITY_LOW
                    fixed3 channels = tex2D(_ChanTex, i.uv1);
                #endif
                
                // phong shadows
                #ifdef QUALITY_HGH
                    fixed shdlight = smoothstep(0.2, 0.3, i.shd * channels.b);
                #endif
                #ifdef QUALITY_MED
                    fixed shdlight = smoothstep(0.2, 0.3, i.shd * channels.b);
                #endif
                #ifdef QUALITY_LOW
                    fixed shdlight = step(0.25, i.shd);
                #endif
                
                // realtime shadows
                #if !defined(SHADOWS_OFF)
                    shdlight *= SHADOW_ATTENUATION(i);
                #endif
                
                // spec, rim
                #ifdef QUALITY_HGH
                    fixed3 spclight = i.spc * channels.r;
                    fixed3 rimlight = i.rim * channels.b;
                #endif
                #ifdef QUALITY_MED
                    fixed3 spclight = i.spc * channels.r;
                    fixed3 rimlight = i.rim * channels.b;
                #endif
                #ifdef QUALITY_LOW
                    fixed3 spclight = i.spc;
                    fixed3 rimlight = i.rim;
                #endif
                
                // reflection
                #ifdef QUALITY_HGH
                    fixed3 reflight = texCUBE(_CubeMap, i.ref);
                    reflight *= 0.5 + outcolor;
                    outcolor = lerp(outcolor, reflight, channels.g);
                #endif
                
                // composite
                #ifdef QUALITY_HGH
                    outcolor *= 0.2 + _Gbl_Amb + _Gbl_Lgt * shdlight;
                    outcolor *= 0.6 + spclight + rimlight;// + i.lgt;
                #endif
                #ifdef QUALITY_MED
                    outcolor *= 0.2 + _Gbl_Amb + _Gbl_Lgt * shdlight;
                    outcolor *= 0.5 + spclight + rimlight;// + i.lgt;
                #endif
                #ifdef QUALITY_LOW
                    outcolor *= 0.2 + _Gbl_Amb + _Gbl_Lgt * shdlight;
                    outcolor *= 0.4 + spclight + rimlight;// + i.lgt;
                #endif
                
                outcolor *= _TintColor;
                
                return fixed4(outcolor.rgb, outalpha);
            }
            
            ENDCG
            
        }
    }
    FallBack "Diffuse"
}