IOS build – meshrenderer shader issue?

Unity 2022.3.33f1

For some reason modifying meshrenderer shader material doesn’t work on ios, but it works on android and windows build!!

I was working on Fog Of War, where I used SimpleFOW by Revision3 it’s very simple FOW.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

namespace SimpleFOW
{
    [RequireComponent(typeof(MeshRenderer))]
    public class FogOfWarShaderControl : MonoBehaviour
    {
        public static FogOfWarShaderControl Instance { get; private set; }

        [Header("Maximum amount of revealing points")]
        [SerializeField] private uint maximumPoints = 512;

        [Header("Game Camera")]
        [SerializeField] private Camera mainCamera;

        private List<Vector4> points = new List<Vector4>();

        private Vector2 meshSize, meshExtents;

        private Vector4[] sendBuffer;

        private MeshRenderer meshRenderer;

        private void Awake()
        {
            Instance = this;

            Init();
        }

        // Initialize required variables
        public void Init()
        {
            meshRenderer = GetComponent<MeshRenderer>();
            meshExtents = meshRenderer.bounds.extents;
            meshSize = meshRenderer.bounds.size;

            points = new List<Vector4>();
            sendBuffer = new Vector4[maximumPoints];
        }

        // Transform world point to UV coordinate of FOW mesh
        public Vector2 WorldPointToMeshUV(Vector2 wp)
        {
            Vector2 toRet = Vector2.zero;

            toRet.x = (transform.position.x - wp.x + meshExtents.x) / meshSize.x;
            toRet.y = (transform.position.y - wp.y + meshExtents.y) / meshSize.y;

            return toRet;
        }

        // Show or hide FOW
        public void SetEnabled(bool on)
        {
            meshRenderer.enabled = on;
        }

        // Add revealing point to FOW renderer if amount of points is lower than MAX_POINTS
        public void AddPoint(Vector2 worldPoint)
        {
            if (points.Count < maximumPoints)
            {
                points.Add(WorldPointToMeshUV(worldPoint));
            }
        }

        // Remove FOW revealing point
        public void RemovePoint(Vector2 worldPoint)
        {
            if (worldPoint == new Vector2(0, 0))
            {
                return;
            }

            if (points.Contains(WorldPointToMeshUV(worldPoint)))
            {
                points.Remove(WorldPointToMeshUV(worldPoint));
            }
        }

        // Send any change to revealing point list to shader for rendering
        public void SendPoints()
        {
            points.ToArray().CopyTo(sendBuffer, 0);

            meshRenderer.material.SetVectorArray("_PointArray", sendBuffer);
            meshRenderer.material.SetInt("_PointCount", points.Count);
        }

        // Send new range value to shader
        public void SendRange(float range)
        {
            meshRenderer.material.SetFloat("_RadarRange", range);
        }

        // Send new scale value to shader
        public void SendScale(float scale)
        {
            meshRenderer.material.SetFloat("_Scale", scale);
        }
    }
}

And the shader

Shader "Revision3/FogOfWar"
{
    Properties
    {
        _MainTex ("Texture", 2D) = "black" {}
        _PointCount("Point count", Range(0,512)) = 0
        _Scale("Scale", Float) = 1.0
        _RadarRange("Range", Float) = .5
        _MaxAlpha("Maximum Alpha", Float) = 1.0
    }
    SubShader
    {
        Tags { "RenderType"="Transparent" "Queue"="Transparent" }
        LOD 100

        ZWrite Off
        Blend SrcAlpha OneMinusSrcAlpha

        Pass
        {
            CGPROGRAM

            #pragma vertex vert
            #pragma fragment frag
            // make fog work
            #pragma multi_compile_fog

            #include "UnityCG.cginc"

            struct appdata
            {
                float4 vertex : POSITION;
                float2 uv : TEXCOORD0;
            };

            struct v2f
            {
                float2 uv : TEXCOORD0;
                UNITY_FOG_COORDS(1)
                float4 vertex : SV_POSITION;
            };

            sampler2D _MainTex;
            float4 _MainTex_ST;

            float _RadarRange;
            uint _PointCount;
            float _Scale;
            float _MaxAlpha;

            float2 _PointArray[512];

            v2f vert (appdata v)
            {
                v2f o;
                o.vertex = UnityObjectToClipPos(v.vertex);
                o.uv = TRANSFORM_TEX(v.uv, _MainTex);
                return o;
            }

            float getDistance(float2 pa[512], float2 uv) {

                float cdist = 99999.0;


                for (uint i = 0; i < _PointCount; i++) {
                    cdist = min(cdist, distance(pa[i]*_Scale, uv));
                }


                return cdist;
            }

            fixed4 frag (v2f i) : SV_Target
            {
                // sample the texture
                fixed4 col = tex2D(_MainTex, i.uv);

                i.uv *= _Scale;

                if (_PointCount > 0)
                    col.w = min(_MaxAlpha, max(0.0f, getDistance(_PointArray, i.uv) - _RadarRange));
                else
                    col.w = _MaxAlpha;

                return col;
            }
            ENDCG
        }
    }
}

Now I create a gameobject called FogOfWar as follows

And then in Unit.cs script and Building.cs script I add the following logic

private Vector3 lastPos;

private void Update()
{
    if (lastPos != transform.position)
    {
        FogOfWarShaderControl.Instance.RemovePoint(lastPos);
        FogOfWarShaderControl.Instance.AddPoint(transform.position);

        lastPos = transform.position;

        FogOfWarShaderControl.Instance.SendPoints();
    }
}

Now this gives me the effect of FOW as follows on IOS

View post on imgur.com

where the result should be as follows on other devices

View post on imgur.com

I don’t know what causes this to happen only on ios devices.

The logic works fine on android/windows/linux/editor but not ios devices.

Is there some kind of option in ios build, where it disable meshrenderer material shader change?!

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật