I'm new to custom effects (ex. pixel shaders) in monogame, but I've researched a bit and made some test effects.
I've noticed that the color variable "Color.[color]" doesn't change the color of the texture when an effect is active.
example:
I can't draw text that uses the effect, because the text doesn't turn black, it stays white.
This is my custom shader file:
sampler2D TextureSampler = sampler_state
{
Texture = <Texture>;
};
float4 PixelShaderFunction(float4 pos : SV_POSITION, float4 color1 : COLOR0, float4 texCoord : TEXCOORD0) : SV_TARGET0
{
float4 color = tex2D(TextureSampler, texCoord);
float high = .6;
float low = .4;
if (color.r > high) color.r = 1;
else if (color.r < low) color.r = 0;
if (color.g > high) color.g = 1;
else if (color.g < low) color.g = 0;
if (color.b > high) color.b = 1;
else if (color.b < low) color.b = 0;
return color;
}
technique Technique1
{
pass Pass1
{
PixelShader = compile ps_4_0_level_9_1 PixelShaderFunction();
}
}
And this is an example of the color change that doesn't happen:
spriteBatch.DrawString(font, [text], [position], Color.Black);
When the program starts (with the effect on), the text stays white and doesn't turn black. The effect works on all the other textures, when they don't need a color change.
Is this because of the sampler in the effect file?
EDIT
My question is actually if I can use the "Color.[color]" variable with a custom effect, or do I need to add a color parameter to the effect?
I ask this because I also have a button class that draws buttons with text on it. The draw function for the button draws the text and the button at almost the same time. color change for the text is written in that button class (ex. Color.Black). But when I use the custom shader, it doesn't work.
I'm also not sure if this will work with hlsl parameters for the colors, because I don't know how to seperate the button and the text with a hlsl shader, and only change the color of the text.