xna 4.0 sprite+MRT+pixelshader

xna 4.0 sprite+MRT+pixelshader,xna,xna-4.0,pixel-shader,rendertarget,spritebatch,Xna,Xna 4.0,Pixel Shader,Rendertarget,Spritebatch,我正在尝试组合两个渲染目标,颜色和法线,用于漫反射闪电,并在屏幕上渲染结果。其思想是使用具有仅包含像素着色器的效果的精灵来组合来自纹理的渲染目标。 XNA代码: GraphicsDevice.SetRenderTargetnull; GraphicsDevice.ClearOptions.Target | ClearOptions.DepthBuffer,颜色.黑色,1.0f,0; effect.currenttechnic=effect.technics[show_buffer]; effec

我正在尝试组合两个渲染目标,颜色和法线,用于漫反射闪电,并在屏幕上渲染结果。其思想是使用具有仅包含像素着色器的效果的精灵来组合来自纹理的渲染目标。 XNA代码:

GraphicsDevice.SetRenderTargetnull; GraphicsDevice.ClearOptions.Target | ClearOptions.DepthBuffer,颜色.黑色,1.0f,0; effect.currenttechnic=effect.technics[show_buffer]; effect.Parameters[normalTex].SetValuenormalRendertarget; effect.Parameters[colorTex].SetValuecolorRendertarget; effect.Parameters[AmbientIntensity].SetValueAmbientIntensity; effect.Parameters[LightDirection].SetValuelightDirection; 效果。参数[DiffuseIntensity]。设置值DiffuseIntensity; spriteBatch.Begin0,BlendState.不透明,null,null,null,effect; spriteBatch.DrawnormalRT,矢量2.零,颜色.白色; spriteBatch.结束; 由于某些原因,spriteBatch.Draw中使用的rendertarget会影响结果

像素着色器:

void Tex_PixelShaderfloat2 texCoord:TEXCOORD0,out float4 color:COLOR0 { float4 normal=tex2DnormalTexSampler,texCoord; //将正常值转换回[-1,1]范围 normal.rgb=normal.rgb*2-1; float4 baseColor=tex2dcolortex采样器,texCoord; float3 lightDirectionNorm=normalizelLightdirection; float diffuse=饱和点光源方向规范,normal.rgb; //仅适用于spriteBatch.Draw中的normalRT //spriteBatch中的colorRT。Draw提供colorRT,但结果更暗 颜色=float4 baseColor.rgb*环境强度+漫反射*漫反射强度,1.0f; //仅适用于spriteBatch.Draw中的colorRT //spriteBatch.Draw中的normalRT将给出normalRT作为结果 //颜色=tex2dcolortex采样器,texCoord; //仅适用于NormalRT //spriteBatch.Draw中的colorRT将给出colorRT作为结果 //颜色=tex2DnormalTexSampler,texCoord; //使用spriteBatch.Draw中的任何渲染目标 //颜色=40.0f、1.0f、0.0f、1.0f; } 两个渲染目标中的alpha值始终为1。将顶点着色器添加到效果会导致黑色。使用spriteBatch绘制一个没有任何效果的渲染目标。Draw显示每个渲染目标的内容都很好。我搞不懂这个。有什么想法吗?

使用GraphicsDevice.textures[1]=tex设置纹理;而不是效果。参数[tex]=tex;工作。谢谢安德鲁

将xna代码更改为:

GraphicsDevice.SetRenderTargetnull; GraphicsDevice.ClearOptions.Target | ClearOptions.DepthBuffer,颜色.黑色,1.0f,0; effect.currenttechnic=effect.technics[show_buffer]; GraphicsDevice.Textures[1]=normalRT//改变 GraphicsDevice.Textures[2]=colorRT//改变 effect.Parameters[AmbientIntensity].SetValueAmbientIntensity; effect.Parameters[LightDirection].SetValuelightDirection; 效果。参数[DiffuseIntensity]。设置值DiffuseIntensity; spriteBatch.Begin0,BlendState.不透明,null,null,null,effect; spriteBatch.DrawTexture2DcolorRT,矢量2.零,颜色.白色; spriteBatch.结束; 并将着色器代码设置为:

取样器正常取样器:寄存器1//补充 采样器颜色采样器:寄存器2//补充 void Tex_PixelShaderfloat2 texCoord:TEXCOORD0,out float4 color:COLOR0 { float4 normal=tex2DnormalSampler,texCoord;//已更改 normal.rgb=normal.rgb*2-1; float4 baseColor=tex2DcolorSampler,texCoord;//已更改 float3 lightDirectionNorm=normalizelLightdirection; float diffuse=饱和点光源方向规范,normal.rgb; 颜色=float4 baseColor.rgb*环境强度+漫反射*漫反射强度,1.0f; } SpriteBatch将设置纹理[0]。是否正在设置纹理[1]?