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?