Shader not working in 5.4

I wrote modified a Shader to provide a overlay effect when the a mesh overlaps another mesh here is the shader code

// Upgrade NOTE: replaced '_Object2World' with 'unity_ObjectToWorld'

Shader "FX/Culling_Shader"
{
    Properties
    {
        _MainTex("Base Color", 2D) = "white" {}
        _Color("Color", Color) = (0.5,0.5,0.5,1)
    }

        SubShader
    {
        Tags{ "Queue" = "Transparent" }

        Pass
        {
            Cull Back
            ZWrite Off
            Blend SrcAlpha OneMinusSrcAlpha

            CGPROGRAM
#pragma        vertex vert
#pragma        fragment frag

            uniform fixed4x4 _CullerSpace[2];
            uniform sampler2D _MainTex;
            uniform fixed4 _Color;

            struct vout
            {
                fixed4 pos : SV_POSITION;
                fixed4 tex : TEXCOORD0;
                fixed4 cullerpos0 : TEXCOORD1;
                fixed4 cullerpos1 : TEXCOORD2;
            };

            struct vin
            {
                fixed4 vertex : POSITION;
                fixed4 texcoord : TEXCOORD0;
            };

            vout vert(vin _in)
            {
                vout _out;
                _out.pos = mul(UNITY_MATRIX_MVP, _in.vertex);
                float4 worldpos = mul(unity_ObjectToWorld, _in.vertex);
                _out.cullerpos0 = mul(_CullerSpace[0], worldpos);
                _out.cullerpos1 = mul(_CullerSpace[1], worldpos);


                _out.tex = _in.texcoord;
                return _out;
            }

            float4 frag(vout _in) : COLOR
            {

                fixed lengths[7];
            
                lengths[0] = length(_in.cullerpos0.xyz);
                lengths[1] = length(_in.cullerpos1.xyz);



                if (lengths[0] > 0.5 && lengths[1] > 0.5)
                discard;

                fixed dis = 1;
                for (int i = 0; i < 2; i++)
                {
                    if (lengths[i] < dis)
                        dis = lengths[i];
                }

                fixed4 endColor = tex2D(_MainTex, _in.tex.xy) * _Color;
                endColor.w = ((1 - dis) - dis);
                return endColor;
            }

            ENDCG
        }
    }
}

AND

public class CullMe : MonoBehaviour
{
    public Transform[ ] cullers  = new Transform[2];// MAX set in shader

    private Material mat = null;

    void Awake()
    {
        Renderer rend = GetComponent<Renderer>();
        mat = rend.material;
    }

    void Update()
    {
        if (cullers.Length <=0 )
            return;

        for (int i = 0; i < cullers.Length; i++)
        {
            mat.SetMatrix("_CullerSpace"+i.ToString(), cullers.worldToLocalMatrix);
        }
    }
}

It worked great in 5.3 but does not work in 5.4 I have tried several Graphic API and none seem to work
Thoughts?

Solution Replace

        for (int i = 0; i < cullers.Length; i++)
        {
            mat.SetMatrix("_CullerSpace"+i.ToString(), cullers[i].worldToLocalMatrix);
        }

with

        Matrix4x4[] mats = new Matrix4x4[2];

        for (int i = 0; i < cullers.Length; i++)
        {
            mats[i] = cullers[i].worldToLocalMatrix;
        }

        mat.SetMatrixArray("_CullerSpace", mats);
1 Like