【发布时间】:2014-01-03 20:15:47
【问题描述】:
我正在使用 VS 2013 并试图让像素着色器正常工作。我已经让这个着色器在 XNA 4 中工作,所以我很确定它没问题。
我正在尝试使用 2MGFX 工具编译着色器
只是跑步
2MGFX.exe AlphaMap.fx AlphaMap.fxg
工作,我得到我编译的 AlphaMap.fxg 文件。
但是,当尝试在 MonoGame 中使用/加载此文件时,我得到:
MGFX 效果是这个平台的错误配置文件!
解决此问题的方法似乎是将 /DX11 添加到 2MGFX 命令,但后来我收到此错误:
像素着色器“PixelShaderFunction”必须是 SM 4.0 级别 9.1 或更高! 输入文件“AlphaMap.fx”编译失败!
我做错了什么?
着色器代码。
uniform extern texture ScreenTexture;
sampler screen = sampler_state
{
// get the texture we are trying to render.
Texture = <ScreenTexture>;
};
uniform extern texture MaskTexture;
sampler mask = sampler_state
{
Texture = <MaskTexture>;
};
// here we do the real work.
float4 PixelShaderFunction(float2 inCoord: TEXCOORD0) : COLOR
{
float4 color = tex2D(screen, inCoord);
color.rgba = color.rgba - tex2D(mask, inCoord).r;
return color;
}
technique
{
pass P0
{
// changed this to reflect fex answer
PixelShader = compile ps_4_0_level_9_1 PixelShaderFunction();
}
}
编辑
fex 的回答让我能够加载效果,但它现在似乎不起作用。
我是这样使用它的:
Texture2D Planet = _Common.ContentManager.Load<Texture2D>("Materials/RedPlanet512");
Texture2D AlphaMapp = _Common.ContentManager.Load<Texture2D>("Materials/Dots2");
Effect AlphaShader = _Common.ContentManager.Load<Effect>("Effects/AlphaMap");
AlphaShader.Parameters["MaskTexture"].SetValue(AlphaMapp);
spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, null, null, null, AlphaShader, _Common.Camera.View);
spriteBatch.Draw(Planet,
new Vector2(0, 0),
null, Color.White, 0f,
new Vector2(Planet.Width / 2, Planet.Height / 2),
1f, SpriteEffects.None, 1f);
spriteBatch.End();
这些是我使用的纹理:
http://www.syntaxwarriors.com/wp-content/gallery/alphamapping-gallery/redplanet512.png http://www.syntaxwarriors.com/wp-content/gallery/alphamapping-gallery/whitedots_0.png
【问题讨论】: