Custom Outline Shader acting weird on iOS builds.
Hello! We are using a custom outline shader in our project. It works great in the editor, on android, and on older iOS devices, but it seems on iOS 11 devices, the outline on the shader appears to disappear. It clearly still has the same shader on, but almost appears as if the values are getting adjusted in the builds or something strange.
Does anyone know anything about why this would happen? I'll shader the shader code below. I did not write it.
Any help is greatly appreciated!
Shader "Custom/OutlineShader" {
Properties {
_MainTex ("Base (RGB)", 2D) = "white" {}
_Outline("Outline Thickness", Range(0.0, 0.3)) = 0.002
_OutlineColor("Outline Color", Color) = (0,0,0,1)
}
CGINCLUDE
#include "UnityCG.cginc"
sampler2D _MainTex;
half4 _MainTex_ST;
half _Outline;
half4 _OutlineColor;
struct appdata {
half4 vertex : POSITION;
half4 uv : TEXCOORD0;
half3 normal : NORMAL;
fixed4 color : COLOR;
};
struct v2f {
half4 pos : POSITION;
half2 uv : TEXCOORD0;
fixed4 color : COLOR;
};
ENDCG
SubShader
{
Tags {
"RenderType"="Opaque"
"Queue" = "Transparent"
}
Pass{
Name "OUTLINE"
Cull Front
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
v2f vert(appdata v)
{
v2f o;
o.pos = UnityObjectToClipPos(v.vertex);
half3 norm = mul((half3x3)UNITY_MATRIX_IT_MV, v.normal);
half2 offset = TransformViewToProjection(norm.xy);
o.pos.xy += offset * o.pos.z * _Outline;
o.color = _OutlineColor;
return o;
}
fixed4 frag(v2f i) : COLOR
{
fixed4 o;
o = i.color;
return o;
}
ENDCG
}
Pass
{
Name "TEXTURE"
Cull Back
ZWrite On
ZTest LEqual
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
v2f vert(appdata v)
{
v2f o;
o.pos = UnityObjectToClipPos(v.vertex);
o.uv = TRANSFORM_TEX(v.uv, _MainTex);
o.color = v.color;
return o;
}
fixed4 frag(v2f i) : COLOR
{
fixed4 o;
o = tex2D(_MainTex, i.uv.xy);
return o;
}
ENDCG
}
}
}
Hi there, Have you found a solution?, im having the same problem over here. cheers. [Edit] I also found your reddit post, the shader files U shared aren't available anymore, I know how to write shaders, im not highly skilled since im still a noob in CG but with your files & experience we may find a suitable solution.
Answer by daniil_iisus · Jul 15, 2018 at 12:53 AM
Well I've found a solution, and it's thanks to you @Josepht45 for sharing that the shader works fine under older iOS versions, the most relevant factor was the Metal Graphics API, I supposed its shaders work differently from OpenGL's, so to fix shaders working weird in iOS you need to be working with macOS and in Unity go to;
Edit->Project Settings->Player, under the iOS tab select; Other, and enable; Metal Editor Support* and Metal API Validation*
Unity should restart using the Metal API and render your scene identical as it would in your IOS device, use your shader "Properties" Block to parametrize its values and play around until you achieve the desired look.
In your case which is very similar to mine just modify:
_Outline("Outline Thickness", Range(0.0, 0.3)) = 0.002
To
_Outline ("Outline width", Range (.002, 0.1)) = .005
Apparently Metal draws the line very thin basically invisible so just use a greater value for thickness in your IOS builds.