XNA Creators Club Online
Page 1 of 1 (3 items)
Sort Posts: Previous Next

How can I access a color from the back buffer? (Blur Effect)

Last post 09-06-2008 1:21 PM by sonnendeck. 2 replies.
  • 09-04-2008 5:14 PM

    How can I access a color from the back buffer? (Blur Effect)

    Hello!

    I wrote a small shader test program and I have a problem. I wrote a 2 pass blur effect, my technique looks like:

    1 technique blur 
    2
    3     pass p0 
    4     { 
    5         vertexshader = compile vs_1_1 VertexShader(); 
    6         pixelshader = compile ps_2_0 PS_HorBlur();         
    7     } 
    8     pass p1 
    9     {   
    10         PixelShader  = compile ps_2_0 PS_VerBlur(); 
    11     } 
    12
     

    And here is one of my blur pixel units:

    1 // horizontal blur 
    2 void PS_HorBlur( in VertexToPixel IN, out PixelToScreen OUT ) 
    3
    4     OUT.color = 0; 
    5     for (int i=0; i<8; i++) 
    6     { 
    7          
    8         float4 posColor = tex2D(texSampler, IN.textCoord + float2(pos[i], 0) * blurSize); 
    9         float4 negColor = tex2D(texSampler, IN.textCoord - float2(pos[i], 0) * blurSize); 
    10          
    11         OUT.color += (posColor + negColor)*weights[i]; 
    12     } 
    13
     

     The problem is in line 4 of the second code snipped. If I run it without this line I get an error:

    Error    1    Errors compiling C:\...\Content\effects\postProcessingEffects.fx:
    (107): error X4000: variable 'OUT' used without having been completely initialized
    (188): ID3DXEffectCompiler::CompileEffect: There was an error compiling expression
    ID3DXEffectCompiler: Compilation failed 

     

     For the seond pass I need the color value from the frame buffer. How can I access it?

     

  • 09-04-2008 6:52 PM In reply to

    Re: How can I access a color from the back buffer? (Blur Effect)

    You cannot read the value from the framebuffer. You have to draw to a rendertarget in your first pass, then read from that rendertarget in your second pass. Check out the Bloom sample (on this site) for an example.
    XNA Framework Developer - blog - homepage
  • 09-06-2008 1:21 PM In reply to

    Re: How can I access a color from the back buffer? (Blur Effect)

    Thanks, it works now.

    I had a look at the Bloom sample and I know how it's going but I still have a problem with my program.

    Details:

    1. Filter start image (darker parts become darker or black; brighter parts become brighter)
    2. Blur image (horizontal+vertical)
    3. Blend the original image (without applied effects) and the blurred image together

    My idea for a bloom effect was to filter the start image as follows:

    1 void PS_brightnessFilter( in VertexToPixel IN, out PixelToScreen OUT ) 
    2
    3     float4 color = tex2D(texSampler, IN.textCoord);  
    4     float sum = color.r + color.g + color.b; 
    5      
    6     if (sum < glowValue)  // glowValue could be 1.5 or so
    7     { 
    8         OUT.color = saturate(float4(0.0, 0.0, 0.0, 0.0)); 
    9     } 
    10     else 
    11     { 
    12         OUT.color = color; 
    13     } 
    15
     

    In the sample its done this way:

    1 void PS_brightnessFilter( in VertexToPixel IN, out PixelToScreen OUT ) 
    2
    3     float4 c = tex2D(texSampler, IN.textCoord); 
    4  
    5     OUT.color = saturate((c - glowValue) / (1 - glowValue));       
    6

    But even with this its not really glowing.

    Thanks for help.

Page 1 of 1 (3 items) Previous Next