Search Unity

Resolved Compile error in shader in Unity 2020.2.3 but not in Unity 2019.2.17

Discussion in 'Shaders' started by Gladyon, Feb 14, 2021.

  1. Gladyon

    Gladyon

    Joined:
    Sep 10, 2015
    Posts:
    389
    I've written a few shaders which were working perfectly with Unity 2019.2.17.
    When I upgrade to Unity 2020.2.3 they throw some errors and a lot of warnings.

    The errors and warnings made no real sense, and in the end I've fixed one warning which fixed all the other warnings and errors.
    It was this warning:
    It was located on that line of code (please look at the right end of the line, the problem lies there...):
    Code (CSharp):
    1. // ************************************************************************************************************************************************ \\
    Yes, I know that it's only a comment (I use that in a pattern to separate functions) and that it should work perfectly fine, yet it generates a warning.

    I had hundreds of these warnings, and they generated other warnings and errors (I guess that at some point Unity simply stopped reading the code).

    The fix was to replace my pattern with:
    Code (CSharp):
    1. // ************************************************************************************************************************************************
     
  2. aleksandrk

    aleksandrk

    Unity Technologies

    Joined:
    Jul 3, 2017
    Posts:
    3,025
    We added a new preprocessor for shaders in 2020.2. It is more strict than what was used before.
    This pattern is not "just a comment". Those trailing backslashes tell the preprocessor that the current line continues on the next line. The next line becomes part of the comment.
     
  3. Gladyon

    Gladyon

    Joined:
    Sep 10, 2015
    Posts:
    389
    Thank you for the explanation.

    You may want to change the error message, as it doesn't explain that at all:
     
  4. aleksandrk

    aleksandrk

    Unity Technologies

    Joined:
    Jul 3, 2017
    Posts:
    3,025
    This warning is about something different, and shouldn't explain this :)
    It just says that there shouldn't be any spaces between the backslash and the new line, and it just happened that your code had it.
     
  5. Gladyon

    Gladyon

    Joined:
    Sep 10, 2015
    Posts:
    389
    No, my code had no space character between the last '\' and the new line.
    It probably doesn't like the CR-LF and consider that CR is a space character.

    Now that I know that '\\' is used to append the next line I won't have any problem with it again, but other people may face the same warning and struggle to find out the root of the problem.
     
  6. aleksandrk

    aleksandrk

    Unity Technologies

    Joined:
    Jul 3, 2017
    Posts:
    3,025
    Perhaps, I'll check.
    Well, this is just correct preprocessor behaviour :)
     
  7. Hexane

    Hexane

    Joined:
    Jan 23, 2018
    Posts:
    17
    Correct preprocessor behavior is great, but like Gladyon says, now I'm having this problem and I have no clue what to do with it. :)
     
  8. aleksandrk

    aleksandrk

    Unity Technologies

    Joined:
    Jul 3, 2017
    Posts:
    3,025
    @Hexane what exactly is the error you see?
     
  9. Hexane

    Hexane

    Joined:
    Jan 23, 2018
    Posts:
    17
    @aleksandrk

    I get this warning in the Console constantly that keeps polluting the logs:

    >Shader warning in '[BrickBreak_vfx] [Burst] OutputUpdate': Extra space between '\' and newline. at VFXCommon.hlsl(204)

    When I click the generated file it points to, the inspector says this:
    >[Brick Break_vfx] [Burst] Output Update (Compute Shader)
    >CSMain Directo3D11
    >Preprocess only [false]
    >Errors (6)
    >Extra space between '\' and newline. ...................................................... 26 VFXCommon.hlsl:202
    >Extra space between '\' and newline. at kernel CS Main ........................ 26 VFXCommon.hlsl:202
    >Extra space between '\' and newline. ...................................................... 26 VFXCommon.hlsl:203
    >Extra space between '\' and newline. at kernel CS Main ........................ 26 VFXCommon.hlsl:203
    >Extra space between '\' and newline. ...................................................... 26 VFXCommon.hlsl:204
    >Extra space between '\' and newline. at kernel CS Main ........................ 26 VFXCommon.hlsl:204

    When I click "Show compiled code" and go to line 26 it says:
    > 25: if_nz r0.y
    > 26: ..ishl r0.y, r1.x, l(8)
    > 27: ..ld_raw_indexable(raw_buffer)(mixed,mixed,mixed,mixed) r0.yzw, r0.y, t0.xxyz

    (Added periods to show indent)

    There's no '\' anywhere. This is a project that I've upgraded from a previous version to version 2021/2022. I've also recompiled all of my VFX Graph scripts but it keeps happening. I'm now using 2022.2.18.
     
    Last edited: May 8, 2023
    inin13 likes this.
  10. aleksandrk

    aleksandrk

    Unity Technologies

    Joined:
    Jul 3, 2017
    Posts:
    3,025
    Please check VFXCommon.hlsl line 26
     
  11. Hexane

    Hexane

    Joined:
    Jan 23, 2018
    Posts:
    17
    Ah, duh, it didn't occur to me that VFXCommon.hlsl would be its own file. I found it under "Library/PackageCache/com.unity.render-pipelines.universal@14.0.7/Runtime/VFXGraph/Shaders/VFXCommon.hlsl"

    Code (CSharp):
    1. #if defined(_GBUFFER_NORMALS_OCT)
    2. #define VFXComputePixelOutputToNormalBuffer(i,normalWS,uvData,outNormalBuffer) \
    3. { \
    4.     float2 octNormalWS = PackNormalOctQuadEncode(normalWS); \          // values between [-1, +1], must use fp32 on some platforms
    5.     float2 remappedOctNormalWS = saturate(octNormalWS * 0.5 + 0.5); \  // values between [ 0,  1]
    6.     half3 packedNormalWS = PackFloat2To888(remappedOctNormalWS); \     // values between [ 0,  1]
    7.     outNormalBuffer = float4(packedNormalWS, 0.0); \
    8. }
    9. #else
    10. #define VFXComputePixelOutputToNormalBuffer(i,normalWS,uvData,outNormalBuffer) \
    11. { \
    12.     outNormalBuffer = float4(normalWS, 0.0); \
    13. }
    14. #endif
    I edited the file but Unity keeps regenerating the file as-is. I also reinstalled the com.unity.render-pipelines.universal@14.0.7 package but it keeps happening (and broke all my Shader Graph materials in the process ). I wonder if it's something else on my end?
     
    inin13 likes this.
  12. aleksandrk

    aleksandrk

    Unity Technologies

    Joined:
    Jul 3, 2017
    Posts:
    3,025
    No. I would suggest reporting this as a bug since it's Unity code.
     
  13. Hexane

    Hexane

    Joined:
    Jan 23, 2018
    Posts:
    17
    Will look into it, thank you so much!
     
    aleksandrk likes this.
  14. Gustjc

    Gustjc

    Joined:
    Oct 16, 2017
    Posts:
    9
    I can also confirm this is happening. It's just a warning, but it is annoying.

    It started happening to me after I've updated the URP package from:
    - "com.unity.render-pipelines.universal": "12.1.10",
    + "com.unity.render-pipelines.universal": "14.0.7",
     
    Hexane likes this.
  15. Bersaelor

    Bersaelor

    Joined:
    Oct 8, 2016
    Posts:
    111
    Same here, same update of the `Visual Effect Graph` (and URP) package to 14.0.7.
     
  16. maxmcarthur

    maxmcarthur

    Joined:
    Jan 25, 2015
    Posts:
    3
    Same issue.

    Outside of the already-identified problem in the source with the " \" in the last lines of VFX Common in com.unity.render-pipelines.universal@14.0.7, when changing the Output Quad settings you can find that the Additive and Opaque mixing options don't trigger the warnings while Alpha and Alpha Premultiplied do.

    I guess you could change to Additive and modify the colors a bit in certain use cases, if the warnings are the greater evil.
     
  17. Snigros

    Snigros

    Joined:
    Jun 12, 2018
    Posts:
    38
    Same issue here...with update to Unity LTS 2022.3.0 (and hence Shader Graph 14.0.7)....
     
  18. yupengfei

    yupengfei

    Joined:
    Nov 10, 2017
    Posts:
    21
    same issue on 2022.2.20f1 and visual effect graph 14.0.7
     
  19. aleksandrk

    aleksandrk

    Unity Technologies

    Joined:
    Jul 3, 2017
    Posts:
    3,025
    Did anyone file a bug report?
     
  20. OliverTheLove

    OliverTheLove

    Joined:
    Jun 26, 2016
    Posts:
    24
  21. OliverTheLove

    OliverTheLove

    Joined:
    Jun 26, 2016
    Posts:
    24
    I managed to get rid of the warnings locally, as a temporary solution, by removing the comments in the package manager. UnityHub\2022.3.0f1\Editor\Data\Resources\PackageManager\BuiltInPackages\com.unity.render-pipelines.universal\Runtime\VFXGraph\Shaders\VFXCommon.hlsl

    #if defined(_GBUFFER_NORMALS_OCT)
    #define VFXComputePixelOutputToNormalBuffer(i,normalWS,uvData,outNormalBuffer)\
    {\
    float2 octNormalWS = PackNormalOctQuadEncode(normalWS);\
    float2 remappedOctNormalWS = saturate(octNormalWS * 0.5 + 0.5);\
    half3 packedNormalWS = PackFloat2To888(remappedOctNormalWS);\
    outNormalBuffer = float4(packedNormalWS, 0.0);\
    }
    #else
    #define VFXComputePixelOutputToNormalBuffer(i,normalWS,uvData,outNormalBuffer)\
    {\
    outNormalBuffer = float4(normalWS, 0.0);\
    }
    #endif
     
    inin13, Gustjc, Sphax84 and 1 other person like this.
  22. EpsilonsQc

    EpsilonsQc

    Joined:
    Feb 27, 2022
    Posts:
    2
    I can also confirm that I have the exact same issue within
    Unity 2022.2.21f1
    using
    Shader Graph 14.0.7
    and that the solution provided by @OliverTheLove (removing the comments at line 203, 204 and 205) worked fine to temporarily fix the problem.
     
    Last edited: Jun 6, 2023
    Arnold_2013 likes this.
  23. Sphax84

    Sphax84

    Joined:
    Jun 23, 2015
    Posts:
    36
    I had that exact same issue with Unity 2022.2.21f1 and even after updating to 2022.3.1f1(lts) I still have that issue...
    Shader Graph, Visual Effect Graph and URP 14.0.8
     
  24. bartuq

    bartuq

    Joined:
    Sep 26, 2016
    Posts:
    127
    The issue still exists in the latest LTS 2022.3.2f1.
     
    ZenOwl likes this.
  25. aleksandrk

    aleksandrk

    Unity Technologies

    Joined:
    Jul 3, 2017
    Posts:
    3,025
    If you check the link posted above, it says it has been fixed in 2023.2 already, and 2023.1 and 2022.3 didn't get it yet.
     
  26. kodra_dev

    kodra_dev

    Joined:
    Oct 31, 2022
    Posts:
    108
    I wonder what LTS stands for. Definitely not long-term support for Unity Inc.
     
  27. kaan0550

    kaan0550

    Joined:
    Jun 2, 2019
    Posts:
    10
    Bug exist at 2022.3.3f1
     
  28. onuralpyilkin

    onuralpyilkin

    Joined:
    Dec 12, 2015
    Posts:
    2
    I have the same warning in 2022.3.0f1. I couldn't find any solution yet.
     
  29. aleksandrk

    aleksandrk

    Unity Technologies

    Joined:
    Jul 3, 2017
    Posts:
    3,025
    The link above says it has been fixed in 2022.3.5f1, 2023.1.3f1 and 2023.2.0a15.
     
    AxelFaux and Threeyes like this.
  30. ZenOwl

    ZenOwl

    Joined:
    Oct 14, 2018
    Posts:
    5
    Confirming it is not fixed in 2023.1.3f1...still breaking "hidden" shaders.
     
    Hexane likes this.