4

I have been having some issues with sampling a texture and sampling outside the bounds of the texture. I have set the texture to GL_CLAMP_TO_EDGE for wrapping, so when the texture goes out of bounds it clamps to the edge:

glBindTexture(GL_TEXTURE_2D, m_color_tex);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);

In my shader I am trying to implement DoF effects, the problem I was facing was seeing lots of small squares, so I started experimenting. I am using a deferred rendering method so for these effects I draw a fullscreen quad, inside my shader file is the following:

#version 330

uniform sampler2D color_texture;

uniform vec2 Resolution;

out vec4 fragment_colour;

void main(void)
{
    vec2 inverseVP = vec2(1.0 / Resolution.x, 1.0 / Resolution.y);
    vec2 coord = gl_FragCoord.xy * inverseVP;
    vec4 texel_color = texture(color_texture, coord + (vec2(0.0, 0.1)));

    fragment_colour = texel_color;
}

The color_texture is the accumulation of all my drawing generated from my FBO. In the shader I am just offsetting the pixel to read by 10% of the texture size. However when I try this, I get the following result:

In the image you see lots of small squares, I am at a loss as to why they are appearing, if I have no offset the scene is rendered normally. It seems that pixels not near the edge of the texture are affected, but they should not be.

Does anyone know the issue here?

Nico Schertler
  • 32,049
  • 4
  • 39
  • 70
Killermud
  • 59
  • 1
  • 5
    I'm not sure, but this looks like it _may_ be a texture feedback loop. Do you render into the same texture you are sampling from? This would also explain why it only appears when the offset is applied, because without that offset, you might hit a special case where that is guaranteed to work. – derhass Apr 27 '15 at 18:49
  • Also what are the dimensions you are rendering? I got sometimes accuracy problems while combining render passes because of different interpolators results for the same area in separate passes see [ray and ellipsoid intersection accuracy improvement](http://stackoverflow.com/q/25470493/2521214) the last image with the earth globes. It could be related ... – Spektre Nov 05 '15 at 09:17

0 Answers0