Shader broken in stand-alone build if Float property value is too high

I had a problem where a material would render just fine in the editor, but show up magenta in the stand-alone build; in the latter case, the log would say that the shader was unsupported.

I tracked it down to a single Property in the shader: when the value of a given float was too high, the problem would occur. Testing showed that if I set the default value of a Float to 999999.4, the shader/material rendered fine in the stand-alone; however, if I set the Float’s default value to 999999.5 or higher, I’d have the error. This value seems super arbitrary; also, interestingly, I could set the default value (in the shader) to a small value, say 1, and then set it to a “bad” value, say 999999.5 in the inspector, and the bug would NOT happen in the stand-alone build. Very weird.

I’m able to work around this, and the fact that you can set the “bad” values in the inspector (not in the shader itself) with no consequences should make this a non-blocking bug. However, I’m writing it down here in case someone comes across a similar issue, and sees this kind of behaviour.

Here’s a test shader that shows the bug.

Shader "Fake" {
    Properties {
        _Colour ("Colour", Color) = (1, 1, 1, 1)
        _BadFloat ("Bad float", Float) = 1              // this one works
        //_BadFloat ("Bad float", Float) = 999999.4     // this one works
        //_BadFloat ("Bad float", Float) = 999999.5     // this one does NOT work
    }

    SubShader {
        Pass {

            Blend One OneMinusSrcAlpha
        
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#include "UnityCG.cginc"

uniform float4 _Colour;
uniform float _BadFloat;

struct v2f {
    float4 pos : POSITION;
};


v2f vert(appdata_base v) {
    v2f o;
    o.pos = mul(UNITY_MATRIX_MVP, v.vertex);
    return o;
}


half4 frag(v2f i) : COLOR {
    return _Colour;
}

ENDCG
        }
    } 
    FallBack "Diffuse"
}

You should submit your reproduction steps and example project via the bug reporter.

Yup, forgot to mention: it’s submitted with #572228.