Unlit Shader Graph with shadows

Hi All

I’m attempting to create a shader in shader graph that is essentially unlit but I would like it to receive and if possible cast shadows. I’m wondering if this is possible within shader graph and how I would go about doing it if so?

Many Thanks!

Did you do any googling?

If you are using old renderpipeline (casts and receives shadows, flat shaded):

But since you posted to Shader Graph area, you specifically want to do it in shader graph?

I’m using LWRP, I was searching for Shader Graph examples. I know Shader Graph recently introduced the custom function node so maybe I can use that.

I found this for 2019.3.0b4 so maybe I’ll have to upgrade.

If you are using LWRP, you could just create an Unlit Graph? Just the same as in HDRP. I think there was one.
They do cast shadows, but don’t receive it. But if that shadow receiving is critical for you, that doesn’t work.

That link you posted is for toggling off shadows, not shading? I thought you need to remove the shading and keep the shadow casting? :slight_smile:

Yeah I’m trying to create a style of grass, I’d like to make the bottom of the blades of grass disappear into the floor. My idea was to do it with an unlit shader but ideally it could receive shadows from the player.

Hi, i found this, explain and code of shader :slight_smile:

or juste code :

Shader "Unlit/UnlitCastShadow"
{
    Properties
    {
        _MainTex ("Texture", 2D) = "white" {}
    }
   
    SubShader
    {
        Tags {"RenderType"="Opaque" }
        LOD 100
       
        // Pass to render object without lighting and shading
        Pass
        {
            CGPROGRAM
            #pragma vertex vert
            #pragma fragment frag
            // make fog work
            #pragma multi_compile_fog
           
            #include "UnityCG.cginc"

            struct appdata
            {
                float4 vertex : POSITION;
                float2 uv : TEXCOORD0;
            };

            struct v2f
            {
                float2 uv : TEXCOORD0;
                UNITY_FOG_COORDS(1)
                float4 vertex : SV_POSITION;
            };

            sampler2D _MainTex;
            float4 _MainTex_ST;
           
            v2f vert (appdata v)
            {
                v2f o;
                o.vertex = UnityObjectToClipPos(v.vertex);
                o.uv = TRANSFORM_TEX(v.uv, _MainTex);
                UNITY_TRANSFER_FOG(o,o.vertex);
                return o;
            }
           
            fixed4 frag (v2f i) : SV_Target
            {
                // sample the texture
                fixed4 col = tex2D(_MainTex, i.uv);
                // apply fog
                UNITY_APPLY_FOG(i.fogCoord, col);
                return col;
            }
            ENDCG
        }
       
        // Pass to render object as a shadow caster
        Pass
        {
            Name "CastShadow"
            Tags { "LightMode" = "ShadowCaster" }
   
            CGPROGRAM
            #pragma vertex vert
            #pragma fragment frag
            #pragma multi_compile_shadowcaster
            #include "UnityCG.cginc"
   
            struct v2f
            {
                V2F_SHADOW_CASTER;
            };
   
            v2f vert( appdata_base v )
            {
                v2f o;
                TRANSFER_SHADOW_CASTER(o)
                return o;
            }
   
            float4 frag( v2f i ) : COLOR
            {
                SHADOW_CASTER_FRAGMENT(i)
            }
            ENDCG
        }
    }
}

If you want an example of an unlit shader that receives shadows, you can download one here.

https://alexanderameye.github.io/simple-toon.html

1 Like

Hey @alexanderameye great shader. I managed to get the shadows working in an unlit shader. How can I make it so the unlit shader object can receive shadows of other objects but not of itself?

Do you still have the URP unlit shader that receives shadows?

Edit: I see your toon shader there but when copying the prospect It does not take in shadows from other objects. Just itself.

1 Like