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. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

Bug Shader macro with multi-line arguments fails to compile

Discussion in '2020.2 Beta' started by Jasper-Flick, Sep 21, 2020.

  1. Jasper-Flick

    Jasper-Flick

    Joined:
    Jan 17, 2011
    Posts:
    954
    Shader code like this used to work:

    Code (CSharp):
    1.     return SAMPLE_TEXTURE2D_SHADOW(
    2.         _DirectionalShadowAtlas, SHADOW_SAMPLER, positionSTS
    3.     );
    But in Unity 2020.2.0b2.3094 it fails:

    Code (CSharp):
    1. Shader error in 'Custom RP/Unlit': 'SAMPLE_TEXTURE2D_SHADOW': Too few arguments to a macro call. at Assets/Custom RP/ShaderLibrary/Shadows.hlsl(148)
    A single-line statement does compile:

    Code (CSharp):
    1.     return SAMPLE_TEXTURE2D_SHADOW(_DirectionalShadowAtlas, SHADOW_SAMPLER, positionSTS);
    So the shader parser suddenly can no longer cope with newlines in macro argument lists.

    I don't know when this bug was introduced, but just noticed it when trying something in the 2020.2 beta.

    Submitted a bug report for it, with case ID 1279246.
     
    Last edited: Sep 21, 2020
    Peter77 and MadeFromPolygons like this.
  2. Jasper-Flick

    Jasper-Flick

    Joined:
    Jan 17, 2011
    Posts:
    954
  3. aleksandrk

    aleksandrk

    Unity Technologies

    Joined:
    Jul 3, 2017
    Posts:
    2,879
    Hi!
    Caching preprocessor is used by default starting with 2020.2.0a13 - this is where this got broken. A fix is on its way :)
     
  4. PhoenixAdvanced

    PhoenixAdvanced

    Joined:
    Sep 30, 2016
    Posts:
    316
    I am still getting what I believe is this issue in 2020.2 final:

    Code (CSharp):
    1.  
    2. Shader error in 'WeatherMaker/WeatherMakerPrecipitationShader': 'UNITY_SAMPLE_TEX2D_SAMPLER_LOD': Too few arguments to a macro call. at Assets/WeatherMaker/Prefab/Shaders/WeatherMakerCloudShaderInclude.cginc(142)
    3.  
     
  5. aleksandrk

    aleksandrk

    Unity Technologies

    Joined:
    Jul 3, 2017
    Posts:
    2,879
    @PhoenixAdvanced this is something different then - can you please report a bug?
     
  6. PhoenixAdvanced

    PhoenixAdvanced

    Joined:
    Sep 30, 2016
    Posts:
    316
  7. PhoenixAdvanced

    PhoenixAdvanced

    Joined:
    Sep 30, 2016
    Posts:
    316
    Hi aleksandrk, I am in the process of submitting a bug report, but the issue, as I mentioned in my thread above, is that the problem occurs in a paid third party shader file (WeatherMaker). Am I allowed to attach that to the bug report, or would that be a licence violation?
     
  8. aleksandrk

    aleksandrk

    Unity Technologies

    Joined:
    Jul 3, 2017
    Posts:
    2,879
    Let me double-check this on my side quickly, I think I know, what the issue is :)
    I'll answer in your other thread in a couple of minutes.
     
  9. PhoenixAdvanced

    PhoenixAdvanced

    Joined:
    Sep 30, 2016
    Posts:
    316
    Excellent, thank you very much!
     
  10. jjxtra

    jjxtra

    Joined:
    Aug 30, 2013
    Posts:
    1,455
    @aleksandrk This macro (which is a Unity built in shader macro) was working fine in 2020.1.10 and broke in 2020.1.16, do you know why?
     
  11. jjxtra

    jjxtra

    Joined:
    Aug 30, 2013
    Posts:
    1,455
    @PhoenixAdvanced I have hacked around this and refreshed the latest weather maker version. Let me know if it helps. Still does not explain what changed in the newer Unity versions.
     
  12. aleksandrk

    aleksandrk

    Unity Technologies

    Joined:
    Jul 3, 2017
    Posts:
    2,879
    @jjxtra looks this macro requires 4 arguments, and the macro call has three. I wonder, why it worked in the first place :)
     
  13. jjxtra

    jjxtra

    Joined:
    Aug 30, 2013
    Posts:
    1,455
    I am not sure, but it has worked for all Unity versions prior to Unity 2020.1.16 :) I submitted an update to use the 4 arg call. Maybe something to do with using default parameters when not specified getting broken?
     
  14. aleksandrk

    aleksandrk

    Unity Technologies

    Joined:
    Jul 3, 2017
    Posts:
    2,879
    @jjxtra can you please submit a bug report? I'd like to figure out, what happened here :)
     
  15. jjxtra

    jjxtra

    Joined:
    Aug 30, 2013
    Posts:
    1,455
    I did a few days ago from the Unity editor
     
    aleksandrk likes this.
  16. aleksandrk

    aleksandrk

    Unity Technologies

    Joined:
    Jul 3, 2017
    Posts:
    2,879
    Can you please share the bug report number then?
     
  17. PhoenixAdvanced

    PhoenixAdvanced

    Joined:
    Sep 30, 2016
    Posts:
    316
    Thank you very much, I'll check this out later when I'm in front of my work machine.