Skip to content

Instantly share code, notes, and snippets.

@nir1082
Created March 8, 2018 08:22
Show Gist options
  • Save nir1082/a59a35d93e3ccf164f91d57a1d4e762d to your computer and use it in GitHub Desktop.
Save nir1082/a59a35d93e3ccf164f91d57a1d4e762d to your computer and use it in GitHub Desktop.
Shader "UI/Unlit/ReversedColor"
{
Properties
{
[PerRendererData] _MainTex ("Sprite Texture", 2D) = "white" {}
}
SubShader
{
Tags { "RenderType"="Opaque" "Queue"="Transparent" }
GrabPass { "_GrabTexture" }
LOD 100
Blend SrcAlpha OneMinusSrcAlpha
Pass
{
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#include "UnityCG.cginc"
struct appdata
{
float4 vertex : POSITION;
float2 uv : TEXCOORD0;
};
struct v2f
{
float2 uv : TEXCOORD0;
float4 vertex : SV_POSITION;
float4 grabUV : TEXCOORD1;
};
sampler2D _MainTex;
float4 _MainTex_ST;
sampler2D _GrabTexture;
v2f vert (appdata v)
{
v2f o;
o.vertex = UnityObjectToClipPos(v.vertex);
o.uv = v.uv;
o.grabUV = ComputeGrabScreenPos(UnityObjectToClipPos(v.vertex));
return o;
}
fixed4 frag (v2f i) : SV_Target
{
fixed4 col = tex2D(_MainTex, i.uv);
fixed4 grabCol = 1 - tex2D(_GrabTexture, i.grabUV);
grabCol.a = col.a;
return grabCol;
}
ENDCG
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment