Search Unity

unrecognized identifier 'SHADOW_COORDS' error in 2017.3

Discussion in 'Shaders' started by Damjan-Mozetic, Dec 19, 2017.

  1. Damjan-Mozetic

    Damjan-Mozetic

    Joined:
    Aug 15, 2013
    Posts:
    46
    Hello.

    Just updated Unity to 2017.3 and I am encountering an "unrecognized identifier 'SHADOW_COORDS'" error when using the UNITY_SHADOW_COORDS(N) define (N is an appropriate number, just to clarify). Any idea on what might be going on here?

    Thank you!
     
  2. jbooth

    jbooth

    Joined:
    Jan 6, 2014
    Posts:
    5,461
    Yes, Unity changed the macro's around in 2017.3 so that they have a reduced scope in which they are able to be used. You can fix this by including this into your shader code:

    Code (CSharp):
    1. #ifndef AUTOLIGHT_FIXES_INCLUDED
    2. #define AUTOLIGHT_FIXES_INCLUDED
    3.  
    4. #include "HLSLSupport.cginc"
    5. #include "UnityShadowLibrary.cginc"
    6.  
    7. // Problem 1: SHADOW_COORDS - undefined identifier.
    8. // Why: Using SHADOWS_DEPTH without SPOT.
    9. // The file AutoLight.cginc only takes into account the case where you use SHADOWS_DEPTH + SPOT (to enable SPOT just add a Spot Light in the scene).
    10. // So, if your scene doesn't have a Spot Light, it will skip the SHADOW_COORDS definition and shows the error.
    11. // Now, to workaround this you can:
    12. // 1. Add a Spot Light to your scene
    13. // 2. Use this CGINC to workaround this scase.  Also, you can copy this in your own shader.
    14. #if defined (SHADOWS_DEPTH) && !defined (SPOT)
    15. #       define SHADOW_COORDS(idx1) unityShadowCoord2 _ShadowCoord : TEXCOORD##idx1;
    16. #endif
    17.  
    18.  
    19. // Problem 2: _ShadowCoord - invalid subscript.
    20. // Why: nor Shadow screen neighter Shadow Depth or Shadow Cube and trying to use _ShadowCoord attribute.
    21. // The file AutoLight.cginc defines SHADOW_COORDS to empty when no one of these options are enabled (SHADOWS_SCREEN, SHADOWS_DEPTH and SHADOWS_CUBE),
    22. // So, if you try to call "o._ShadowCoord = ..." it will break because _ShadowCoord isn't an attribute in your structure.
    23. // To workaround this you can:
    24. // 1. Check if one of those defines actually exists in any place where you have "o._ShadowCoord...".
    25. // 2. Use the define SHADOWS_ENABLED from this file to perform the same check.
    26. #if defined (SHADOWS_SCREEN) || defined (SHADOWS_DEPTH) || defined (SHADOWS_CUBE)
    27. #    define SHADOWS_ENABLED
    28. #endif
    29.  
    30. #endif
     
    kosowski, XiaGu and twobob like this.