Monogame HLSL shader error "The Parameter is incorrect"

Viewed 83

I got the following error message:

SharpDX.SharpDXException: 'HRESULT: [0x80070057], Module: [General], ApiCode: [E_INVALIDARG/Invalid Arguments], Message: The parameter is incorrect.

                    this.effect.Parameters["UserTexture1"].SetValue(this.grass);
                    this.effect.Parameters["UserTexture2"].SetValue(this.blocked);
                    this.effect.Parameters["WorldViewProj"].SetValue(world * mView * mProjection);
                    this.effect.Parameters["Transition"].SetValue(0.5f);

                    this.effect.CurrentTechnique.Passes[0].Apply();
                    this.graphicsDevice.DrawPrimitives(PrimitiveType.TriangleStrip, 0, 2); // exception here

The strange thing is the shader seems to work in one project which is classic .net framework but it does not work in another project which is using .net6. can anyone give me some clues on that?

float4x4 WorldViewProj : WORLDVIEWPROJECTION;
texture UserTexture1;
texture UserTexture2;
float Transition;

sampler userMap1 = sampler_state
{
    texture = <UserTexture1>;       
    AddressU = MIRROR;
    AddressV = MIRROR;
};

sampler userMap2 = sampler_state
{
    texture = <UserTexture2>;
    AddressU = MIRROR; 
    AddressV = MIRROR;
};

struct VS_INPUT
{
    float4 Position : SV_POSITION0;
    float2 Texcoord : TEXCOORD0;
};

struct VS_OUTPUT
{
    float4 Position : SV_POSITION0;
    float2 Texcoord : TEXCOORD0;
};

VS_OUTPUT vs_main(VS_INPUT Input)
{
    VS_OUTPUT Output;
    Output.Position = mul(Input.Position, WorldViewProj);
    Output.Texcoord = Input.Texcoord;
    return Output;
}

float4 ps_main(VS_OUTPUT Input) : SV_TARGET
{
   return lerp(tex2D(userMap1, Input.Texcoord), tex2D(userMap2, Input.Texcoord), Transition);
}

technique
{
    pass
    {
        PixelShader = compile ps_4_0 ps_main();
        VertexShader = compile vs_4_0 vs_main();
    }
}
1 Answers

I solved the issue for now by setting DesktopGL instead of Windows as monogame platform. But then it says that shadermodel 4 is not supported, so I had to set it to 3 which works but still very strange.

Related