微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

c# – 为MonoGame编译着色器

我正在使用VS 2013并试图让像素着色器正常工作.我已经在XNA 4中使用了这个着色器,所以我很确定它没问题.

我正在尝试使用2MGFX工具编译着色器

刚刚跑步

2MGFX.exe AlphaMap.fx AlphaMap.fxg

Works和我得到我编译的AlphaMap.fxg文件.

但是当尝试在MonoGame中使用/加载此文件时,我得到:

The MGFX effect is the wrong profile for this platform!

对此的修复似乎是将/ DX11添加到2MGFX命令,但后来我得到此错误

Pixel shader ‘PixelShaderFunction’ must be SM 4.0 level 9.1 or higher!
Failed to compile the input file ‘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,AlphaShader,_Common.Camera.View);

    spriteBatch.Draw(Planet,new Vector2(0,0),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

解决方法

尝试更改此行:

PixelShader = compile ps_2_0 PixelShaderFunction();

成:

PixelShader = compile ps_4_0_level_9_1 PixelShaderFunction();

顺便说一下 – 你为什么不使用MonoGame内容模板

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐