Hello there,
I am fairly new to shaders, but I had one working in my XNA project.
It basically replaces certain colors with other colors in the Pixel Shader.
sampler2D input : register(s0);
float4 FromColor1 : register(C0);
float4 FromColor2 : register(C1);
float4 FromColor3 : register(C2);
float4 FromColor4 : register(C3);
float4 ToColor1 : register(C4);
float4 ToColor2 : register(C5);
float4 ToColor3 : register(C6);
float4 ToColor4 : register(C7);
float4 main(float2 uv : TEXCOORD) : COLOR
{
float4 Color = tex2D(input, uv);
if (Color.r == FromColor1.r && Color.g == FromColor1.g && Color.b == FromColor1.b)
return ToColor1;
if (Color.r == FromColor2.r && Color.g == FromColor2.g && Color.b == FromColor2.b)
return ToColor2;
if (Color.r == FromColor3.r && Color.g == FromColor3.g && Color.b == FromColor3.b)
return ToColor3;
if (Color.r == FromColor4.r && Color.g == FromColor4.g && Color.b == FromColor4.b)
return ToColor4;
return Color;
}
technique Technique1
{
pass Pass1
{
PixelShader = compile ps_4_0 main();
}
}
This is what the code looks like in MonoGame now, which is the exact same as in XNA, but with a tiny change: the ps compile statement changed from ps_2_0
to ps_4_0
.
This seems to cause the following problem:
Instead of using the texture coordinate uv
correctly, it just always takes the pixel at 0, 0. I have tried using a Vertex Shader to input the position data, but that gave me the same result.
Does anyone know if that is a problem due to the 4.0 Pixel Shader compiler, or if that is a bug, and how to possibly fix this?