Problems in simple post processing in HLSL

You are an experienced programmer and have a problem with the engine, shaders, or advanced effects? Here you'll get answers.
No questions about C++ programming or topics which are answered in the tutorials!
Post Reply
Tihtinen
Posts: 76
Joined: Fri Jan 08, 2010 3:12 pm
Location: Finland

Problems in simple post processing in HLSL

Post by Tihtinen »

Hi, I've recently tried to create a small post processing system for demo purposes. I'm having a problem that the final image gets more and more blurred the more post processing passes I render.

Here is my vertex shader for the screen quad:

Code: Select all

struct VS_OUTPUT
{
    float4 position : POSITION0;
    float2 texCoord : TEXCOORD0;
};

VS_OUTPUT vertexMain( float4 position : POSITION0, 
                float2 texCoord: TEXCOORD0  )
{
   VS_OUTPUT output;
   output.position = float4(position.x, position.y, 0, 1 );
   output.texCoord = texCoord;
   return output;
}
And here is my "post processing" shader:

Code: Select all

sampler2D sampler0 : register(s0);

float4 pixelMain(float2 TexCoords: TEXCOORD0): COLOR
{
	float4 color = tex2D( sampler0, TexCoords );
	return color;
}
If I render, say, 10 passes of this combination on the screen quad's RTT, it will blur the overall image and oversample at the edges. Does anyone know what this is about? I googled something about the differences in pixel and texel coordinates (pixel's origin is at its center and texel's at its corner), but I was unable to work on any results based on this information.

I would be really thankful if someone sees some noob mistake in my shaders :)
Mel
Competition winner
Posts: 2292
Joined: Wed May 07, 2008 11:40 am
Location: Granada, Spain

Post by Mel »

Have you added a small shift to the screenquad mapping coordinates? it is necesary to sample exactly the middle of the pixel, Sampling without the shift will lead to filtered samples, which will blur the final result, and adding passes will only make things worse.

You have to add a 0.5/screenresolution.Width to the U mapping coordinates and a 0.5/screenresolution.Height to the V mapping coordinates in the screenquad definition. That should do it.

Watch this example.

http://irrlicht.sourceforge.net/phpBB2/ ... hp?t=39022

See how the screenquad is defined.
"There is nothing truly useless, it always serves as a bad example". Arthur A. Schmitt
Tihtinen
Posts: 76
Joined: Fri Jan 08, 2010 3:12 pm
Location: Finland

Post by Tihtinen »

Yeah, thanks I got it. Actually I had tried this before, but managed to screw up setting the uniform variables for screen size :D

But anyway, thanks a lot :) At least you confirmed that this was the issue. Now I can continue on my work.
Post Reply