HLSL Pixel Shader that does palette swap
- by derrace
I have implemented a simple pixel shader which can replace a particular colour in a sprite with another colour.
It looks something like this:
sampler input : register(s0);
float4 PixelShaderFunction(float2 coords: TEXCOORD0) : COLOR0
{
float4 colour = tex2D(input, coords);
if(colour.r == sourceColours[0].r &&
colour.g == sourceColours[0].g &&
colour.b == sourceColours[0].b) return targetColours[0];
return colour;
}
What I would like to do is have the function take in 2 textures, a default table, and a lookup table (both same dimensions).
Grab the current pixel, and find the location XY (coords) of the matching RGB in the default table, and then substitute it with the colour found in the lookup table at XY.
I have figured how to pass the Textures from C# into the function, but I am not sure how to find the coords in the default table by matching the colour.
Could someone kindly assist?
Thanks in advance.