- Home /
Why does addshadow cause shadows to be projected on top of the caster if the caster is stenciled?
If you have #pragma addshadow defined on a stenciled object, its shadow will be projected on top of it instead of behind it. Other depth effects are broken too. Removing addshadow and having just fullforwardshadows leads to the expected behaviour.
Sample shader
Shader "IslandTest"
{
Properties
{
_Color0("Color 0", Color) = (0.2270826,0.764151,0.2394226,0)
[HideInInspector] __dirty( "", Int ) = 1
}
SubShader
{
Tags{ "RenderType" = "Opaque" "Queue" = "Geometry+0" "IgnoreProjector" = "True" }
Cull Back
Stencil
{
Ref 1
Comp Equal
}
CGPROGRAM
#pragma target 3.0
#pragma surface surf Standard keepalpha addshadow fullforwardshadows exclude_path:deferred nodynlightmap noforwardadd
struct Input
{
half filler;
};
uniform half4 _Color0;
void surf( Input i , inout SurfaceOutputStandard o )
{
o.Albedo = _Color0.rgb;
o.Alpha = 1;
}
ENDCG
}
Fallback "Diffuse"
CustomEditor "ASEMaterialInspector"
}
Unity: 2018.4.11
Update: The shader was generated with Amplify Shader Editor
addshadow.png
(38.6 kB)
Comment
Best Answer
Answer by sbsmith · Jan 03, 2020 at 09:25 PM
A discussion and answer can be found here https://forum.unity.com/threads/why-does-addshadow-cause-shadows-to-be-projected-on-top-of-the-caster-if-the-caster-is-stenciled.800673/
Your answer
![](https://koobas.hobune.stream/wayback/20220612220555im_/https://answers.unity.com/themes/thub/images/avi.jpg)