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
 
Shader "Character/CreateRole"
{
    Properties
    {
        _MainTex ("Main Texture", 2D) = "white" { }
        _NormTex ("Norm Texture", 2D) = "white" { }
        _ChanTex ("Channels Texture", 2D) = "white" { }
        _SpecTex ("Spec Texture", 2D) = "white" { }
        _CubeMap ("Cubemap", CUBE) = "white" { }
        
        _FlowColor ("FlowColor", Color) = (1, 1, 1, 1)
        _FlowSpeed ("FlowSpeed", Range(0, 1)) = 0
        _FlowIntensity ("FlowIntensity", Range(0, 2)) = 0
        _FlowDirectionH ("FlowDirectionH", Range(-1, 1)) = 0
        _FlowDirectionV ("FlowDirectionV", Range(-1, 1)) = 0
        
        _SelfLuminousColor ("SelfLuminousColor", Color) = (1, 1, 1, 1)
        _SelfLuminousSpeed ("SelfLuminousSpeed", Range(0, 1)) = 0
        _SelfLuminousIntensity ("SelfLuminousIntensity", Range(0, 2)) = 0
        
        _SelfLuminousMin ("SelfLuminousMin", Range(0, 1)) = 0
        _SelfLuminousMax ("SelfLuminousMax", Range(0, 1)) = 1
    }
    
    Subshader
    {
        
        Tags { "Queue" = "Transparent" "IgnoreProjector" = "True" "LightMode" = "ForwardBase" }
        
        Pass
        {
            Cull Back
            Fog
            {
                Mode Off
            }
            
            Blend SrcAlpha OneMinusSrcAlpha
            
            CGPROGRAM
            
            #pragma target 3.0
            #pragma vertex vert
            #pragma fragment frag
            
            #pragma multi_compile_fwdbase
            #pragma exclude_renderers flash
            
            #include "UnityCG.cginc"
            #include "SnxxzCG.cginc"
            
            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
                half3 nrm: TEXCOORD1;
                half3 tng: TEXCOORD2;
                half3 bin: TEXCOORD3;
                half3 cam: TEXCOORD4;
                half3 ref: TEXCOORD6;
            };
            // assets
            uniform sampler2D _MainTex;
            uniform sampler2D _NormTex;
            uniform sampler2D _ChanTex;
            uniform sampler2D _SpecTex;
            uniform samplerCUBE _CubeMap;
            
            
            fixed4 _FlowColor;
            fixed _FlowSpeed;
            fixed _FlowDirectionH;
            fixed _FlowDirectionV;
            fixed _FlowIntensity;
            
            fixed4    _SelfLuminousColor;
            fixed  _SelfLuminousSpeed;
            fixed  _SelfLuminousIntensity;
            fixed  _SelfLuminousMin;
            fixed  _SelfLuminousMax;
            
            vertShader vert(vertexInput v)
            {
                vertShader o;
                half3 worldVertex = mul(unity_ObjectToWorld, v.vertex).xyz;
                
                // pos and uv tex coord
                o.pos = UnityObjectToClipPos(v.vertex);
                o.uv1 = v.texcoord;
                
                // frag lighting
                o.nrm = normalize(mul(half4(v.normal, 0.0), unity_WorldToObject).xyz);
                o.tng = normalize(mul(unity_ObjectToWorld, half4(v.tangent.xyz, 0.0)).xyz);
                o.bin = normalize(cross(o.nrm, o.tng) * v.tangent.w);
                o.cam = normalize(WorldSpaceViewDir(v.vertex));
                o.ref = normalize(worldVertex - _WorldSpaceCameraPos);
                
                return o;
            }
            
            fixed4 frag(vertShader i): SV_Target
            {
                // textures
                fixed4 mainColor = tex2D(_MainTex, i.uv1);
                fixed3 outcolor = mainColor.xyz;
                fixed3 specchannels = tex2D(_SpecTex, i.uv1);
                fixed3 bumpmap = tex2D(_NormTex, i.uv1);
                fixed3 channels = tex2D(_ChanTex, i.uv1);
                
                // normals
                fixed3 normRG = fixed3(bumpmap.rg, 1) - fixed3(0.5, 0.5, 0.5);
                fixed3x3 matrixDIR = half3x3(i.tng, i.bin, i.nrm);
                fixed3 normDIR = normalize(mul(normRG, matrixDIR));
                
                // shadows
                fixed shdlight = dot(_WorldSpaceLightPos0, normDIR) * specchannels.b;
                shdlight = smoothstep(0.333, 0.333 + 0.666 * bumpmap.b, shdlight);
                
                // spec, rim
                fixed dotprod = max(0, dot(i.cam, normDIR));
                fixed spclight = pow(dotprod, 30) * specchannels.r;
                fixed rimlight = pow(1 - dotprod, 2) * specchannels.b * 0.5;
                fixed3 additive = _Gbl_Spc * spclight + _Gbl_Rim * rimlight;
                
                // reflection
                fixed3 reflDIR = reflect(i.ref, normDIR);
                fixed3 reflight = texCUBE(_CubeMap, reflDIR);
                reflight *= 0.8 + outcolor;
                
                // composite
                outcolor = lerp(outcolor, reflight, specchannels.g);
                outcolor *= 0.3 + _Gbl_Amb + _Gbl_Lgt * shdlight;
                outcolor *= 0.6 + additive;
                
                outcolor.rgb *= 1.2;
                fixed timeadd = _Time.y * 5 * _FlowSpeed;
                
                fixed uvshiftH = (timeadd - floor(timeadd)) * _FlowDirectionH;
                fixed uvshiftV = (timeadd - floor(timeadd)) * _FlowDirectionV;
                
                fixed channelsB = tex2D(_ChanTex, i.uv1 + fixed2(uvshiftH, uvshiftV)).b;
                outcolor.rgb += _FlowColor * channels.r * _FlowIntensity * channelsB;
                
                fixed delta = _SelfLuminousMax - _SelfLuminousMin;
                outcolor.rgb += _SelfLuminousColor * channels.g * ((delta * 0.5 * sin(_Time.y * 10 * _SelfLuminousSpeed)) + (2 - _SelfLuminousMin) * 0.5) * _SelfLuminousIntensity;
                
                return fixed4(outcolor.rgb, mainColor.a);
            }
            
            ENDCG
            
        }
    }
    FallBack "Diffuse"
}