CrossFade for LODs without LodGroup

Hello!

I have the following shader for CrossFading:

Shader "Custom/CrossFadingLod (Dither)"
{
    Properties
    {
        _Color ("Color", Color) = (1,1,1,1)
        _MainTex ("Albedo (RGB)", 2D) = "white" {}
        _Glossiness ("Smoothness", Range(0,1)) = 0.5
        _Metallic ("Metallic", Range(0,1)) = 0.0
    }
    SubShader
    {
        Tags { "RenderType"="TransparentCutout" "Queue"="AlphaTest" }
        LOD 200
       
        CGPROGRAM

        #pragma multi_compile _ LOD_FADE_CROSSFADE

        #pragma surface surf Standard vertex:vert
        #pragma target 3.0

        sampler2D _MainTex;

        struct Input
        {
            float2 uv_MainTex;
            UNITY_DITHER_CROSSFADE_COORDS
        };

        half _Glossiness;
        half _Metallic;
        fixed4 _Color;

        void vert(inout appdata_full v, out Input o)
        {
            UNITY_INITIALIZE_OUTPUT(Input, o);
            UNITY_TRANSFER_DITHER_CROSSFADE(o, v.vertex);
        }

        void surf(Input IN, inout SurfaceOutputStandard o)
        {
            // Albedo comes from a texture tinted by color
            fixed4 c = tex2D (_MainTex, IN.uv_MainTex) * _Color;
            o.Albedo = c.rgb;
            // Metallic and smoothness come from slider variables
            o.Metallic = _Metallic;
            o.Smoothness = _Glossiness;
            o.Alpha = c.a;
#ifdef LOD_FADE_CROSSFADE
            UNITY_APPLY_DITHER_CROSSFADE(IN);
#endif
        }
        ENDCG
    }
    FallBack "Diffuse"
}

How to work with it without LodGroup?

I tried to send unity_LODFade in the shader

    obj.gameObject.GetComponent<MeshRenderer>().sharedMaterial.SetVector("unity_LODFade", new Vector4(znachenie, 1,1,1));

but received a warning:

Trying to set builtin parameter "unity_LODFade". Will be ignored.

Help me please! :slight_smile:

Looks to me like they are intercepting the SetVector() call when the parameter name uses one of the builtin ones.
To circumvent this you might look for all the places in the cginc files that have definitions for:
UNITY_TRANSFER_DITHER_CROSSFADE()
UNITY_APPLY_DITHER_CROSSFADE()
UNITY_DITHER_CROSSFADE_COORDS
etcetera and create your own shader functionality utilizing custom parameter names. Simply spoken: copy their stuff and modify the parameter names.

Thank you, but I want to use the standard features LODs. :frowning:

I’m not sure what the reason for this is, but it’s pretty annoying that we cannot set unity_LODFade from script.