2

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

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

4

1 回答 1

2

我让它工作了!:)

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

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

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

谢谢!

于 2013-06-15T22:11:06.087 回答