Monogame HLSL 着色器错误“参数不正确”

发布于 01-18 13:38 字数 1774 浏览 3 评论 0原文

我收到以下错误消息:

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

流心雨2025-01-25 13:38:34

我现在通过设置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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文