- Home /
Is it possible to tell Unity not to auto-upgrade a shader?
I have a Unity 5.4 project that I need to work with Unity 5.1 also.
There's a shader using the matrix unity_ObjectToWorld in 5.4. I'm using conditional compilation:
#if UNITY_VERSION < 540
return mul(UNITY_MATRIX_V, mul(_Object2World, float4(pos, 1.0))).xyz;
#else
return mul(UNITY_MATRIX_V, mul(unity_ObjectToWorld, float4(pos, 1.0))).xyz;
#endif
This works in both versions of Unity but as soon as I reimport the shader in Unity 5.4 it auto-upgrades the shader and replaces _Object2World in the conditional with unity_Object2World, breaking the 5.1 version of the project.
Any ideas for a fix that will allow me to keep this backwards compatibility? Is there anything I can add to tell Unity not to auto-upgrade the shader file?
There is a line you can put in a file to prevent upgrade I believe. I just can't find where I read about it now :/
Answer by JakeTurner · Oct 18, 2016 at 09:15 AM
From the 5.4 release notes:
Shaders: Added ability to exclude shaders from automatic upgrade by having "UNITY_SHADER_NO_UPGRADE" anywhere in shader source file.
Thanks - putting it in a comment did work. Crowd-sourced documentation search FTW.
Answer by SamBaker · Oct 14, 2016 at 09:25 PM
I've found a workaround until a better solution comes along.
I renamed the compat.cginc file with the conditional compilation in it, to compat.cginchack. So far that stops Unity from auto-upgrading it. It also doesn't show up in Monodevelop so it's not great but it gets me by for now. You can #include "compat.cginchack" fine though.
Who downvoted this? Seems like a good workaround to me - thanks for sharing :)
Your answer
Follow this Question
Related Questions
up the contrast (0-1) in shader code 0 Answers
ShaderLab CG question 0 Answers
Make a complex object semi transparent without changing it 2 Answers
Images with gradient poorly managed by Unity 1 Answer
Shadow sprite rotation regardless of the light source 0 Answers