Search Unity

  1. Looking for a job or to hire someone for a project? Check out the re-opened job forums.
    Dismiss Notice
  2. We are looking for your feedback about Templates! Tell us about your experiences by taking our survey.
    Dismiss Notice
  3. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice

Help Wanted 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,340
  3. abitofjohn

    abitofjohn

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

    Olmi

    Joined:
    Nov 29, 2012
    Posts:
    1,340
    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,300
  8. bachirk

    bachirk

    Joined:
    Mar 9, 2014
    Posts:
    15
    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?
     
unityunity