OK both versions here, are modified versions of other xray/rim shaders I found from wiki or forums.
I added the passes and ztest/write changes, so that the alpha sorting looks clean, and it renders on top of objects.
They both look great, and work fine on PC.
But on iOS device The first one errors out, and the second one works.
Maybe cos the first one is missing a fragment shader ?
I’m no shader expert yet, but would like to know exactly why ? thanks
Shader "XRay"
{
Properties {
_Color ("Tint (RGB)", Color) = (1,1,1,1)
_RampTex ("Facing Ratio Ramp (RGB)", 2D) = "white" {}
}
SubShader
{
//Tags { "Queue"="Transparent+1" }
Tags { "Queue" = "Overlay" }
Pass
{
ZTest Off
ZWrite On
Blend Zero One
SetTexture [_MainTex]
{
combine texture
}
}
Pass
{
ZTest LEqual
ZWrite On
Blend Zero One
SetTexture [_MainTex]
{
combine texture
}
}
Pass
{
//ZTest Always
ZTest LEqual
ZWrite Off
//Tags { "Queue" = "Transparent" }
//Tags { "Queue"="Transparent+1" }
//Tags { "Queue" = "Overlay" }
Blend One One
CGPROGRAM
// Upgrade NOTE: excluded shader from OpenGL ES 2.0 because it does not contain a surface program or both vertex and fragment programs.
#pragma exclude_renderers gles
#pragma vertex vert
#include "UnityCG.cginc"
struct v2f
{
float4 pos : SV_POSITION;
float4 uv : TEXCOORD0;
};
v2f vert (appdata_base v)
{
v2f o;
o.pos = mul (UNITY_MATRIX_MVP, v.vertex);
float3 viewDir = normalize(ObjSpaceViewDir(v.vertex));
o.uv = float4( dot(viewDir,v.normal), 0.5, 0.0, 1.0 );
return o;
}
ENDCG
SetTexture [_RampTex] {constantColor[_Color] combine texture * constant}
}
/* ZTest Off
Pass
{
Blend One One
SetTexture [_MainTex]
{
constantColor[_Color]
}
} */
}
Fallback "XRay2"
}
the one that works on iOS…
Shader "XRay-cloud" {
Properties {
_Color ("Tint (RGB)", Color) = (1,1,1,1)
_RampTex ("Facing Ratio Ramp (RGB)", 2D) = "white" {}
}
SubShader {
Cull Off //turn this on if using Blend One One
ZWrite Off
//Tags { "RenderType"="Opaque" "Queue" = "Transparent" "VisibleInDepth"="On" "Queue" = "Overlay"}
Tags { "RenderType"="Opaque" "Queue" = "Overlay" "VisibleInDepth"="On" }
//Blend One One
Pass
{
ZTest Off
ZWrite On
Blend Zero One
SetTexture [_MainTex]
{
combine texture
}
}
Pass
{
ZTest LEqual
ZWrite On
Blend Zero One
SetTexture [_MainTex]
{
combine texture
}
}
Pass {
//Blend One OneMinusSrcColor
Blend One One
ZTest LEqual
ZWrite Off
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#include "UnityCG.cginc"
float4 _Color;
sampler2D _RampTex;
struct v2f {
float4 pos : SV_POSITION;
float2 uv : TEXCOORD0;
};
float4 _RampTex_ST;
v2f vert (appdata_base v) {
v2f o;
o.pos = mul (UNITY_MATRIX_MVP, v.vertex);
float3 viewDir = normalize(ObjSpaceViewDir(v.vertex));
o.uv = float4( abs(dot(viewDir,v.normal)), 0.5, 0.0, 1.0 );
return o;
}
half4 frag (v2f i) : COLOR
{
half4 texcol = tex2D (_RampTex, i.uv);
return texcol * _Color;
}
ENDCG
}
}
Fallback "VertexLit"
}