   [.net] [fixed] pixel shader that take not in account input texture
  Hii'm wondering the following code render an empty texture:  postProcesses.SetValue("g_txSrcColor", intermediateRenderTexture);  postProcesses.Technique = "PostProcessdoNothing";  int numPasses = postProcesses.Begin(0);  for (int passe = 0; passe < numPasses; passe++)  { device.SetRenderTarget(0, backbufferColor); device.Clear(ClearFlags.Target, System.Drawing.Color.BlueViolet, 1.0f, 0); postProcesses.BeginPass(passe); device.SetStreamSource(0, iVertexBuffer, 0); device.VertexFormat = PPVERT.FVF; device.DrawPrimitives(PrimitiveType.TriangleStrip, 0, 2); postProcesses.EndPass();  }  postProcesses.End();the intermediateRenderTexture looks like as input:  the code for postProcesses FX is the following:texture g_txSrcColor;sampler2D g_samSrcColor =sampler_state{    Texture = <g_txSrcColor>;    AddressU = Clamp;    AddressV = Clamp;    MinFilter = Point;    MagFilter = Linear;    MipFilter = Linear;};//-----------------------------------------------------------------------------// Pixel Shader: PostProcessPSNothing// Desc: Performs post-processing effect that do nothing//-----------------------------------------------------------------------------float4 PostProcessPSNothing(float2 Tex : TEXCOORD0) : COLOR{    return tex2D( g_samSrcColor, Tex.xy);}//-------------------------------------// Technique: PostProcessdoNothing// Desc: Performs post-processing effect that do nothingtechnique PostProcessdoNothing{    pass p0    {   VertexShader = null;   PixelShader = compile ps_2_0 PostProcessPSNothing();   ZEnable = false;    }}  Can anyone help me to find what's wrong ?Thanks in advance, alt3.Edit: i'm using c#, .net 2.0, mdx1.1, vs2008, and there is no particular trick about renderState. iVertexBuffer and PPVERT.FVF is a simple quad and its vertexformat (position, textured)[Edited by - alt3 on April 26, 2009 8:50:14 AM]
  First, don't use mdx.  It's deprecated, obsolete, and just plain sucks.  Use Xna or SlimDX instead.Some ideas:- Why are you clearing with each pass?- Make sure the quad you're rendering the post processing to has it's texture coordinates defined.  Better yet, render it to a sprite.  There's information on the internet about how to use a custom pixel shader with sprites.- Make sure the vertices' FVF is defined correctly.That's all I can think of based on what you've shown us.   ;  Thanks for your response.Quote:Original post by gharen2First, don't use mdx.  It's deprecated, obsolete, and just plain sucks.  Use Xna or SlimDX instead.How much load does i expect to have in case of switch to XNA or SlimDX ?Quote:Original post by gharen2- Why are you clearing with each pass?It is of course unecessary. However, theses lines of code are taken from old code of mine that worked. After a refactor, i've got this problem, and i've tried to have the same behaviour as before, as a testing point of view. Quote:Original post by gharen2- Make sure the quad you're rendering the post processing to has it's texture coordinates defined.  Better yet, render it to a sprite.  There's information on the internet about how to use a custom pixel shader with sprites.- Make sure the vertices' FVF is defined correctly.[/quOK, i'll check that.All seems to be good:public struct PPVERT{    public Vector4 Position;    public float tu, tv;    public float tu2, tv2;    public static readonly VertexFormats FVF = VertexFormats.PositionW | VertexFormats.Texture2;    public static VertexElement[] Decl =   { new VertexElement(0,0,DeclarationType.Float4, DeclarationMethod.Default, DeclarationUsage.PositionTransformed, 0), new VertexElement(0,16,DeclarationType.Float4, DeclarationMethod.Default, DeclarationUsage.TextureCoordinate, 0), new VertexElement(0,24,DeclarationType.Float4, DeclarationMethod.Default, DeclarationUsage.TextureCoordinate, 1), VertexElement.VertexDeclarationEnd  };}private static void applyPostProcesses(){    SurfaceDescription backBufferDesc = backbufferColor.Description;    VertexBuffer vertexBuffer = new VertexBuffer(   typeof(PPVERT),   4,   device,   Usage.WriteOnly,   PPVERT.FVF,   Pool.Default);    PPVERT[] quad = (PPVERT[])vertexBuffer.Lock(0, 0);    {   quad[0] = new PPVERT();   quad[0].Position = new Vector4(0.0f, 0.0f, 1.0f, 1.0f);   quad[0].tu = 0.0f;   quad[0].tv = 0.0f;   quad[0].tu2 = 0.0f;   quad[0].tv2 = 0.0f;   quad[1] = new PPVERT();   quad[1].Position = new Vector4(0.0f, backBufferDesc.Height, 1.0f, 1.0f);   quad[1].tu = 0.0f;   quad[1].tv = 1.0f;   quad[1].tu2 = 0.0f;   quad[1].tv2 = 1.0f;   quad[2] = new PPVERT();   quad[2].Position = new Vector4(backBufferDesc.Width, 0.0f, 1.0f, 1.0f);   quad[2].tu = 1.0f;   quad[2].tv = 0.0f;   quad[2].tu2 = 1.0f;   quad[2].tv2 = 0.0f;   quad[3] = new PPVERT();   quad[3].Position = new Vector4(backBufferDesc.Width, backBufferDesc.Height, 1.0f, 1.0f);   quad[3].tu = 1.0f;   quad[3].tv = 1.0f;   quad[3].tu2 = 1.0f;   quad[3].tv2 = 1.0f;    }    vertexBuffer.Unlock();    PerformSinglePostProcess(vertexBuffer);//, quad);    vertexBuffer.Dispose();}private static void PerformSinglePostProcess(VertexBuffer iVertexBuffer)//, PPVERT[] quad){    device.VertexDeclaration = new VertexDeclaration(device, PPVERT.Decl);    postProcesses.SetValue("g_txSrcColor", intermediateRenderTexture);   TextureLoader.Save("d:\\tmp\\intermediateRenderTexture.png", ImageFileFormat.Png, intermediateRenderTexture);    SurfaceLoader.Save("d:\\tmp\\intermediateRenderTarget.png", ImageFileFormat.Png, intermediateRenderTarget);    // Validated techniques:    // * PostProcessInvert    // * PostProcessGreenExtraction    // * PostProcessMoreColor    // * PostProcessMultiSampleBlur    // * PostProcessMultiSampleSharp    // * PostProcessEmboss    // * PostProcessdoNothing    // * PostProcessBloomH    // * PostProcessBloomV    // * PostProcessTVization    postProcesses.Technique = "PostProcessdoNothing";   device.SetRenderTarget(0, backbufferColor);    //device.SetRenderTarget(0, intermediateRenderTarget);    device.Clear(ClearFlags.Target, System.Drawing.Color.BlueViolet, 1.0f, 0);    int numPasses = postProcesses.Begin(0);    for (int passe = 0; passe < numPasses; passe++)    {   postProcesses.BeginPass(passe);   device.SetStreamSource(0, iVertexBuffer, 0);   device.VertexFormat = PPVERT.FVF;   device.DrawPrimitives(PrimitiveType.TriangleStrip, 0, 2);   postProcesses.EndPass();    }    postProcesses.End();    SurfaceLoader.Save("d:\\tmp\\backbufferColor.png", ImageFileFormat.Png, backbufferColor);} [Edited by - alt3 on April 18, 2009 9:23:51 AM];  Seem to be shader technique issue.I don't really understand since these technique are working in another environment, as FX Composer.Here is the code of the debugged techniques:// ----------------------------------------------------------------------------// Samplers & textures// texture g_txSrcColor;texture g_txSrcNormal;texture g_txSrcPosition;texture g_txSrcVelocity;texture g_txSceneColor;texture g_txSceneNormal;texture g_txScenePosition;texture g_txSceneVelocity;sampler2D g_samSrcColor =sampler_state{    Texture = <g_txSrcColor>;    AddressU = Clamp;    AddressV = Clamp;    MinFilter = Point;    MagFilter = Linear;    MipFilter = Linear;};sampler2D g_samSrcNormal =sampler_state{    Texture = <g_txSrcNormal>;    AddressU = Clamp;    AddressV = Clamp;    MinFilter = Point;    MagFilter = Linear;    MipFilter = Linear;};sampler2D g_samSrcPosition =sampler_state{    Texture = <g_txSrcPosition>;    AddressU = Clamp;    AddressV = Clamp;    MinFilter = Point;    MagFilter = Linear;    MipFilter = Linear;};sampler2D g_samSrcVelocity =sampler_state{    Texture = <g_txSrcVelocity>;    AddressU = Clamp;    AddressV = Clamp;    MinFilter = Point;    MagFilter = Linear;    MipFilter = Linear;};sampler2D g_samSceneColor = sampler_state{    Texture = <g_txSceneColor>;    AddressU = Clamp;    AddressV = Clamp;    MinFilter = Point;    MagFilter = Linear;    MipFilter = Linear;};sampler2D g_samSceneNormal = sampler_state{    Texture = <g_txSceneNormal>;    AddressU = Clamp;    AddressV = Clamp;    MinFilter = Point;    MagFilter = Linear;    MipFilter = Linear;};sampler2D g_samScenePosition = sampler_state{    Texture = <g_txScenePosition>;    AddressU = Clamp;    AddressV = Clamp;    MinFilter = Point;    MagFilter = Linear;    MipFilter = Linear;};sampler2D g_samSceneVelocity = sampler_state{    Texture = <g_txSceneVelocity>;    AddressU = Clamp;    AddressV = Clamp;    MinFilter = Point;    MagFilter = Linear;    MipFilter = Linear;};// ----------------------------------------------------------------------------// Vertex shader related//struct VS_INPUT{    float4 screenPos : POSITION;float4 texture0  : TEXCOORD0;};struct VS_OUTPUT{    float4 hposition : POSITION;float4 Tex  : TEXCOORD0;    };VS_OUTPUT PostProcessVS(VS_INPUT IN){ VS_OUTPUT OUT;OUT.hposition = IN.screenPos;   OUT.hposition.x = (OUT.hposition.x - 150)/150 ;OUT.hposition.y = (150 - OUT.hposition.y)/150 ; OUT.Tex = IN.texture0;return OUT;}// ----------------------------------------------------------------------------// Globales & variables //static const int g_cKernelSize = 13;float2 TexelKernel[g_cKernelSize]<    string ConvertPixelsToTexels = "PixelKernel";>;static const float BlurWeights[g_cKernelSize] = {    0.002216,    0.008764,    0.026995,    0.064759,    0.120985,    0.176033,    0.199471,    0.176033,    0.120985,    0.064759,    0.026995,    0.008764,    0.002216,};float BloomScale = 1.5f;// ----------------------------------------------------------------------------// Effects & Techniques////-----------------------------------------------------------------------------// Pixel Shader: PostProcessPSTVization//-----------------------------------------------------------------------------float4 PostProcessPSTVization(VS_OUTPUT IN, float2 vPos: VPOS) : COLOR0{float4 Color;    Color = tex2D( g_samSrcColor, IN.Tex.xy);    float Mult;    if (vPos.y%2 == 0)    {    Mult = 2.0;    }    else    {    Mult = 1.0;    }    Color.r = Color.r * Mult;    Color.g = Color.g * Mult;    Color.b = Color.b * Mult;    return Color;} //-------------------------------------// Technique: PostProcessTVizationtechnique PostProcessTVization{    pass p0    {   VertexShader = compile vs_3_0 PostProcessVS();   PixelShader = compile ps_3_0 PostProcessPSTVization(); AlphaBlendEnable = false;   ZEnable= false;   CullMode    = None;   FillMode    = Solid;  // (even if wireframe is turned on)  }}//-----------------------------------------------------------------------------// Pixel Shader: PostProcessPSInvert// Desc: Performs post-processing effect that converts a colored image to//  its inverse.//-----------------------------------------------------------------------------float4 PostProcessPSInvert(VS_OUTPUT IN, float2 vPos: VPOS) : COLOR0{return 1.0f - tex2D( g_samSrcColor, IN.Tex.xy);} //-------------------------------------// Technique: PostProcessInvert// Desc: Performs post-processing effect that converts a colored image to//  its inverse.technique PostProcessInvert{    pass p0    {   VertexShader = compile vs_3_0 PostProcessVS();   PixelShader = compile ps_3_0 PostProcessPSInvert(); AlphaBlendEnable = false;   ZEnable= false;   CullMode    = None;   FillMode    = Solid;  // (even if wireframe is turned on)    }}//-----------------------------------------------------------------------------// Pixel Shader: PostProcessPSGreenExtraction// Desc: Performs post-processing effect that converts a colored image to//  conserve only green component.//-----------------------------------------------------------------------------float4 PostProcessPSGreenExtraction(VS_OUTPUT IN, float2 vPos: VPOS) : COLOR0{    float4 Color;    Color = tex2D( g_samSrcColor, IN.Tex.xy);    Color.r = 0.0;    Color.b = 0.0;    return Color;}//-------------------------------------// Technique: PostProcessGreenExtraction// Desc: Performs post-processing effect that converts a colored image to//  conserve only green component.technique PostProcessGreenExtraction{    pass p0    {   VertexShader = compile vs_3_0 PostProcessVS();   PixelShader = compile ps_3_0 PostProcessPSGreenExtraction(); AlphaBlendEnable = false;   ZEnable= false;   CullMode    = None;   FillMode    = Solid;  // (even if wireframe is turned on)    }}//-----------------------------------------------------------------------------// Pixel Shader: PostProcessPSMoreColor// Desc: Performs post-processing effect that converts a colored image to//  multiply color value.//-----------------------------------------------------------------------------float4 PostProcessPSMoreColor(VS_OUTPUT IN, float2 vPos: VPOS) : COLOR0{return tex2D( g_samSrcColor, IN.Tex.xy)*2;}//-------------------------------------// Technique: PostProcessMoreColor// Desc: Performs post-processing effect that converts a colored image to//  multiply color value.technique PostProcessMoreColor{    pass p0    {   VertexShader = compile vs_3_0 PostProcessVS();   PixelShader = compile ps_3_0 PostProcessPSMoreColor(); AlphaBlendEnable = false;   ZEnable= false;   CullMode    = None;   FillMode    = Solid;  // (even if wireframe is turned on)    }}//-----------------------------------------------------------------------------// Pixel Shader: PostProcessPSMultiSampleBlur// Desc: Performs post-processing effect that blur an image//-----------------------------------------------------------------------------float4 PostProcessPSMultiSampleBlur(VS_OUTPUT IN, float2 vPos: VPOS) : COLOR0{    float4 Color;Color = tex2D( g_samSrcColor, IN.Tex.xy);Color += tex2D( g_samSrcColor, IN.Tex.xy+0.001);Color += tex2D( g_samSrcColor, IN.Tex.xy+0.002);Color += tex2D( g_samSrcColor, IN.Tex.xy+0.003);Color = Color / 4;    return Color;}//-------------------------------------// Technique: PostProcessMultiSampleBlur// Desc: Performs post-processing effect that blur an imagetechnique PostProcessMultiSampleBlur{    pass p0    {   VertexShader = compile vs_3_0 PostProcessVS();   PixelShader = compile ps_3_0 PostProcessPSMultiSampleBlur(); AlphaBlendEnable = false;   ZEnable= false;   CullMode    = None;   FillMode    = Solid;  // (even if wireframe is turned on)    }}//-----------------------------------------------------------------------------// Pixel Shader: PostProcessPSMultiSampleSharp// Desc: Performs post-processing effect that sharp an image//-----------------------------------------------------------------------------float4 PostProcessPSMultiSampleSharp(VS_OUTPUT IN, float2 vPos: VPOS) : COLOR0{    float4 Color;Color = tex2D( g_samSrcColor, IN.Tex.xy);Color -= tex2D( g_samSrcColor, IN.Tex.xy+0.0001)*10.0f;Color += tex2D( g_samSrcColor, IN.Tex.xy-0.0001)*10.0f;    return Color;}//-------------------------------------// Technique: PostProcessMultiSampleSharp// Desc: Performs post-processing effect that sharp an imagetechnique PostProcessMultiSampleSharp{    pass p0    {   VertexShader = compile vs_3_0 PostProcessVS();   PixelShader = compile ps_3_0 PostProcessPSMultiSampleSharp(); AlphaBlendEnable = false;   ZEnable= false;   CullMode    = None;   FillMode    = Solid;  // (even if wireframe is turned on)    }}//-----------------------------------------------------------------------------// Pixel Shader: PostProcessPSEmboss// Desc: Performs post-processing effect that emboss an image//-----------------------------------------------------------------------------float4 PostProcessPSEmboss(VS_OUTPUT IN, float2 vPos: VPOS) : COLOR0{    float4 Color;Color.a = 1.0f;Color.rgb = 0.5f;Color -= tex2D( g_samSrcColor, IN.Tex.xy-0.001)*2.0f;Color += tex2D( g_samSrcColor, IN.Tex.xy+0.001)*2.0f;Color.rgb = (Color.r+Color.g+Color.b)/3.0f;    return Color;}//-------------------------------------// Technique: PostProcessEmboss// Desc: Performs post-processing effect emboss emboss an imagetechnique PostProcessEmboss{    pass p0    {   VertexShader = compile vs_3_0 PostProcessVS();   PixelShader = compile ps_3_0 PostProcessPSEmboss(); AlphaBlendEnable = false;   ZEnable= false;   CullMode    = None;   FillMode    = Solid;  // (even if wireframe is turned on)    }}//-----------------------------------------------------------------------------// Pixel Shader: PostProcessPSNothing// Desc: Performs post-processing effect that do nothing//-----------------------------------------------------------------------------float4 PostProcessPSNothing(VS_OUTPUT IN, float2 vPos: VPOS) : COLOR0{    return tex2D( g_samSrcColor, IN.Tex.xy);}//-------------------------------------// Technique: PostProcessdoNothing// Desc: Performs post-processing effect that do nothingtechnique PostProcessdoNothing{    pass p0    {   VertexShader = compile vs_3_0 PostProcessVS();   PixelShader = compile ps_3_0 PostProcessPSNothing(); AlphaBlendEnable = false;   ZEnable= false;   CullMode    = None;   FillMode    = Solid;  // (even if wireframe is turned on)    }}//-----------------------------------------------------------------------------// Pixel Shader: PostProcessPSBloomH// Desc: Performs post-processing effect that bloom horizontaly//-----------------------------------------------------------------------------float4 PostProcessPSBloomH(VS_OUTPUT IN, float2 vPos: VPOS) : COLOR0{    float4 Color = 0;    for (int i = 0; i < g_cKernelSize; i++)    {  Color += tex2D( g_samSrcColor, IN.Tex + TexelKernel.xy ) * BlurWeights;    }    return Color * BloomScale;}//-----------------------------------------------------------------------------// Technique: PostProcessBloomH// Desc: Performs post-processing effect that bloom horizontalytechnique PostProcessBloomH<    string Parameter0 = "BloomScale";    float4 Parameter0Def = float4( 1.5f, 0, 0, 0 );    int Parameter0Size = 1;    string Parameter0Desc = " (float)";>{    pass p0    {   VertexShader = compile vs_3_0 PostProcessVS();   PixelShader = compile ps_3_0 PostProcessPSBloomH(); AlphaBlendEnable = false;   ZEnable= false;   CullMode    = None;   FillMode    = Solid;  // (even if wireframe is turned on)    }}//-----------------------------------------------------------------------------// Pixel Shader: PostProcessPSBloomV// Desc: Performs post-processing effect that bloom vertically//-----------------------------------------------------------------------------float4 PostProcessPSBloomV(VS_OUTPUT IN, float2 vPos: VPOS) : COLOR0{    float4 Color = 0;    for (int i = 0; i < g_cKernelSize; i++)    {  Color += tex2D( g_samSrcColor, IN.Tex + TexelKernel.xy ) * BlurWeights;    }    return Color * BloomScale;}//-------------------------------------// Technique: PostProcessBloomV// Desc: Performs post-processing effect that bloom verticallytechnique PostProcessBloomV<    string Parameter0 = "BloomScale";    float4 Parameter0Def = float4( 1.5f, 0, 0, 0 );    int Parameter0Size = 1;    string Parameter0Desc = " (float)";>{    pass p0    {   VertexShader = compile vs_3_0 PostProcessVS();   PixelShader = compile ps_3_0 PostProcessPSBloomV(); AlphaBlendEnable = false;   ZEnable= false;   CullMode    = None;   FillMode    = Solid;  // (even if wireframe is turned on)    }}Thanks for reading.