Search Unity

SHADOW_ATTENUATION behaviour change in 5.6?

Discussion in 'Shaders' started by bluescrn, May 15, 2017.

  1. bluescrn

    bluescrn

    Joined:
    Feb 25, 2013
    Posts:
    642
    Hi,

    I've been using SHADOW_ATTENUATION in custom shaders to sample directional light shadows (for iOS/Android, so forward rendering, trying to do everything in a single pass)

    Prior to 5.6, I think, the SHADOW_ATTENUATION macro seemed to be handling the shadow depth-fade?

    But in 5.6, this isn't happening, so my shadows are a bit of a mess - objects popping in/out, and everything in shadow beyond the limits of the shadow frustum.

    Is there an easy way to get the depth-fade working again? - preferably without requiring a per-pixel world position? (as seems to be expected by UnityComputeShadowFadeDistance()?)

    (Looking back at a 5.4 project, back then directional shadows used the CollectShadows pass and screen-space shadowmap - at least in the editor - and that was 'pre-faded'. But it's not doing this any more?)

    edit: after a bit more fiddling around, I got it working (at least in the editor, not yet tested on devices) doing something like this:

    Code (csharp):
    1.  
    2. fixed fade  = max(0, LinearEyeDepth( i.pos.z ) * _LightShadowData.z + _LightShadowData.w );
    3. fixed atten = min(1, SHADOW_ATTENUATION(i) + fade );
    4.  
     
    Last edited: May 15, 2017