Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Question Unlit Shader Graph with shadows

Discussion in 'Shader Graph' started by abitofjohn, Oct 20, 2019.

  1. abitofjohn

    abitofjohn

    Joined:
    Nov 6, 2012
    Posts:
    27
    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!
     
  2. Olmi

    Olmi

    Joined:
    Nov 29, 2012
    Posts:
    1,553
  3. abitofjohn

    abitofjohn

    Joined:
    Nov 6, 2012
    Posts:
    27
  4. Olmi

    Olmi

    Joined:
    Nov 29, 2012
    Posts:
    1,553
    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? :)
     
    Last edited: Oct 20, 2019
  5. abitofjohn

    abitofjohn

    Joined:
    Nov 6, 2012
    Posts:
    27
    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.
     
    Last edited: Oct 20, 2019
  6. YannigJuicy

    YannigJuicy

    Joined:
    May 20, 2019
    Posts:
    2
    Hi, i found this, explain and code of shader :)
    https://styly.cc/tips/unlitcastshadow-go-shader/

    or juste code :


    Code (CSharp):
    1. Shader "Unlit/UnlitCastShadow"
    2. {
    3.     Properties
    4.     {
    5.         _MainTex ("Texture", 2D) = "white" {}
    6.     }
    7.    
    8.     SubShader
    9.     {
    10.         Tags {"RenderType"="Opaque" }
    11.         LOD 100
    12.        
    13.         // Pass to render object without lighting and shading
    14.         Pass
    15.         {
    16.             CGPROGRAM
    17.             #pragma vertex vert
    18.             #pragma fragment frag
    19.             // make fog work
    20.             #pragma multi_compile_fog
    21.            
    22.             #include "UnityCG.cginc"
    23.  
    24.             struct appdata
    25.             {
    26.                 float4 vertex : POSITION;
    27.                 float2 uv : TEXCOORD0;
    28.             };
    29.  
    30.             struct v2f
    31.             {
    32.                 float2 uv : TEXCOORD0;
    33.                 UNITY_FOG_COORDS(1)
    34.                 float4 vertex : SV_POSITION;
    35.             };
    36.  
    37.             sampler2D _MainTex;
    38.             float4 _MainTex_ST;
    39.            
    40.             v2f vert (appdata v)
    41.             {
    42.                 v2f o;
    43.                 o.vertex = UnityObjectToClipPos(v.vertex);
    44.                 o.uv = TRANSFORM_TEX(v.uv, _MainTex);
    45.                 UNITY_TRANSFER_FOG(o,o.vertex);
    46.                 return o;
    47.             }
    48.            
    49.             fixed4 frag (v2f i) : SV_Target
    50.             {
    51.                 // sample the texture
    52.                 fixed4 col = tex2D(_MainTex, i.uv);
    53.                 // apply fog
    54.                 UNITY_APPLY_FOG(i.fogCoord, col);
    55.                 return col;
    56.             }
    57.             ENDCG
    58.         }
    59.        
    60.         // Pass to render object as a shadow caster
    61.         Pass
    62.         {
    63.             Name "CastShadow"
    64.             Tags { "LightMode" = "ShadowCaster" }
    65.    
    66.             CGPROGRAM
    67.             #pragma vertex vert
    68.             #pragma fragment frag
    69.             #pragma multi_compile_shadowcaster
    70.             #include "UnityCG.cginc"
    71.    
    72.             struct v2f
    73.             {
    74.                 V2F_SHADOW_CASTER;
    75.             };
    76.    
    77.             v2f vert( appdata_base v )
    78.             {
    79.                 v2f o;
    80.                 TRANSFER_SHADOW_CASTER(o)
    81.                 return o;
    82.             }
    83.    
    84.             float4 frag( v2f i ) : COLOR
    85.             {
    86.                 SHADOW_CASTER_FRAGMENT(i)
    87.             }
    88.             ENDCG
    89.         }
    90.     }
    91. }
    92.  
     
  7. alexanderameye

    alexanderameye

    Joined:
    Nov 27, 2013
    Posts:
    1,383
    CityWizardGames likes this.
  8. bachirk

    bachirk

    Joined:
    Mar 9, 2014
    Posts:
    16
    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?
     
  9. LT23Live

    LT23Live

    Joined:
    Jul 8, 2014
    Posts:
    85
    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.
     
    Last edited: Mar 6, 2024