1
\$\begingroup\$

I'm having a problem with post processing in my deferred renderer. When I'm applying an effect like bloom on top of my scene, the bottom of the bloom effect texture leaks into the top of my screen, the top of the texture leaks into the bottom of the screen, the left into the right of the screen and so on. Looks like the uv coords don't get clamped correctly, although I thought I'd have set that all correctly.

The bloom effect in this case is created in a lower resolution and the gets upsampled using linear filtering.

This image shows the problem:

problem

I render the postprocessing effects using a simple quad:

glm::vec3(-1.f, -1.f, 0.f),
glm::vec3(1.f, -1.f, 0.f),
glm::vec3(1.f, 1.f, 0.f),
glm::vec3(-1.f, 1.f, 0.f)

This is the vertex shader I use to render the quad:

#version 430 core

layout(location = 0) in vec3 POSITION;

noperspective out vec2 tex_coord;

void main(void)
{
    tex_coord = POSITION.xy * 0.5 + 0.5;

    gl_Position = vec4(POSITION.xy, 0.0, 1.0);
}

And of course in the fragment shader I'm doing something like this:

#version 430 core

uniform sampler2D uTexture;

noperspective in vec2 tex_coord;

out vec4 frag_color;

void main(void)
{
    frag_color = texture(uTexture, tex_coord);
}

The effect got rendered into a frame buffer object which got set up like this:

glGenFramebuffers(1, &_filterFbo);
glBindFramebuffer(GL_FRAMEBUFFER, _filterFbo);

// filter texture
glGenTextures(1, &_filterTexture);
glBindTexture(GL_TEXTURE_2D, _filterTexture);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB16F, _effectWidth, _effectHeight, 0, GL_RGB, GL_FLOAT, NULL);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, _filterTexture, 0);

I really don't know what's the problem here, I hope anyone got an idea.

Thanks in advance

\$\endgroup\$
  • \$\begingroup\$ Is this texture power of 2? \$\endgroup\$ – jgallant Oct 5 '16 at 16:48
1
\$\begingroup\$

You are creating a 2D texture but you are setting clamping to 2D array texture. Replace this:

glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);

with

glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.