- Home /
Why doesn't clip shader work with shadows?
Hello,
I have a simple clip shader that does clipping with "clip" in a surface shader. It clips pixels that are outside of a cylinder. But it causes shadows artifacts. When an object is being clipped, its shadow starts rendering on its back, and it also occludes the shadowing from other objects that are casting shadows. Can you help me understand what the issue is?
Here is the shader:
Shader "Custom/ClipCylinderDiffuse"
{
Properties
{
_color("Color", Color) = (1,1,1)
_radius("size",Range(1,20)) = 6
_center("center", Vector) = (1,1,1)
}
SubShader
{
Tags{ "RenderType" = "Opaque" }
CGPROGRAM
#pragma surface surf Lambert
struct Input
{
float2 uv_MainTex;
float2 uv_BumpMap;
float3 worldPos;
};
sampler2D _MainTex;
sampler2D _BumpMap;
float _radius;
float3 _center;
float3 _color;
void surf(Input IN, inout SurfaceOutput o)
{
clip(_radius*_radius - ((_center.x - IN.worldPos.x)*(_center.x - IN.worldPos.x) + (_center.z - IN.worldPos.z)*(_center.z - IN.worldPos.z)));
o.Albedo = _color.rgb;
o.Alpha = 0.005;
}
ENDCG
}
Fallback "Diffuse"
}
Thanks, John
clipshader1.png
(132.4 kB)
clipshader2.png
(131.8 kB)
Comment