0
\$\begingroup\$

I'm trying to make invisible object with shadow by using it's shadow castting pass it additionaly shades back side of object itself. I mean object shades his back side and draws shadow on the background surface.(my unity version is Unity 5.6)

you can see this problem in below animated gif:

shadow caster problem

this is my shader for unity's shadow pass:

Shader "Test/ShadowCaster"
{
    SubShader
    {
    Tags{ "LightMode" = "ShadowCaster"  }
    Name "ShadowCaster"
        Pass
    {
        CGPROGRAM

#pragma vertex vert
#pragma fragment frag
#pragma multi_compile_shadowcaster
#pragma fragmentoption ARB_precision_hint_fastest

#include "UnityCG.cginc"

        struct v2f
    {
        V2F_SHADOW_CASTER;
    };

    v2f vert(appdata_base v)
    {
        v2f o;
        TRANSFER_SHADOW_CASTER_NORMALOFFSET(o)
        return o;
    }

    float4 frag(v2f i) : COLOR
    {
        SHADOW_CASTER_FRAGMENT(i)
    }
        ENDCG
    }
    }
        FallBack Off
}
\$\endgroup\$
  • 2
    \$\begingroup\$ You can do this without a special shader by setting the object's renderer mode to Shadows Only. \$\endgroup\$ – DMGregory Jan 24 '18 at 6:10
  • \$\begingroup\$ @DMGregory that's right but I had problem In my shader that it only fixed by using shadow caster in shader.in vertex and fragment shader you can't do it so I have to write it from scratch. \$\endgroup\$ – Seyed Morteza Kamali Jan 24 '18 at 11:03
1
\$\begingroup\$

I solved this problem by adding Transparent Queue tag to my shader.

Tags{ "Queue" = "Transparent" "LightMode" = "ShadowCaster" }

2018-01-24_8-08-47

Transparent - this render queue is rendered after Geometry and AlphaTest, in back-to-front order. Anything alpha-blended (i.e. shaders that don’t write to depth buffer) should go here (glass, particle effects).

https://docs.unity3d.com/Manual/SL-SubShaderTags.html

Useful link for learning shadow casters in unity.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.