Why does my toon shader not work when I build it in webgl?
I made an unlit shader with toon shading and when I build it in webgl, the textures have no shading. Why is this? I already added the shader to the "Always Included Shaders" list. Here is the code:
Shader "Unlit/Cell Highlight"
{
Properties
{
_MainTex ("Texture", 2D) = "white" {}
_Brightness ("Brightness", Range(-.5,.5)) = 0.3
_Strength ("Strength", Range(-.5,.5)) = 0.5
_Steps ("Steps", Range(0,1)) = 0.5
_Color ("Color", COLOR) = (1,1,1,1)
}
SubShader
{
Tags { "RenderType"="Opaque" }
LOD 100
Pass
{
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#pragma multi_compile_fwdbase
#include "UnityCG.cginc"
#include "Lighting.cginc"
#include "AutoLight.cginc"
struct appdata
{
float4 vertex : POSITION;
float2 uv : TEXCOORD0;
float3 normal : NORMAL;
};
struct v2f
{
float2 uv : TEXCOORD0;
float4 vertex : SV_POSITION;
half3 worldNormal: NORMAL;
SHADOW_COORDS(2)
};
sampler2D _MainTex;
float4 _MainTex_ST;
float _Brightness;
float _Strength;
float _Steps;
float4 _Color;
float Toon(float3 normal , float3 lightDir) {
float NdotL = max(0.0, dot(normalize(normal), normalize(lightDir)));
return floor(NdotL / _Steps);
}
v2f vert (appdata v)
{
v2f o;
o.vertex = UnityObjectToClipPos(v.vertex);
o.uv = TRANSFORM_TEX(v.uv, _MainTex);
o.worldNormal = UnityObjectToWorldNormal(v.normal);
//TRANSFER_SHADOW(o)
return o;
}
fixed4 frag (v2f i) : SV_Target
{
float3 normal = normalize(i.worldNormal);
//float3 viewDir = normalize(i.viewDir);
float NdotL = dot(_WorldSpaceLightPos0, normal);
float shadow = SHADOW_ATTENUATION(i);
float lightIntensity = smoothstep(0, 0.01, NdotL * shadow);
// sample the texture
fixed4 col = tex2D(_MainTex, i.uv);
col += Toon(i.worldNormal, _WorldSpaceLightPos0.xyz) * shadow * _Strength * _Color + _Brightness;
// In the fragment shader, above the existing lightIntensity declaration.
return col;
}
ENDCG
}
UsePass "Legacy Shaders/VertexLit/SHADOWCASTER"
}
}
Thanks a ton!!
Comment