Last active
July 6, 2023 10:10
-
-
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)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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