I'm using a shader (code below) which allows me to turn an image color into a grayscale (with transparency if needed).
Everything was perfect until I updated my device to iOS 15. Since that update, my shaders glitch as soon as the scene is rendered. After a lot of days searching for a solution, I noticed that this is related to the iPhone Dark Mode.
I provided here some "concept" example in order to show you what currently happens:
The Grayscale shader is applied onto a red cube.
- The cube A runs on an iPhone with Dark Mode activated (which is the result I get in Unity, the correct one).
- The cube B represents the same object with Dark Mode disabled.
The problem is that I've been using these shaders for a lot of items inside my application and this gives me an inconsistency and ugly UI according to the User's Dark Mode preferences.
Note: I don't think that the problem is the shader itself, because on the < iOS 15 version it works fine. I think is something about how iOS 15 handles shaders with transparency effects, but It's just a supposition 'cause I still don't know how to work with shaders (I'm a student).
This is the shader I'm using:
Shader "Unlit/NewUnlitShader"
{
Properties
{
_MainTex ("Base (RGB) Trans (A)", 2D) = "white" {}
_EffectAmount ("Effect Amount", Range (0, 1)) = 1.0
}
SubShader
{
Tags
{
"Queue"="Transparent"
"IgnoreProjector"="True"
"RenderType"="Transparent"
}
LOD 200
Blend SrcAlpha OneMinusSrcAlpha
Pass
{
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#include "UnityCG.cginc"
struct appdata_t
{
float4 vertex : POSITION;
float2 texcoord : TEXCOORD0;
};
struct v2f
{
float4 vertex : SV_POSITION;
half2 texcoord : TEXCOORD0;
};
sampler2D _MainTex;
float4 _MainTex_ST;
uniform float _EffectAmount;
v2f vert (appdata_t v)
{
v2f o;
o.vertex = UnityObjectToClipPos(v.vertex);
o.texcoord = TRANSFORM_TEX(v.texcoord, _MainTex);
return o;
}
fixed4 frag (v2f i) : SV_Target
{
fixed4 c = tex2D(_MainTex, i.texcoord);
c.rgb = lerp(c.rgb, dot(c.rgb, float3(0.3, 0.59, 0.11)), _EffectAmount);
return c;
}
ENDCG
}
}
Fallback "Standard"
}
Is this a bug or am I missing something?
UPDATE - SOLVE
It's a bug, Unity devs have been notified about this.