2013-05-19 84 views
2

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

我有這樣的錯誤: https://gamedev.stackexchange.com/questions/46994/has-anyone-got-the-krypton-lighting-engine-working-in-monogame-for-windows-8

我試圖用2MGFX,但工具報告:效果必須至少包含一種技術和通過。從我能從myshader.fx看到的文件中,它確實如此。

這裏是我的shader代碼:

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,但它仍然拋出「的影響必須包含至少一個技術,並通過

+0

嘗試使用不同的配置文件,如ps_4_0_level_9_3 sine,您的目標是Windows 8. – borrillis

+1

ps_4_0_level_9_1如果您的目標是Windows 8,ps_4_0_level_9_3如果您的目標是Windows Phone 8 –

回答

2

我得到它的工作! :)

首先我使用2MGFX工具。然後我加載這樣的效果:

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

希望它能幫助別人呢! :)

謝謝!