Search Unity

Question Shadow quality issues with custom shader

Discussion in 'Editor & General Support' started by Hanesto, Mar 19, 2023.

  1. Hanesto

    Hanesto

    Joined:
    Mar 30, 2016
    Posts:
    12
    Hey guys,

    I am creating a game with a custom shader graph cell shader, that also uses keywords to receive shadows. My problem is that those shadows are really low resolution, even though my shadow resolution is at 4096 and I am using cascades.
    Also, soft shadows don't seem to work at all.

    Screenshot 2023-03-19 114951.png
    Screenshot 2023-03-19 115136.png

    I know that soft shadows are disabled in the screenshot, it simply did not change anything when activated.
    I am using URP in Unity 2021.3.21f1.
    I am also using the keywords:
    MAIN_LIGHT_CALCULATE_SHADOWS,
    _MAIN_LIGHT_SHADOWS_CASCADE and
    SHADOWS_SOFT
    in my shader to get shadows.
    I am not really doing anything else to those shadows in the shader.

    Does anybody know what could cause this or how to fix it?
    Thanks,
    Hannes
     

    Attached Files:

  2. DevDunk

    DevDunk

    Joined:
    Feb 13, 2020
    Posts:
    5,063
    Send the shader
     
  3. Hanesto

    Hanesto

    Joined:
    Mar 30, 2016
    Posts:
    12
    I am using pretty much unitys official method for custom lighting:
    https://blog.unity.com/technology/custom-lighting-in-shader-graph-expanding-your-graphs-in-2019

    Code (CSharp):
    1. void MainLight_float(float3 WorldPos, out float3 Direction, out float3 Color,
    2.     out float DistanceAtten, out float ShadowAtten)
    3. {
    4. #ifdef SHADERGRAPH_PREVIEW
    5.     Direction = normalize(float3(0.5f, 0.5f, 0.25f));
    6.     Color = float3(1.0f, 1.0f, 1.0f);
    7.     DistanceAtten = 1.0f;
    8.     ShadowAtten = 1.0f;
    9. #else
    10.     #if SHADOWS_SCREEN
    11.         half4 clipPos = TransformWorldToHClip(WorldPos);
    12.         half4 shadowCoord = ComputeScreenPos(clipPos);
    13.     #else
    14.         float4 shadowCoord = TransformWorldToShadowCoord(WorldPos);
    15.     #endif
    16.  
    17.     Light mainLight = GetMainLight(shadowCoord);
    18.     Direction = mainLight.direction;
    19.     Color = mainLight.color;
    20.     DistanceAtten = mainLight.distanceAttenuation;
    21.     ShadowAtten = mainLight.shadowAttenuation;
    22. #endif
    23. }
    24.  
    25. void MainLight_half(half3 WorldPos, out half3 Direction, out half3 Color,
    26.     out half DistanceAtten, out half ShadowAtten)
    27. {
    28. #ifdef SHADERGRAPH_PREVIEW
    29.     Direction = normalize(half3(0.5f, 0.5f, 0.25f));
    30.     Color = half3(1.0f, 1.0f, 1.0f);
    31.     DistanceAtten = 1.0f;
    32.     ShadowAtten = 1.0f;
    33. #else
    34.     half4 shadowCoord = TransformWorldToShadowCoord(WorldPos);
    35.     Light mainLight = GetMainLight(shadowCoord);
    36.     Direction = mainLight.direction;
    37.     Color = mainLight.color;
    38.     DistanceAtten = mainLight.distanceAttenuation;
    39.     ShadowAtten = mainLight.shadowAttenuation;
    40. #endif
    41. }
     
    Last edited: Mar 19, 2023
  4. DevDunk

    DevDunk

    Joined:
    Feb 13, 2020
    Posts:
    5,063
    Can you also send the shader graph you mention?
     
  5. Hanesto

    Hanesto

    Joined:
    Mar 30, 2016
    Posts:
    12
    Its pretty much this, so not that complex at all:

    Screenshot 2023-03-19 140214.png

    The Attenuation in the GetMainLight subgraph is the only calculation in there and its just DistanceAttenunation * ShadowAttenuation