【问题标题】:How to use shaders in MonoGame?如何在 MonoGame 中使用着色器?
【发布时间】:2013-05-19 12:42:13
【问题描述】:

谁能告诉我,如何在单人游戏中使用着色器?

我有这个错误: https://gamedev.stackexchange.com/questions/46994/has-anyone-got-the-krypton-lighting-engine-working-in-monogame-for-windows-8

我尝试使用2MGFX,但工具报告:效果必须包含至少一种技术并通过。从 myshader.fx 文件中我可以看到,确实如此。

这是我的着色器代码:

sampler TextureSampler : register(s0);
float _valueAlpha = 1;
float _valueRGB = 1;

float4 main(float4 color : COLOR0, float2 texCoord : TEXCOORD0) : COLOR0
{
    // Look up the texture color.
    float4 tex = tex2D(TextureSampler, texCoord);

    // Convert it to greyscale. The constants 0.3, 0.59, and 0.11 are because
    // the human eye is more sensitive to green light, and less to blue.
    float greyscale = dot(tex.rgb, float3(0.3, 0.59, 0.11));

    // The input color alpha controls saturation level.
    tex.rgb = lerp(greyscale, tex.rgb *_valueRGB, color.a *_valueAlpha);

    return tex;
}
technique Technique1
{
    pass Pass1
    {
        PixelShader = compile ps_3_0 main();
    }
}

我尝试将技术更改为Technique,并将传递更改为Pass,但它仍然抛出“效果必须包含至少一种技术并传递

【问题讨论】:

  • 尝试使用不同的配置文件,例如 ps_4_0_level_9_3,因为您的目标是 Windows 8。
  • ps_4_0_level_9_1 如果你的目标是 windows 8,ps_4_0_level_9_3 如果你目标是 windows phone 8

标签: xna shader monogame


【解决方案1】:

我让它工作了! :)

首先我使用了 2MGFX 工具。然后我加载了这样的效果:

BinaryReader Reader = new BinaryReader(File.Open(@"Content\\myShader.mgfxo", FileMode.Open)); 
myShader = new Effect(GraphicsDevice, Reader.ReadBytes((int)Reader.BaseStream.Length)); 

希望它也能帮助其他人! :)

谢谢!

【讨论】:

    猜你喜欢
    • 2013-12-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多