celeste-avali-skin/Effects/AvaliRecolor.fx

36 lines
1.0 KiB
HLSL

// Compile with fxc.exe AvaliRecolor.fx /T fx_2_0 /O3
// Creates a texture at a given texture index
#define DECLARE_TEXTURE(Name, index) \
texture Name: register(t##index); \
sampler Name##Sampler: register(s##index)
// Samples the texture and returns a color
#define SAMPLE_TEXTURE(Name, texCoord) tex2D(Name##Sampler, texCoord)
DECLARE_TEXTURE(text, 0); // The texture to be recolored
uniform float4 color_replace_from; // #1ad589
uniform float4 color_replace_to;
uniform float threshold; // 0.01
// hsls provides distance instead of this...
// float fast_distance4(float4 a, float4 b) {
// float4 diff = a - b;
// return diff.x * diff.x + diff.y * diff.y + diff.z * diff.z + diff.w * diff.w;
// }
float4 ps_recolor(float4 pos: SV_Position, float4 in_color: COLOR0, float2 uv: TEXCOORD0): COLOR {
float4 color = SAMPLE_TEXTURE(text, uv);
return (distance(color, color_replace_from) < threshold ? color_replace_to : color) * in_color;
}
technique Recolor {
pass {
PixelShader = compile ps_2_0 ps_recolor();
}
}