Mine is a generic question. Since I know little about the HLSL language, I was wondering if there is a method / function / sub that compares two colors to see if they are equal.
In particular, my pixel shader is a simple color replacer. Here is the code:
sampler TextureSampler;
struct PixelShaderOutput
{
float4 Position : SV_POSITION;
float4 Color : COLOR0;
float2 TextureCoordinates : TEXCOORD0;
};
float4 OldColor; // Parameter
float4 NewColor; // Parameter
float4 Main(PixelShaderOutput input) : COLOR0
{
float4 color = tex2D(TextureSampler, input.TextureCoordinates);
if (color.a)
{
if (color.r == OldColor.r && color.g == OldColor.g && color.b == OldColor.b) // Is there a way to simplify this line?
{
color = NewColor;
}
color *= input.Color;
}
return color;
}
technique
{
pass
{
PixelShader = compile ps_4_0_level_9_3 Main();
}
}
Though i dunno what you are trying to say with the color there? If its just supposed to be more then zero then execute? Then just get the sign of it and multiply it with the lerp flag. * sign(color.a);
I just want to add that if you want to find close color then you can treat it as point in 3d space and do something like if(distanceSquared(color1, color2) < 16)…