Skip to content

Instantly share code, notes, and snippets.

@atori708
Last active July 6, 2023 10:10
Show Gist options
  • Save atori708/c1ebf1b9992866067350e6909ba23e70 to your computer and use it in GitHub Desktop.
Save atori708/c1ebf1b9992866067350e6909ba23e70 to your computer and use it in GitHub Desktop.
It's invert color post process shader for Unity.(Use ImageEffect or uGUI's Image)
Shader "Custom/InvertColor"
{
// Propertiesはいらなくなる / Properties is unnecessary.
SubShader {
Tags {"Queue" = "Transparent+10000"} // RenderQueueは最後になるようにとにかくでかく / Set biggest value in your scene.
GrabPass{} // 追加 / To add
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;
};
v2f vert (appdata v) {
v2f o;
o.vertex = UnityObjectToClipPos(v.vertex);
o.uv = v.uv;
return o;
}
sampler2D _GrabTexture; // _MainTexから変更 / Change from _MainTex
fixed4 frag (v2f i) : SV_Target {
fixed4 col = tex2D(_GrabTexture, i.uv);
col.rgb = 1 - col.rgb;
return col;
}
ENDCG
}
}
}
Shader "Custom/InvertColorImageEffect"
{
Properties {
_MainTex ("Texture", 2D) = "white" {}
}
SubShader {
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;
};
v2f vert (appdata v) {
v2f o;
o.vertex = UnityObjectToClipPos(v.vertex);
o.uv = v.uv;
return o;
}
sampler2D _MainTex;
fixed4 frag (v2f i) : SV_Target {
fixed4 col = tex2D(_MainTex, i.uv);
col.rgb = 1 - col.rgb;
return col;
}
ENDCG
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment