Search Unity

LWRP/URP Shader No lighting/shadows

Discussion in 'Shaders' started by dyburke, Jan 4, 2020.

  1. dyburke

    dyburke

    Joined:
    Nov 11, 2012
    Posts:
    15
    Hi, I'm trying to shade my geometry shader and I'm having issues getting the shadows to display correctly. It seems like they're in the wrong space, but I used
    TransformObjectToWorld
    so I think it should be correct...

    This is my frag function:
    Code (CSharp):
    1.  
    2.             /* ==============================================================
    3.                 FRAG
    4.             ===============================================================*/
    5.          
    6.             float4 Frag (g2f input) : SV_Target
    7.             {
    8.                 UNITY_SETUP_INSTANCE_ID(input);
    9.                 float4 col;
    10.              
    11.                 float4 shadowCoord = TransformWorldToShadowCoord(input.positionWS);
    12.                 Light mainLight = GetMainLight(shadowCoord);
    13.              
    14.                 float shadowValue = SampleScreenSpaceShadowmap(shadowCoord);
    15.                 float4 lightValue = float4(mainLight.color, 1.0);
    16.              
    17.                 col = lerp(
    18.                           UNITY_ACCESS_INSTANCED_PROP(UnityPerMaterial, _BottomColor),
    19.                           UNITY_ACCESS_INSTANCED_PROP(UnityPerMaterial, _TopColor),
    20.                           input.uv.y
    21.                           );
    22.              
    23.                 return col * lightValue * shadowValue;
    24.             }
    And this is the result:


    Anyone have any ideas?