Sign in to follow this  

GLSL Blur/Glow artifacts

This topic is 3314 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello everyone, I am trying to implement a simple glow as in the following programs in GLSL: Vertex:
varying vec2 texCoord;

void main()                    
{
   vec2 inPos    = sign(gl_Vertex.xy);
   gl_Position = vec4(inPos.xy, 0.0, 1.0);
   texCoord.x  = 0.5 * ( 1.0 + inPos.x );
   texCoord.y  = 0.5 * ( 1.0 + inPos.y );
}
Fragment:
uniform sampler2D glowTexture;
varying vec2      texCoord;

vec2 offsets[12] = vec2[](
		vec2( -0.326212, -0.405805 ),
		vec2( -0.840144, -0.073580 ),
		vec2( -0.695914,  0.457137 ),
		vec2( -0.203345,  0.620716 ),
		vec2(  0.962340, -0.194983 ),
	    vec2(  0.473434, -0.480026 ),
		vec2(  0.519456,  0.767022 ),
		vec2(  0.185461, -0.893124 ),
		vec2(  0.507431,  0.064425 ),
		vec2(  0.896420,  0.412458 ),
		vec2( -0.321940, -0.932615 ),
		vec2( -0.791559, -0.597705 ) );

const float BlurScale = 0.01;

void main()
{
   vec4 sum = texture2D(glowTexture, texCoord);
   
   int i = 0;
   for( i = 0; i < 12; i++ )
   {
      sum += texture2D( glowTexture, texCoord + BlurScale * offsets[i] );
    }
   gl_FragColor = sum / 10.0;
}

Everything works fine except I get the couple line of pixels on the left colored similar to sun. I'm not quite sure why that occurs as also I am not sure why in the original DX implementation (RenderMonkey), the texture coordinates were generated using: texCoord.x = 0.5 * ( 1.0 + inPos.x ); texCoord.y = 0.5 * ( 1.0 - inPos.y ); This gives me a vertically mirrored image as the y coordinate is multiplied by negative. Can someone help me out on this? Thanks. [Edited by - Dynx on November 17, 2008 9:08:53 AM]

Share this post


Link to post
Share on other sites
The problem was with texture wrapping. When using box filter for blurring, the texture coordinates that are beyond texture limits repeat over the other side therefore for the RTT texture, do:

glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);

Share this post


Link to post
Share on other sites

This topic is 3314 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this