Update toon_cutoff16.shader
Browse files- toon_cutoff16.shader +373 -216
toon_cutoff16.shader
CHANGED
|
@@ -1,216 +1,373 @@
|
|
| 1 |
-
Shader "Toon/Cutoff"
|
| 2 |
-
{
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
_Cutoff ("Alpha cutoff", Range(0,1)) = 0.9
|
| 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 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
Shader "Toon/Cutoff"
|
| 2 |
+
{
|
| 3 |
+
Properties
|
| 4 |
+
{
|
| 5 |
+
[MainColor] _Color("Color(RGBA)", Color) = (1,1,1,1)
|
| 6 |
+
[MainTexture] _MainTex("Texture", 2D) = "white" {}
|
| 7 |
+
_Shininess ("Shininess(0.0:)", Float) = 1.0
|
| 8 |
+
|
| 9 |
+
_ShadowThreshold ("Shadow Threshold(0.0:1.0)", Range(0,1)) = 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 |
+
// URP
|
| 17 |
+
// ============================================================
|
| 18 |
+
SubShader
|
| 19 |
+
{
|
| 20 |
+
Tags
|
| 21 |
+
{
|
| 22 |
+
"RenderPipeline" = "UniversalPipeline"
|
| 23 |
+
"Queue" = "AlphaTest"
|
| 24 |
+
"RenderType" = "AlphaTest"
|
| 25 |
+
}
|
| 26 |
+
|
| 27 |
+
Pass
|
| 28 |
+
{
|
| 29 |
+
Name "ForwardLit"
|
| 30 |
+
Tags { "LightMode" = "UniversalForward" }
|
| 31 |
+
|
| 32 |
+
Cull Off
|
| 33 |
+
ZWrite On
|
| 34 |
+
ZTest LEqual
|
| 35 |
+
Blend One Zero
|
| 36 |
+
|
| 37 |
+
HLSLPROGRAM
|
| 38 |
+
#pragma target 2.0
|
| 39 |
+
#pragma vertex vert
|
| 40 |
+
#pragma fragment frag
|
| 41 |
+
|
| 42 |
+
#pragma multi_compile _ _MAIN_LIGHT_SHADOWS _MAIN_LIGHT_SHADOWS_CASCADE _MAIN_LIGHT_SHADOWS_SCREEN
|
| 43 |
+
#pragma multi_compile _ _ADDITIONAL_LIGHTS
|
| 44 |
+
#pragma multi_compile _ _ADDITIONAL_LIGHT_SHADOWS
|
| 45 |
+
#pragma multi_compile_fog
|
| 46 |
+
#pragma multi_compile_instancing
|
| 47 |
+
|
| 48 |
+
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
|
| 49 |
+
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Lighting.hlsl"
|
| 50 |
+
|
| 51 |
+
struct Attributes
|
| 52 |
+
{
|
| 53 |
+
float4 positionOS : POSITION;
|
| 54 |
+
float3 normalOS : NORMAL;
|
| 55 |
+
float2 uv : TEXCOORD0;
|
| 56 |
+
UNITY_VERTEX_INPUT_INSTANCE_ID
|
| 57 |
+
};
|
| 58 |
+
|
| 59 |
+
struct Varyings
|
| 60 |
+
{
|
| 61 |
+
float4 positionCS : SV_POSITION;
|
| 62 |
+
float2 uv : TEXCOORD0;
|
| 63 |
+
float3 positionWS : TEXCOORD1;
|
| 64 |
+
float3 normalWS : TEXCOORD2;
|
| 65 |
+
float4 shadowCoord : TEXCOORD3;
|
| 66 |
+
half fogFactor : TEXCOORD4;
|
| 67 |
+
UNITY_VERTEX_INPUT_INSTANCE_ID
|
| 68 |
+
UNITY_VERTEX_OUTPUT_STEREO
|
| 69 |
+
};
|
| 70 |
+
|
| 71 |
+
CBUFFER_START(UnityPerMaterial)
|
| 72 |
+
float4 _Color;
|
| 73 |
+
float4 _ShadowColor;
|
| 74 |
+
float4 _MainTex_ST;
|
| 75 |
+
float _Shininess;
|
| 76 |
+
float _ShadowThreshold;
|
| 77 |
+
float _ShadowSharpness;
|
| 78 |
+
float _Cutoff;
|
| 79 |
+
CBUFFER_END
|
| 80 |
+
|
| 81 |
+
TEXTURE2D(_MainTex);
|
| 82 |
+
SAMPLER(sampler_MainTex);
|
| 83 |
+
|
| 84 |
+
Varyings vert(Attributes IN)
|
| 85 |
+
{
|
| 86 |
+
Varyings OUT;
|
| 87 |
+
|
| 88 |
+
UNITY_SETUP_INSTANCE_ID(IN);
|
| 89 |
+
UNITY_TRANSFER_INSTANCE_ID(IN, OUT);
|
| 90 |
+
UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(OUT);
|
| 91 |
+
|
| 92 |
+
VertexPositionInputs posInputs = GetVertexPositionInputs(IN.positionOS.xyz);
|
| 93 |
+
VertexNormalInputs normalInputs = GetVertexNormalInputs(IN.normalOS);
|
| 94 |
+
|
| 95 |
+
OUT.positionCS = posInputs.positionCS;
|
| 96 |
+
OUT.positionWS = posInputs.positionWS;
|
| 97 |
+
OUT.normalWS = normalize(normalInputs.normalWS);
|
| 98 |
+
OUT.uv = TRANSFORM_TEX(IN.uv, _MainTex);
|
| 99 |
+
OUT.shadowCoord = GetShadowCoord(posInputs);
|
| 100 |
+
OUT.fogFactor = ComputeFogFactor(posInputs.positionCS.z);
|
| 101 |
+
|
| 102 |
+
return OUT;
|
| 103 |
+
}
|
| 104 |
+
|
| 105 |
+
half3 ToonLight(half3 baseColor, half3 normalWS, Light light)
|
| 106 |
+
{
|
| 107 |
+
half atten = light.distanceAttenuation * light.shadowAttenuation;
|
| 108 |
+
|
| 109 |
+
half lightStrength = dot(normalWS, normalize(light.direction)) * 0.5h + 0.5h;
|
| 110 |
+
|
| 111 |
+
half shadowRate =
|
| 112 |
+
abs(max(-1.0h,
|
| 113 |
+
(min(lightStrength, (half)_ShadowThreshold) - (half)_ShadowThreshold) *
|
| 114 |
+
(half)_ShadowSharpness)) * _ShadowColor.a;
|
| 115 |
+
|
| 116 |
+
shadowRate = saturate(shadowRate);
|
| 117 |
+
|
| 118 |
+
half3 toonTint = lerp(half3(1.0h, 1.0h, 1.0h), _ShadowColor.rgb, shadowRate);
|
| 119 |
+
|
| 120 |
+
return baseColor * light.color * toonTint * saturate(atten * 2.0h) * max((half)_Shininess, 0.0h);
|
| 121 |
+
}
|
| 122 |
+
|
| 123 |
+
half4 frag(Varyings IN) : SV_Target
|
| 124 |
+
{
|
| 125 |
+
UNITY_SETUP_INSTANCE_ID(IN);
|
| 126 |
+
|
| 127 |
+
half4 texColor = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, IN.uv) * _Color;
|
| 128 |
+
clip(texColor.a - _Cutoff);
|
| 129 |
+
|
| 130 |
+
half3 normalWS = normalize(IN.normalWS);
|
| 131 |
+
half3 color = 0;
|
| 132 |
+
|
| 133 |
+
Light mainLight = GetMainLight(IN.shadowCoord);
|
| 134 |
+
color += ToonLight(texColor.rgb, normalWS, mainLight);
|
| 135 |
+
|
| 136 |
+
#if defined(_ADDITIONAL_LIGHTS)
|
| 137 |
+
uint pixelLightCount = GetAdditionalLightsCount();
|
| 138 |
+
LIGHT_LOOP_BEGIN(pixelLightCount)
|
| 139 |
+
Light additionalLight = GetAdditionalLight(lightIndex, IN.positionWS, half4(1,1,1,1));
|
| 140 |
+
color += ToonLight(texColor.rgb, normalWS, additionalLight);
|
| 141 |
+
LIGHT_LOOP_END
|
| 142 |
+
#endif
|
| 143 |
+
|
| 144 |
+
color = MixFog(color, IN.fogFactor);
|
| 145 |
+
return half4(color, texColor.a);
|
| 146 |
+
}
|
| 147 |
+
ENDHLSL
|
| 148 |
+
}
|
| 149 |
+
|
| 150 |
+
Pass
|
| 151 |
+
{
|
| 152 |
+
Name "ShadowCaster"
|
| 153 |
+
Tags { "LightMode" = "ShadowCaster" }
|
| 154 |
+
|
| 155 |
+
ZWrite On
|
| 156 |
+
ZTest LEqual
|
| 157 |
+
ColorMask 0
|
| 158 |
+
Cull Off
|
| 159 |
+
|
| 160 |
+
HLSLPROGRAM
|
| 161 |
+
#pragma target 2.0
|
| 162 |
+
#pragma vertex ShadowPassVertex
|
| 163 |
+
#pragma fragment ShadowPassFragment
|
| 164 |
+
#pragma multi_compile_vertex _ _CASTING_PUNCTUAL_LIGHT_SHADOW
|
| 165 |
+
#pragma multi_compile_instancing
|
| 166 |
+
|
| 167 |
+
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
|
| 168 |
+
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Lighting.hlsl"
|
| 169 |
+
|
| 170 |
+
struct Attributes
|
| 171 |
+
{
|
| 172 |
+
float4 positionOS : POSITION;
|
| 173 |
+
float3 normalOS : NORMAL;
|
| 174 |
+
float2 uv : TEXCOORD0;
|
| 175 |
+
UNITY_VERTEX_INPUT_INSTANCE_ID
|
| 176 |
+
};
|
| 177 |
+
|
| 178 |
+
struct Varyings
|
| 179 |
+
{
|
| 180 |
+
float4 positionCS : SV_POSITION;
|
| 181 |
+
float2 uv : TEXCOORD0;
|
| 182 |
+
UNITY_VERTEX_INPUT_INSTANCE_ID
|
| 183 |
+
UNITY_VERTEX_OUTPUT_STEREO
|
| 184 |
+
};
|
| 185 |
+
|
| 186 |
+
CBUFFER_START(UnityPerMaterial)
|
| 187 |
+
float4 _Color;
|
| 188 |
+
float4 _ShadowColor;
|
| 189 |
+
float4 _MainTex_ST;
|
| 190 |
+
float _Shininess;
|
| 191 |
+
float _ShadowThreshold;
|
| 192 |
+
float _ShadowSharpness;
|
| 193 |
+
float _Cutoff;
|
| 194 |
+
CBUFFER_END
|
| 195 |
+
|
| 196 |
+
TEXTURE2D(_MainTex);
|
| 197 |
+
SAMPLER(sampler_MainTex);
|
| 198 |
+
|
| 199 |
+
float3 _LightDirection;
|
| 200 |
+
float3 _LightPosition;
|
| 201 |
+
|
| 202 |
+
float4 GetShadowPositionHClip(Attributes input)
|
| 203 |
+
{
|
| 204 |
+
float3 positionWS = TransformObjectToWorld(input.positionOS.xyz);
|
| 205 |
+
float3 normalWS = TransformObjectToWorldNormal(input.normalOS);
|
| 206 |
+
|
| 207 |
+
#if _CASTING_PUNCTUAL_LIGHT_SHADOW
|
| 208 |
+
float3 lightDirectionWS = normalize(_LightPosition - positionWS);
|
| 209 |
+
#else
|
| 210 |
+
float3 lightDirectionWS = _LightDirection;
|
| 211 |
+
#endif
|
| 212 |
+
|
| 213 |
+
float4 positionCS = TransformWorldToHClip(ApplyShadowBias(positionWS, normalWS, lightDirectionWS));
|
| 214 |
+
positionCS = ApplyShadowClamping(positionCS);
|
| 215 |
+
return positionCS;
|
| 216 |
+
}
|
| 217 |
+
|
| 218 |
+
Varyings ShadowPassVertex(Attributes IN)
|
| 219 |
+
{
|
| 220 |
+
Varyings OUT;
|
| 221 |
+
|
| 222 |
+
UNITY_SETUP_INSTANCE_ID(IN);
|
| 223 |
+
UNITY_TRANSFER_INSTANCE_ID(IN, OUT);
|
| 224 |
+
UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(OUT);
|
| 225 |
+
|
| 226 |
+
OUT.uv = TRANSFORM_TEX(IN.uv, _MainTex);
|
| 227 |
+
OUT.positionCS = GetShadowPositionHClip(IN);
|
| 228 |
+
return OUT;
|
| 229 |
+
}
|
| 230 |
+
|
| 231 |
+
half4 ShadowPassFragment(Varyings IN) : SV_Target
|
| 232 |
+
{
|
| 233 |
+
UNITY_SETUP_INSTANCE_ID(IN);
|
| 234 |
+
|
| 235 |
+
half alpha = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, IN.uv).a * _Color.a;
|
| 236 |
+
clip(alpha - _Cutoff);
|
| 237 |
+
|
| 238 |
+
return 0;
|
| 239 |
+
}
|
| 240 |
+
ENDHLSL
|
| 241 |
+
}
|
| 242 |
+
|
| 243 |
+
Pass
|
| 244 |
+
{
|
| 245 |
+
Name "DepthOnly"
|
| 246 |
+
Tags { "LightMode" = "DepthOnly" }
|
| 247 |
+
|
| 248 |
+
ZWrite On
|
| 249 |
+
ZTest LEqual
|
| 250 |
+
ColorMask 0
|
| 251 |
+
Cull Off
|
| 252 |
+
|
| 253 |
+
HLSLPROGRAM
|
| 254 |
+
#pragma target 2.0
|
| 255 |
+
#pragma vertex DepthOnlyVertex
|
| 256 |
+
#pragma fragment DepthOnlyFragment
|
| 257 |
+
#pragma multi_compile_instancing
|
| 258 |
+
|
| 259 |
+
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
|
| 260 |
+
|
| 261 |
+
struct Attributes
|
| 262 |
+
{
|
| 263 |
+
float4 positionOS : POSITION;
|
| 264 |
+
float2 uv : TEXCOORD0;
|
| 265 |
+
UNITY_VERTEX_INPUT_INSTANCE_ID
|
| 266 |
+
};
|
| 267 |
+
|
| 268 |
+
struct Varyings
|
| 269 |
+
{
|
| 270 |
+
float4 positionCS : SV_POSITION;
|
| 271 |
+
float2 uv : TEXCOORD0;
|
| 272 |
+
UNITY_VERTEX_INPUT_INSTANCE_ID
|
| 273 |
+
UNITY_VERTEX_OUTPUT_STEREO
|
| 274 |
+
};
|
| 275 |
+
|
| 276 |
+
CBUFFER_START(UnityPerMaterial)
|
| 277 |
+
float4 _Color;
|
| 278 |
+
float4 _ShadowColor;
|
| 279 |
+
float4 _MainTex_ST;
|
| 280 |
+
float _Shininess;
|
| 281 |
+
float _ShadowThreshold;
|
| 282 |
+
float _ShadowSharpness;
|
| 283 |
+
float _Cutoff;
|
| 284 |
+
CBUFFER_END
|
| 285 |
+
|
| 286 |
+
TEXTURE2D(_MainTex);
|
| 287 |
+
SAMPLER(sampler_MainTex);
|
| 288 |
+
|
| 289 |
+
Varyings DepthOnlyVertex(Attributes IN)
|
| 290 |
+
{
|
| 291 |
+
Varyings OUT;
|
| 292 |
+
|
| 293 |
+
UNITY_SETUP_INSTANCE_ID(IN);
|
| 294 |
+
UNITY_TRANSFER_INSTANCE_ID(IN, OUT);
|
| 295 |
+
UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(OUT);
|
| 296 |
+
|
| 297 |
+
OUT.positionCS = TransformObjectToHClip(IN.positionOS.xyz);
|
| 298 |
+
OUT.uv = TRANSFORM_TEX(IN.uv, _MainTex);
|
| 299 |
+
|
| 300 |
+
return OUT;
|
| 301 |
+
}
|
| 302 |
+
|
| 303 |
+
half4 DepthOnlyFragment(Varyings IN) : SV_Target
|
| 304 |
+
{
|
| 305 |
+
UNITY_SETUP_INSTANCE_ID(IN);
|
| 306 |
+
|
| 307 |
+
half alpha = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, IN.uv).a * _Color.a;
|
| 308 |
+
clip(alpha - _Cutoff);
|
| 309 |
+
|
| 310 |
+
return 0;
|
| 311 |
+
}
|
| 312 |
+
ENDHLSL
|
| 313 |
+
}
|
| 314 |
+
}
|
| 315 |
+
|
| 316 |
+
// ============================================================
|
| 317 |
+
// Built-in Render Pipeline fallback
|
| 318 |
+
// ============================================================
|
| 319 |
+
SubShader
|
| 320 |
+
{
|
| 321 |
+
Tags
|
| 322 |
+
{
|
| 323 |
+
"Queue" = "AlphaTest"
|
| 324 |
+
"RenderType" = "TransparentCutout"
|
| 325 |
+
}
|
| 326 |
+
|
| 327 |
+
Cull Off
|
| 328 |
+
ZWrite On
|
| 329 |
+
|
| 330 |
+
CGPROGRAM
|
| 331 |
+
#pragma surface surf Toon alphatest:_Cutoff addshadow fullforwardshadows
|
| 332 |
+
|
| 333 |
+
sampler2D _MainTex;
|
| 334 |
+
fixed4 _Color;
|
| 335 |
+
half _Shininess;
|
| 336 |
+
half _ShadowThreshold;
|
| 337 |
+
fixed4 _ShadowColor;
|
| 338 |
+
half _ShadowSharpness;
|
| 339 |
+
half _Cutoff;
|
| 340 |
+
|
| 341 |
+
struct Input
|
| 342 |
+
{
|
| 343 |
+
float2 uv_MainTex;
|
| 344 |
+
};
|
| 345 |
+
|
| 346 |
+
inline half4 LightingToon(SurfaceOutput s, half3 lightDir, half3 viewDir, half atten)
|
| 347 |
+
{
|
| 348 |
+
half lightStrength = dot(s.Normal, lightDir) * 0.5h + 0.5h;
|
| 349 |
+
|
| 350 |
+
half shadowRate =
|
| 351 |
+
abs(max(-1.0h,
|
| 352 |
+
(min(lightStrength, _ShadowThreshold) - _ShadowThreshold) *
|
| 353 |
+
_ShadowSharpness)) * _ShadowColor.a;
|
| 354 |
+
|
| 355 |
+
shadowRate = saturate(shadowRate);
|
| 356 |
+
|
| 357 |
+
half3 toonTint = lerp(half3(1,1,1), _ShadowColor.rgb, shadowRate);
|
| 358 |
+
half3 rgb = s.Albedo * _LightColor0.rgb * toonTint * saturate(atten * 2.0h) * max(_Shininess, 0.0h);
|
| 359 |
+
|
| 360 |
+
return half4(rgb, s.Alpha);
|
| 361 |
+
}
|
| 362 |
+
|
| 363 |
+
void surf(Input IN, inout SurfaceOutput o)
|
| 364 |
+
{
|
| 365 |
+
half4 c = tex2D(_MainTex, IN.uv_MainTex) * _Color;
|
| 366 |
+
o.Albedo = c.rgb;
|
| 367 |
+
o.Alpha = c.a;
|
| 368 |
+
}
|
| 369 |
+
ENDCG
|
| 370 |
+
}
|
| 371 |
+
|
| 372 |
+
Fallback "Legacy Shaders/Transparent/Cutout/Diffuse"
|
| 373 |
+
}
|