gpt4 book ai didi

c# - 为 MonoGame 编译着色器

转载 作者:行者123 更新时间:2023-11-30 14:11:13 26 4
gpt4 key购买 nike

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

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

刚跑完

2MGFX.exe AlphaMap.fx AlphaMap.fxg

工作正常,我得到了编译后的 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, 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

最佳答案

尝试改变这一行:

    PixelShader = compile ps_2_0 PixelShaderFunction();

进入:

    PixelShader = compile ps_4_0_level_9_1 PixelShaderFunction();

顺便问一下 - 为什么不使用 MonoGame 内容模板?

关于c# - 为 MonoGame 编译着色器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20893184/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com