Monogame HLSL 着色器错误“参数不正确”
我收到以下错误消息:
SharpDX.SharpDXException:'HRESULT:[0x80070057],模块:[常规], ApiCode:[E_INVALIDARG/无效参数],消息:参数是 不正确。
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
奇怪的是,着色器似乎在一个经典 .net 框架项目中工作,但在另一个使用 .net6 的项目中不起作用。谁能给我一些线索吗?
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();
}
}
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();
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

我现在通过设置DesktoPGL而不是Windows作为单体平台来解决问题。
但是后来说Shadermodel 4不支持,因此我必须将其设置为3的工作,但仍然非常奇怪。
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.