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…):
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).
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.
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.
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.
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:
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.
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”
#if defined(_GBUFFER_NORMALS_OCT)
#define VFXComputePixelOutputToNormalBuffer(i,normalWS,uvData,outNormalBuffer) \
{ \
float2 octNormalWS = PackNormalOctQuadEncode(normalWS); \ // values between [-1, +1], must use fp32 on some platforms
float2 remappedOctNormalWS = saturate(octNormalWS * 0.5 + 0.5); \ // values between [ 0, 1]
half3 packedNormalWS = PackFloat2To888(remappedOctNormalWS); \ // values between [ 0, 1]
outNormalBuffer = float4(packedNormalWS, 0.0); \
}
#else
#define VFXComputePixelOutputToNormalBuffer(i,normalWS,uvData,outNormalBuffer) \
{ \
outNormalBuffer = float4(normalWS, 0.0); \
}
#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?
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.