有人可以告诉我,如何在单游戏中使用着色器吗?
我尝试使用 2MGFX,但该工具报告:效果必须包含至少一种技术和 channel 。从 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
,但它仍然抛出“效果必须包含至少一种技术并通过”
最佳答案
我成功了! :)
首先我使用了2MGFX工具。然后我加载了这样的效果:
BinaryReader Reader = new BinaryReader(File.Open(@"Content\\myShader.mgfxo", FileMode.Open));
myShader = new Effect(GraphicsDevice, Reader.ReadBytes((int)Reader.BaseStream.Length));
希望它对其他人也有帮助! :)
谢谢!
关于xna - 如何在 MonoGame 中使用着色器?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16634752/