- Home /
Invert filter reticule
I have a working reticle, but I'd like to use it as an invert filter so that bits of the scene behind it are rendered with their colors inverted. This results in the reticle's visibility being consistent yet non-obstructive. Below is a demonstrative screenshot from Minecraft. Some players may not notice this, but I sure as hell do. And, I like it.
My current reticle is a GUITexture, but I can change it if doing so were to make this effect possible.
Answer by ScroodgeM · Jul 29, 2012 at 07:43 AM
use this shader and plane with alpha-texture in front of camera.
InvertColor.shader
Shader "Unity Answers/InvertColor" { Properties { _MainTex ("Alpha (A) only", 2D) = "white" {} _AlphaCutOff ("Alpha cut off", Range(0,1)) = 1 } SubShader { Tags { "Queue" = "Transparent+10" } Pass { Fog { Mode Off } Blend OneMinusDstColor Zero ZWrite Off
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
sampler2D _MainTex;
float _AlphaCutOff;
struct appdata
{
float4 vertex : POSITION;
float4 texcoord : TEXCOORD0;
};
struct v2f
{
float4 pos : SV_POSITION;
float4 uv : TEXCOORD0;
};
v2f vert (appdata v)
{
v2f o;
o.pos = mul(UNITY_MATRIX_MVP, v.vertex);
o.uv = float4(v.texcoord.xy, 0, 0);
return o;
}
half4 frag( v2f i ) : COLOR
{
half4 c = 1;
c.a = tex2D(_MainTex, i.uv.xy).a;
clip(_AlphaCutOff - c.a);
return c;
}
ENDCG
}
}
}
Excellent! I used a quad to cut down on triangles, and it looks great. I see significant potential elsewhere for this as well. $$anonymous$$any thanks, good sir.
I still don't know how to use this shader. Any step-by-step please?
Your answer
Follow this Question
Related Questions
Invert The Color Of A GUIText Crosshair? 1 Answer
Is it possible to invert all colors of sprites based on the camera? 1 Answer
Font Color changing shader [color changes based on what background color is] 1 Answer
How do I invert the color of ui text to make it more readable, on a messy background? 4 Answers
Making FPS Reticule Change 1 Answer