Shader macro with multi-line arguments fails to compile

Shader code like this used to work:

    return SAMPLE_TEXTURE2D_SHADOW(
        _DirectionalShadowAtlas, SHADOW_SAMPLER, positionSTS
    );

But in Unity 2020.2.0b2.3094 it fails:

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:

    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.

2 Likes

Issue is covered by this case.

Hi!
Caching preprocessor is used by default starting with 2020.2.0a13 - this is where this got broken. A fix is on its way :)

I am still getting what I believe is this issue in 2020.2 final:

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)

@PhoenixAdvanced this is something different then - can you please report a bug?

I can do. I also made this thread, which gives more detail:

https://discussions.unity.com/t/820939

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?

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.


Excellent, thank you very much!

@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?

@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.

@jjxtra looks this macro requires 4 arguments, and the macro call has three. I wonder, why it worked in the first place :)


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?

@jjxtra can you please submit a bug report? I'd like to figure out, what happened here :)


I did a few days ago from the Unity editor

1 Like

Can you please share the bug report number then?


Thank you very much, I'll check this out later when I'm in front of my work machine.