-
Notifications
You must be signed in to change notification settings - Fork 0
/
CasToonOpaque.shader
297 lines (250 loc) · 9.3 KB
/
CasToonOpaque.shader
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
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
// Upgrade NOTE: replaced 'mul(UNITY_MATRIX_MVP,*)' with 'UnityObjectToClipPos(*)'
Shader".Cascadian/CasToonOpaque"
{
Properties
{
_MainTex ("Color Map", 2D) = "white" {}
_MainColor ("Main Color", Color) = (1,1,1,1)
[Normal] [NoScale] _NormalMap("Normal Map", 2D) = "bump" {}
_NormalStrength("Normal Strength", Range(0,2)) = 1
[Normal] _DetailNormalMap("Detail Normal Map", 2D) = "bump" {}
_DetailNormalStrength("Detail Normal Strength", Range(0,2)) = 1
_ShadowRamp("Shadow Ramp", 2D) = "white" {}
_ShadowColor("Shadow Color", Color) = (0.5,0.5,0.5,1)
_ShadowOffset("Shadow Offset", Range(-1,1)) = 0
_ShadMaskMap("Shadow Mask", 2D) = "white" {}
_ShadowMaskStrength("Shadow Mask Strength", Range(0,1)) = 0
_RimColor ("Rim Color", Color) = (1,1,1,1)
_RimSize ("Rim Size", Float) = 1.5
_RimIntensity("Rim Intensity", Float) = 1
_RimMaskMap("Rimlight Mask", 2D) = "white" {}
_MatCap("Matcap Map", 2D) = "white" {}
_MatMultiply("Mat Multiply", Range(0,1)) = 1
_MatAdd("Mat Add", Range(0,1)) = 0
_MatMaskMap("Matcap Mask", 2D) = "white" {}
_Metallic("Metallic", Range(0,1)) = 1
_RefSmoothness("Reflection Smoothness", Range(0,1)) = 0.5
_invertSmooth("invert smoothness", Float) = 0
_metallicSpecIntensity("Metallic Specular Size", Range(0,1)) = 1
_metallicSpecSize("Metallic Specular Intensity", Range(0,1)) = 1
_SmoothnessMaskMap("Smoothness Mask", 2D) = "white" {}
_MetalMaskMap("Metal Mask", 2D) = "white" {}
_customcubemap("Use Custom Cubemap", Float) = 0
_MultiplyReflection("Multiply Reflection", Range(0,1)) = 0
_AddReflection("Add Reflection", Range(0,1)) = 0
_CustomReflection("Custom Cubemap", CUBE) = "white" {}
_fallbackColor("Fallback Color", Color) = (1,1,1)
_SpeccColor("Specular Color", Color) = (1,1,1,1)
_SpecSmoothness("Smoothness", Range(0,5)) = 0.5
_SpeccSize("Size", Range(0,1)) = 0.5
_SpecMaskMap("Specular Mask", 2D) = "white" {}
_OutlineColor("Outline Color", Color) = (0,0,0,1)
_outlineSize("Outline Size", float) = 1
_OutlineMask("Outline Mask", 2D) = "white" {}
_EmisTex("Emission Map", 2D) = "white" {}
_EmisColor("Emission Color", Color) = (1,1,1,1)
_EmisPower("Emission Power", Float) = 1
// Emission Scroll
_EmisScrollSpeed("Emission Scroll Frequency", Float) = 1
_EmisScrollFrequency("Emission Scroll Frequency", Float) = 5
_EmisScrollMinBrightness("Emission Scroll Min Brightness", Float) = 0
_EmisScrollMaxBrightness("Emission Scroll Max Brightness", Float) = 1
_EmisScrollSpace("Emission Scroll Transform Space", Float) = 0
// Audio Link
_AudioLink ("AudioLink Texture", 2D) = "black" {}
_Bass ("Bass", Range(0,1)) = 0
_LowMid ("LowMid", Range(0,1)) = 0
_HighMid ("HighMid", Range(0,1)) = 0
_Treble ("Treble", Range(0,1)) = 0
_minAudioBrightness ("Minimum Brightness", Range(0,1)) = 0.5
_audioStrength ("Audio Strength", Range(0,5)) = 1
_UnlitIntensity("Unlit Intensity", Range(0,1)) = 0.1
_NormFlatten("Normal Flatten", Range(0,1)) = 0.5
_BakedColorContribution("Baked Color Contribution", Range(0,1)) = 1.0
// Utilities
_HideMeshMap("Hide Mesh Map", 2D) = "white" {}
[Enum(OFF,0,FRONT,1,BACK,2)] _CullingMode("Culling Mode", int) = 2
[IntRange] _StencilRef ("Stencil Reference Value", Range(0, 255)) = 0
[Enum(UnityEngine.Rendering.CompareFunction)] _StencilFunction("Stencil Compare Function", Float) = 8
[Enum(UnityEngine.Rendering.StencilOp)] _StencilOp("Stencil Operation", Float) = 0
// Toggle Groups
_rimtog("toggle rimlight", Float) = 0
_mattog("toggle matcap", Float) = 0
_spectog("toggle specular", Float) = 0
_metaltog("toggle metal", Float) = 0
_outlinetog("toggle outline", Float) = 0
_emistog("toggle emissison", Float) = 0
_emistogscroll("toggle emissison", Float) = 0
_audioLinktog("toggle AudioLink", Float) = 0
}
SubShader
{
Stencil
{
Ref [_StencilRef]
Comp [_StencilFunction]
Pass [_StencilOp]
Fail [_StencilOp]
ZFail [_StencilOp]
}
Pass // Main
{
Tags { "Queue"="Geometry" "RenderType"="Opaque"
"LightMode" = "ForwardBase" "VRCFallback"="Toon"}
LOD 100
Cull [_CullingMode]
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#pragma multi_compile_particles
#pragma multi_compile_fog
#pragma target 3.0
#pragma multi_compile _ LIGHTMAP_ON
#define _IS_TRANSPARENT 0
#include "CasToon.cginc"
ENDCG
}
Pass //Outline
{
Tags { "Queue"="Geometry" "RenderType"="Opaque"
"LightMode" = "ForwardBase"}
LOD 100
Cull FRONT
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#pragma multi_compile_particles
#pragma multi_compile_fog
#pragma target 3.0
#pragma multi_compile _ LIGHTMAP_ON
#include "UnityCG.cginc"
#include "Lighting.cginc"
struct appdata {
float4 vertex : POSITION;
float3 normal : NORMAL;
float4 uv : TEXCOORD0;
UNITY_VERTEX_INPUT_INSTANCE_ID
};
struct v2f {
float4 pos : SV_POSITION;
float3 normal : TEXCOORD0;
};
sampler2D _OutlineMask;
float4 _OutlineColor;
float _outlineSize;
float _outlinetog;
v2f vert(appdata v)
{
v2f o;
if (_outlinetog == 0)
{
o.pos = 0.0/0.0;
}
else
{
o.pos = UnityObjectToClipPos(float4(v.vertex.xyz + v.normal * 0.01 * _outlineSize * tex2Dlod(_OutlineMask, v.uv),1));
}
o.normal = v.normal;
return o;
}
float4 frag(v2f i) : SV_Target
{
float3 bakedLight = saturate(ShadeSHPerPixel(i.normal, _LightColor0, i.pos ));
bakedLight = ((bakedLight.x + bakedLight.y + bakedLight.z) / 3).xxx;
float3 color = min(_OutlineColor.xyz, _OutlineColor.xyz * bakedLight);
return float4(color,1);
}
ENDCG
}
Pass // Cast Shadows
{
Tags {"LightMode"="ShadowCaster"}
Cull [_CullingMode]
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#pragma multi_compile_shadowcaster
#pragma multi_compile_instancing
#include "UnityCG.cginc"
struct v2f {
float4 pos : SV_POSITION;
};
sampler2D _HideMeshMap;
v2f vert(appdata_base v)
{
v2f o;
UNITY_SETUP_INSTANCE_ID(v);
o.pos = v.vertex;
if (tex2Dlod(_HideMeshMap, v.texcoord).x < 0.5)
{
o.pos = 0.0 / 0.0;
return o;
}
o.pos = UnityClipSpaceShadowCasterPos(v.vertex, v.normal);
o.pos = UnityApplyLinearShadowBias(o.pos);
return o;
}
float4 frag(v2f i) : SV_Target
{
return 0;
}
ENDCG
}
Pass // Realtime Lights Contribution
{
Tags {"LightMode" = "ForwardAdd"}
// And it's additive to the base pass.
Blend One One
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#pragma multi_compile_fwdadd
#include "UnityCG.cginc"
#include "AutoLight.cginc"
#include "Lighting.cginc"
#include "UnityStandardUtils.cginc"
float4 _MainTex_ST;
struct v2f {
float4 pos : SV_POSITION;
float2 uv : TEXCOORD0;
float3 normal : TEXCOORD1;
float3 lightDir : TEXCOORD2;
LIGHTING_COORDS(3,4)
float3 tbn[3] : TEXCOORD4; //5&6
};
v2f vert (appdata_full v)
{
v2f o;
o.pos = UnityObjectToClipPos (v.vertex);
o.uv = TRANSFORM_TEX (v.texcoord, _MainTex).xy;
o.normal = v.normal.xyz;
float4 tangent = float4(UnityObjectToWorldDir(v.tangent.xyz), v.tangent.w);
float3 bitangent = cross(o.normal,tangent) * tangent.w ;
o.tbn[0] = tangent;
o.tbn[1] = bitangent;
o.tbn[2] = o.normal;
o.lightDir = ObjSpaceLightDir (v.vertex).xyz;
TRANSFER_VERTEX_TO_FRAGMENT(o);
return o;
}
sampler2D _MainTex;
sampler2D _NormalMap;
sampler2D _ShadowRamp;
float _NormalStrength;
float4 _ShadowColor;
fixed4 frag(v2f i) : COLOR
{
float4 L = normalize(_WorldSpaceLightPos0);
fixed atten = LIGHT_ATTENUATION(i);
float3 norm = UnpackScaleNormal(tex2D(_NormalMap, i.uv), _NormalStrength);
float3 worldNormal = (i.tbn[0] * norm.r + i.tbn[1] * norm.g + i.tbn[2]* norm.b);
float shade = clamp(0, 1, 0.5 * dot(worldNormal, L) + 0.5);
shade = clamp(0,1,tex2D(_ShadowRamp, shade.xx) + (1-_ShadowColor.w));
float3 color = shade * atten * 2 * _LightColor0.rgb * tex2D(_MainTex, i.uv).rgb;
return float4(color,1);
}
ENDCG
}
}
CustomEditor "CasToonGUIV2"
}