UNITY_VERSION broken in 2018.2 ?

hi there,

i just tried to add support for Unity 2018.2 to some shaders – but had to face the fact that:
#if UNITY_VERSION > 20180202
or
#if UNITY_VERSION > 201822
did not work out at all.

so is it broken or do i do something completely wrong here?

thanks,
lars

1 Like

#if UNITY_VERSION > 201822
This should work. This will include the code inside the ‘#if’ part for Unity versions higher than 2018.2.2
What you probably want is ‘#if UNITY_VERSION >= 201820’. This will include the code for any Unity version starting from 2018.2.0

3 Likes

thanks for the tip, but unfortunately it does not work… :frowning:
i tried:
#if UNITY_VERSION >= 201820
#pragma multi_compile_vertex LOD_FADE_PERCENTAGE
#else
#pragma multi_compile LOD_FADE_CROSSFADE LOD_FADE_PERCENTAGE
#endif

but the compiler complains about “redefinition of _MainTex”

only if i use:
#pragma multi_compile_vertex LOD_FADE_PERCENTAGE
and skip the #if #else and 2nd #pragma the shader compiles properly.

Well, that’s a different thing. Preprocessor doesn’t work on #pragma multi_compile directives.

so is there any other way then to just get one shader file suitable for unity 5.6.3 and unity 2018?

There is no way to have different #pragma multi_compile for different Unity versions in a single shader file. Or at least, I’m not aware of those.

What exactly are you trying to achieve?

i just want to write a surface shader that supports lod fading on 5.6.3 – 2018.2.

And why can’t you have #pragma multi_compile LOD_FADE_CROSSFADE LOD_FADE_PERCENTAGE in both versions?

because it results in cross fading even between lods which shall use percentage (when using speedtree like fading).

Hm. You could try doing something like

#if UNITY_VERSION >= 201820
#undef LOD_FADE_CROSSFADE
#endif

as the first thing in your CGPROGRAM block

that works in the shader caster pass (cg) but not the surface shader.

Can you check the output of the surface shader? I wonder, where this #undef ends up at (if it does).

cool, i can’t login on my 2nd machine… two factor authentication.

but i looked into the generated code:

#if UNITY_VERSION >=201822 is part of the block “UNITY: Original start of shader”.
but unlike the #pragmas it is NOT commented.

OK, this means that it’s inserted after the #include directives.
Then, I guess, you need to have two shaders.

thnaks anyway.
but wasn’t there a change during the 5.x cycle which would let you include something before the standard includes?

afaik, it’s not possible
what you could try to do is take a look, which include file is included first, make your own .cginc with the same name, put the #if there and include the global one afterwards

thanks – but i guess i will go with 2 shaders then.

A bit of a necro, but it appears UNITY_VERSION really is legitimately broken for editor versions which reach double digit revision numbers.

For example: 2018.2.20

Going by the documentation, or this thread, one might expect the UNITY_VERSION to be 2018220, but that messes with the original numbering system as now the 6 digit long version for 2019.1.0 (201910) would be less than the 7 digits of the expected version number. The actual UNITY_VERSION for 2018.2.20 is:

2018**40**

It appears to be combining the “.2.20” in to 40 which kind of makes sense if you think about the easiest way to convert the Unity version into a single number.

(major version, “2018”) * 100 + (minor version, “2”) + 10 + (revision, “20”) = UNITY_VERSION

2018 * 100 = 201800
2 * 10 = 20
201800 + 20 + 20 = 201840

Of course collides with what you expect 2018.4.0 to be, which is 201840. It also collides with 2018.3.10 which also uses 201840! 2018.3.11 through 2018.3.14 all use 201839, so someone noticed the problem. Just be warned the number system is inconsistent now.

Hmm. As far as I remember, the fix to clamp versions to max of 9 should have landed to 2017.4 LTS, 2018.3 & 2018.4 LTS, and is in all 2019.x versions. So yeah 2018.2 is probably missing it… is that a big problem?

Big problem? Not really. The fact this isn’t in the documentation isn’t great.

1 Like