c# – 为MonoGame编译着色器
我正在使用VS 2013并试图让像素着色器正常工作.我已经在XNA 4中使用了这个着色器,所以我很确定它没问题.
我正在尝试使用2MGFX工具编译着色器 刚刚跑步
Works和我得到我编译的AlphaMap.fxg文件. 但是当尝试在MonoGame中使用/加载此文件时,我得到:
对此的修复似乎是将/ DX11添加到2MGFX命令,但后来我得到此错误:
我究竟做错了什么? 着色器代码. 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 解决方法
尝试更改此行:
PixelShader = compile ps_2_0 PixelShaderFunction(); 成: PixelShader = compile ps_4_0_level_9_1 PixelShaderFunction(); 顺便说一下 – 你为什么不使用MonoGame内容模板? (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |