Why doesn't this simple shader work with MonoGame (works with XNA)

The shader controls the appearance of the foreground 2D cab texture.
Here is what the game shows with both XNA and MonoGame at daylight:


Here is what the game shows with XNA at night:

Here is what the game shows with MG at night:

As can be seen at night the foreground 2D cab texture gets darker at night, but this does not occur with MG.
Here is the shader used for XNA

`////////////////////////////////////////////////////////////////////////////////
//                            C A B   S H A D E R                             //
////////////////////////////////////////////////////////////////////////////////

////////////////////    G L O B A L   V A L U E S    ///////////////////////////

float    NightColorModifier;  // Modifier for nighttime lighting.
bool     LightOn;       // Dashboard light is on
float4   Light1Pos;     // Dashboard Light 1 cone position
float4   Light2Pos;     // Dashboard Light 2 cone position
float3   Light1Col;     // Light 1 color
float3   Light2Col;     // Light 2 color
float2   TexPos;        // Texture bounding rectangle
float2   TexSize;       // Texture bounding rectangle
texture  ImageTexture;

sampler ImageSampler = sampler_state
{
    Texture = (ImageTexture);
};

////////////////////    V E R T E X   I N P U T S    ///////////////////////////

////////////////////    V E R T E X   O U T P U T S    /////////////////////////

struct PIXEL_INPUT
{
    //float2 Position  : VPOS;
    float2 TexCoords : TEXCOORD0;
    float4 Color     : COLOR0;
    float3 Normal    : NORMAL;
};

    ////////////////////    V E R T E X   S H A D E R S    /////////////////////////

    ////////////////////    P I X E L   S H A D E R S    ///////////////////////////

    float4 PSCabShader(PIXEL_INPUT In) : COLOR0
    {
        float4 origColor = tex2D(ImageSampler, In.TexCoords) * In.Color;
        float3 shadColor = origColor.rgb * NightColorModifier;

        if (LightOn)
        {
            float2 orig = In.TexCoords * TexSize + TexPos;

            float2 diffvect = Light1Pos.xy - orig;
            diffvect.x /= Light1Pos.w;
            float lum1 = saturate ((Light1Pos.z - length(diffvect)) / 200);

            diffvect = Light2Pos.xy - orig;
            diffvect.x /= Light2Pos.w;
            float lum2 = saturate ((Light2Pos.z - length(diffvect)) / 200);

            float3 lightEffect = saturate (lum1 * Light1Col + lum2 * Light2Col);
            shadColor += origColor.rgb * lightEffect;
        }

        return float4(min(shadColor, origColor.rgb * 1.2), origColor.a);
    }

////////////////////    T E C H N I Q U E S    /////////////////////////////////


technique CabShader {
    pass Pass_0 {
        PixelShader = compile ps_2_0 PSCabShader();
    }
}

`

NightColorModifier has a value between 0.2 and 1.0, and is the value that the controls the brightness of the cab.
For Monogame I replaced ps_2_0 with ps_4_0_level_9_1 and got the result shown in the picture.
I made various trials:

  1. adding a Vertex shader
  2. removing the LightOn block
  3. forcing the output color values

All with no result.

Platform is Windows and the problem appears at least since MG 3.5 and up to dev version of October 5th, 2017.

Suggestions are welcome

I would think its probably to do with the PIXEL_INPUT, the DX 11 Shader system is really fussy about its inputs and outputs. I would make sure that they match exactly what the outputs of the Vertex Shader are.
That probably means uncommenting Position (if its in the outputs) and using SV_POSITION (I think) .

Is this an effect that you use with SpriteBatch?

Thank you.
Yes, it’s used with SpriteBatch.
There is no Vertex Shader in this shader.
Simply uncommenting Position, passing it to float4 and using SV_POSITION didn’t do the job.
I’ll have to study more.

This is a wrong post, sorry.

1 Like