加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

c# – 为MonoGame编译着色器

发布时间:2020-12-16 01:59:17 所属栏目:百科 来源:网络整理
导读:我正在使用VS 2013并试图让像素着色器正常工作.我已经在XNA 4中使用了这个着色器,所以我很确定它没问题. 我正在尝试使用2MGFX工具编译着色器 刚刚跑步 2MGFX.exe AlphaMap.fx AlphaMap.fxg Works和我得到我编译的AlphaMap.fxg文件. 但是当尝试在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内容模板?

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读