saliacoel commited on
Commit
9fc9ab1
·
verified ·
1 Parent(s): 9ab04f6

Upload toon_cutoff16.shader

Browse files
Files changed (1) hide show
  1. toon_cutoff16.shader +216 -0
toon_cutoff16.shader ADDED
@@ -0,0 +1,216 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ Shader "Toon/Cutoff"
2
+ {
3
+ Properties
4
+ {
5
+ _Color("Color(RGBA)", Color) = (1,1,1,1)
6
+ _MainTex("Texture", 2D) = "white" {}
7
+ _Shininess ("Shininess(0.0:)", Float) = 1.0
8
+
9
+ _ShadowThreshold ("Shadow Threshold(0.0:1.0)", Float) = 0.5
10
+ _ShadowColor ("Shadow Color(RGBA)", Color) = (0,0,0,0.5)
11
+ _ShadowSharpness ("Shadow Sharpness(0.0:)", Float) = 100
12
+ _Cutoff ("Alpha cutoff", Range(0,1)) = 0.9
13
+
14
+ }
15
+
16
+ SubShader
17
+ {
18
+ // Settings
19
+ Tags {"Queue" = "Transparent" "IgnoreProjector"="False" "RenderType" = "TransparentCutout"}
20
+
21
+
22
+
23
+ // Surface Shader Pass ( Front )
24
+ Cull Back
25
+ ZWrite On
26
+ AlphaTest Greater 0.9
27
+ //AlphaTest Equal 1
28
+ Blend SrcAlpha OneMinusSrcAlpha
29
+ CGPROGRAM
30
+ #pragma surface surf Toon alphatest:_Cutoff vertex:vert
31
+ // Toon Surface Shader for Unity
32
+ // File : ToonSurface.cginc
33
+ // Title : Toon Surface Shader with Alpha
34
+ // Language : Cg Language
35
+ // Include : ToonSurface.cginc
36
+ /*
37
+ How To Use :
38
+
39
+ CGPROGRAM
40
+ #pragma surface surf Toon
41
+ #include "ToonSurface.cginc"
42
+ ENDCG
43
+ */
44
+
45
+ float4 _Color;
46
+ sampler2D _MainTex;
47
+ float _ShadowThreshold;
48
+ float4 _ShadowColor;
49
+ float _ShadowSharpness;
50
+ float _Shininess;
51
+
52
+
53
+ struct ToonSurfaceOutput
54
+ {
55
+ half3 Albedo;
56
+ half3 Normal;
57
+ half3 Emission;
58
+ half3 Gloss;
59
+ half Specular;
60
+ half Alpha;
61
+ half4 Color;
62
+ };
63
+
64
+ inline half4 LightingToon (ToonSurfaceOutput s, half3 lightDir, half3 viewDir, half atten)
65
+ {
66
+ //Lighting paramater
67
+ float4 lightColor = _LightColor0 * atten;
68
+ float lightStrength = dot(lightDir, s.Normal) * 0.5 + 0.5;
69
+
70
+ //ToonMapping
71
+ half shadowRate = abs( max( -1, ( min( lightStrength, _ShadowThreshold ) -_ShadowThreshold)*_ShadowSharpness ) )*_ShadowColor.a;
72
+ float4 toon = float4(1,1,1,1) * (1-shadowRate) + _ShadowColor *shadowRate;
73
+
74
+ //Output
75
+ //float4 color = saturate( _Color * (lightColor*2) ) * s.Color;
76
+ float4 color = _Color * (lightColor) * s.Color * (atten*2) * _Shininess;
77
+
78
+ color *= toon;
79
+ color.a = s.Alpha;
80
+ return color;
81
+ }
82
+
83
+ struct Input
84
+ {
85
+ float2 uv_MainTex;
86
+ };
87
+
88
+
89
+ void vert (inout appdata_full v, out Input o) {
90
+ UNITY_INITIALIZE_OUTPUT(Input,o);
91
+ }
92
+
93
+ void surf (Input IN, inout ToonSurfaceOutput o)
94
+ {
95
+
96
+ // Defaults
97
+ o.Albedo = 0.0;
98
+ o.Emission = 0.0;
99
+ o.Gloss = 0.0;
100
+ o.Specular = 0.0;
101
+
102
+ half4 c = tex2D(_MainTex, IN.uv_MainTex) * _Color;
103
+ //o.Albedo = c;
104
+ o.Color = c;
105
+ o.Alpha = c.a;
106
+ }
107
+
108
+ ENDCG
109
+
110
+ // // Outline Pass
111
+ // Pass
112
+ // {
113
+ // Cull Off
114
+ // ZWrite On
115
+ // Lighting Off
116
+ // CGPROGRAM
117
+ // #pragma vertex vert
118
+ // #pragma fragment frag
119
+ // #include "UnityCG.cginc"
120
+ // #include "ToonOutlineVertFrag.cginc"
121
+ // ENDCG
122
+ // }
123
+
124
+
125
+ // Surface Shader Pass ( Back )
126
+ Cull Front
127
+ ZWrite On
128
+ //AlphaTest Equal 1
129
+ AlphaTest Greater 0.9
130
+ Blend SrcAlpha OneMinusSrcAlpha
131
+ CGPROGRAM
132
+ #pragma surface surf Toon alphatest:_Cutoff vertex:vert
133
+ // Toon Surface Shader for Unity
134
+ // File : ToonSurface.cginc
135
+ // Title : Toon Surface Shader with Alpha
136
+ // Language : Cg Language
137
+ // Include : ToonSurface.cginc
138
+ /*
139
+ How To Use :
140
+
141
+ CGPROGRAM
142
+ #pragma surface surf Toon
143
+ #include "ToonSurface.cginc"
144
+ ENDCG
145
+ */
146
+
147
+ float4 _Color;
148
+ sampler2D _MainTex;
149
+ float _ShadowThreshold;
150
+ float4 _ShadowColor;
151
+ float _ShadowSharpness;
152
+ float _Shininess;
153
+
154
+
155
+ struct ToonSurfaceOutput
156
+ {
157
+ half3 Albedo;
158
+ half3 Normal;
159
+ half3 Emission;
160
+ half3 Gloss;
161
+ half Specular;
162
+ half Alpha;
163
+ half4 Color;
164
+ };
165
+
166
+ inline half4 LightingToon (ToonSurfaceOutput s, half3 lightDir, half3 viewDir, half atten)
167
+ {
168
+ //Lighting paramater
169
+ float4 lightColor = _LightColor0 * atten;
170
+ float lightStrength = dot(lightDir, s.Normal) * 0.5 + 0.5;
171
+
172
+ //ToonMapping
173
+ half shadowRate = abs( max( -1, ( min( lightStrength, _ShadowThreshold ) -_ShadowThreshold)*_ShadowSharpness ) )*_ShadowColor.a;
174
+ float4 toon = float4(1,1,1,1) * (1-shadowRate) + _ShadowColor *shadowRate;
175
+
176
+ //Output
177
+ //float4 color = saturate( _Color * (lightColor*2) ) * s.Color;
178
+ float4 color = _Color * (lightColor) * s.Color * (atten*2) * _Shininess;
179
+
180
+ color *= toon;
181
+ color.a = s.Alpha;
182
+ return color;
183
+ }
184
+
185
+ struct Input
186
+ {
187
+ float2 uv_MainTex;
188
+ };
189
+
190
+
191
+ void vert (inout appdata_full v, out Input o) {
192
+ UNITY_INITIALIZE_OUTPUT(Input,o);
193
+ }
194
+
195
+ void surf (Input IN, inout ToonSurfaceOutput o)
196
+ {
197
+
198
+ // Defaults
199
+ o.Albedo = 0.0;
200
+ o.Emission = 0.0;
201
+ o.Gloss = 0.0;
202
+ o.Specular = 0.0;
203
+
204
+ half4 c = tex2D(_MainTex, IN.uv_MainTex) * _Color;
205
+ //o.Albedo = c;
206
+ o.Color = c;
207
+ o.Alpha = c.a;
208
+ }
209
+
210
+ ENDCG
211
+
212
+ }
213
+
214
+ // Other Environment
215
+ Fallback "Diffuse"
216
+ }