如何在MonoGame中使用着色器?

时间:2013-05-19 12:42:13

标签: xna shader monogame

有人可以告诉我,如何在monogame中使用着色器?

我有这个错误: 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,但它仍会抛出“效果必须包含至少一种技术并传递

1 个答案:

答案 0 :(得分:2)

我得到了它的工作! :)

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

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

希望它也会帮助别人! :)

谢谢!