Shader not working properly - HELP Please!

This code is working properly in XNA project.

sampler s0;
texture lightMask;
sampler lightSampler = sampler_state
{ 
Texture = <lightMask>; 
MinFilter = Linear;
MagFilter = Linear;
MipFilter = Linear;
AddressU = Clamp;
AddressV = Clamp;
};

float4 PixelShaderFunction(float2 coords: TEXCOORD0) : COLOR0
{
    float4 color = tex2D(s0, coords);
    float4 lightColor = tex2D(lightSampler, coords);
    return color * lightColor;
}

technique Technique1
{
    pass Pass1
    {
        PixelShader = compile ps_2_0 PixelShaderFunction();
    }
}

I want it run in monogame. But I made an error when I used the pipeline tool, and then I changed this code to

PixelShader = compile ps_5_0 PixelShaderFunction();

Compiled successfully. But it doesn’t work properly when the project is running.

Only the background color is shown on the screen. I don’t know why.

Please help me! Thanks a lot!

If I’m not mistaken, you need a perfect input match to the VS output. Try this:
float4 PixelShaderFunction(float4 position : SV_Position, float4 color : COLOR0, float2 coords : TEXCOORD0) : COLOR0

Also how are you passing the texture?

I use shader this way in my C# code:

GraphicsDevice.SetRenderTarget(maskRender);
spriteBatch.Begin(SpriteSortMode.Immediate, BlendState.AlphaBlend, SamplerState.PointClamp, null, null);
lightingEffect.Parameters["lightMask"].SetValue(lightRender);
lightingEffect.CurrentTechnique.Passes[0].Apply();
spriteBatch.End();

And I changed my code to

float4 PixelShaderFunction(float4 position : SV_Position, float4 color : COLOR0, float2 coords : TEXCOORD0) : COLOR0
{
	color = tex2D(s0, coords);
	float4 lightColor = tex2D(lightSampler, coords);
	return color * lightColor;
}

Rebuild and run, it works!

Thank you very much!

1 Like