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

Question Proper way to access shadows and light cookie in a post processing shader

Discussion in 'Shaders' started by topitsky, Mar 30, 2023.

  1. topitsky

    topitsky

    Joined:
    Jan 12, 2016
    Posts:
    95
    I've been able to have some shadow information in my outline shader via:
    Code (CSharp):
    1.  
    2.                 float4 coord = getShadowCoord_SingleCascade(finalPos);
    3.                 fixed shadow = UNITY_SAMPLE_SHADOW(_ShadowMapTexture, coord);
    4.                 shadow = lerp(_LightShadowData.r, 1.0, shadow);
    5.                 float4 shadows = (shadow < coord.zzzz) ? _LightShadowData.rrrr : 1.0f;
    Now, everything breaks if I add a pointlight etc. Is there a proper way of sampling with the macros in AutoLight.cginc? My understanding is that these require the usage of TRANSFER_SHADOW macros etc. and wouldnt work with a post processing shader?
     
  2. topitsky

    topitsky

    Joined:
    Jan 12, 2016
    Posts:
    95
    Code (CSharp):
    1.   #define DIRECTIONAL_COOKIE
    2.             #define SHADOWS_SCREEN
    3.             #define SHADOWS_SHADOWMASK
    4.             #define UNITY_NO_SCREENSPACE_SHADOWS
    5.  
    6. was able to figure out something, these must be in top of whatever shader that wants to use to autolight things.
     
  3. topitsky

    topitsky

    Joined:
    Jan 12, 2016
    Posts:
    95
    upload_2023-4-2_13-6-51.png

    The cookie + shadow appears right on the editor window, but upon build it seems to "stretch".

    upload_2023-4-2_13-7-55.png

    Any idea what could be causing this? using latest LTS 2021. The problem disappears, when I just dont use the cookie texture in the directional light. I suspect that something happens to the light textures and matrices upon post processing stage, that is only on build. This stretching only happens on post processing stage, that is, if i turn off the outlines and the grass, the cookie is properly "projected" on ground and props.

    Code (CSharp):
    1. Im using these directives
    2.             #define DIRECTIONAL_COOKIE
    3.             #define SHADOWS_SCREEN
    4.             #define SHADOWS_SHADOWMASK
    5.             #define UNITY_NO_SCREENSPACE_SHADOWS
    6.  
    7. and sampling with
    8.  
    9. UNITY_LIGHT_ATTENUATION(atten, i, finalPos);
     
    Last edited: Apr 2, 2023
  4. topitsky

    topitsky

    Joined:
    Jan 12, 2016
    Posts:
    95
    There is something weird going on. Upon build, if I build in debug mode, and turn the frame debugger on, the stretching disappears and everything works. I think I should make a bug report.