Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Resolved Incorrect Shadow Attenuation at Shadow Cascade Split Distances?

Discussion in 'Shaders' started by Furgl, Sep 22, 2023.

  1. Furgl

    Furgl

    Joined:
    Jan 6, 2022
    Posts:
    13
    I have a custom geometry shader for grass that adds 4 vertices in the Geometry pass and I calculate shadow coordinates for each vertex using the vertex's world position:
    Code (CSharp):
    1. ShadowCoords = TransformWorldToShadowCoord(positionWS);
    In the fragment shader, I get the Main Light from the ShadowCoords and use its shadow attenuation for lighting:
    Code (CSharp):
    1. Light mainLight = GetMainLight(ShadowCoords);
    2. float4 shadowAttenuation = mainLight.shadowAttenuation;
    But for some reason it seems like the edges of each shadow cascade have the wrong shadow attenuation value: https://gyazo.com/a0297f2ccd8b57288a948b1d67e6b596
    To make this easier to see, here is with the fragment shader just returning the shadowAttenuation value: https://gyazo.com/92341d33a83ca2e4331d44296d1088ea (sorry if the gif glitches out a bit!)

    I'm not very experienced with writing shaders, so does anyone have any ideas what to do to resolve this?
     
  2. Furgl

    Furgl

    Joined:
    Jan 6, 2022
    Posts:
    13
    The issue was that I was calculating ShadowCoords in the geometry shader. Calculating them in the fragment shader fixed the issue.