Skip to content

Instantly share code, notes, and snippets.

@DenchiSoft
Created January 4, 2024 17:01
Show Gist options
  • Save DenchiSoft/ba75abdaa9fa381e03980269884eb45b to your computer and use it in GitHub Desktop.
Save DenchiSoft/ba75abdaa9fa381e03980269884eb45b to your computer and use it in GitHub Desktop.
Shader "Custom/ColorRepairShader"
{
Properties
{
_MainTex("Texture", 2D) = "white" {}
_Key("Key Color", color) = (0,0,0,0)
}
Subshader
{
Pass
{
CGPROGRAM
#pragma vertex vertex_shader
#pragma fragment pixel_shader
#pragma target 3.0
sampler2D _MainTex;
float4 _Key;
struct structure
{
float4 vertex : SV_POSITION;
float2 uv : TEXCOORD0;
};
structure vertex_shader(float4 vertex:POSITION,float2 uv : TEXCOORD0)
{
structure vs;
vs.vertex = UnityObjectToClipPos(vertex);
vs.uv = uv;
return vs;
}
float4 pixel_shader(structure ps) : SV_TARGET
{
float4 color = tex2D(_MainTex, ps.uv);
float a = saturate(color.a);
float oma = 1 - a;
float oda = a <= 0 ? 0 : 1 / a;
return color.a <= 0
? float4(0, 0, 0, 0)
: float4(
saturate((color.r - _Key.r * oma) * oda),
saturate((color.g - _Key.g * oma) * oda),
saturate((color.b - _Key.b * oma) * oda), a);
}
ENDCG
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment