0

I stored a 1D Gaussian filter in a sampler1D texture and send it to a fragment shader. When doing the vertical and horizontal blur, I use texelFetch() to get the weights in samlper1D map but didn't work. How is the data stored in the sampler1D ?

in vec2 texCoord; 
uniform int BlurFilterWidth; 
uniform sampler1D BlurFilterTex;
uniform sampler2D OriginalImageTex;
uniform sampler2D ThresholdImageTex;
uniform sampler2D HorizBlurImageTex;
uniform sampler2D VertBlurImageTex;

layout (location = 0) out vec4 FragColor;

void HorizBlurImage()
{
   
    ivec2 pix = ivec2(gl_FragCoord.xy);
    int TexSize = textureSize(BlurFilterTex,0);
    vec4 sum = texelFetch(ThresholdImageTex,pix,0) * texelFetch(BlurFilterTex, 0, 0).r;

   
    for( int i = 1; i < BlurFilterWidth; i++){
       sum += texelFetchOffset(ThresholdImageTex, pix, 0, ivec2(i,0)) * texelFetch(BlurFilterTex, i*TexSize, 0).r;
       sum += texelFetchOffset(ThresholdImageTex, pix, 0, ivec2(-i,0)) * texelFetch(BlurFilterTex, i*TexSize, 0).r;

    }
    FragColor = sum;
}
  • see related QAs: [OpenGl blurring](https://stackoverflow.com/a/64845819/2521214) and [Calculating 2D Gaussian filter in Fragment Shader](https://stackoverflow.com/a/65041047/2521214) – Spektre Jul 25 '22 at 08:17

1 Answers1

1

In a GL_TEXTURE_1D the elements are organized in a 1 dimensional array. The texture coordinate is just an integer that address the element in the array. So why do you multiply the index i by TexSize? The texture coordinate is simply i:

texelFetch(BlurFilterTex, i*TexSize, 0).r;

texelFetch(BlurFilterTex, i, 0).r;
Rabbid76
  • 202,892
  • 27
  • 131
  • 174