Skip to content

Instantly share code, notes, and snippets.

@JCash
Last active January 4, 2024 07:30
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JCash/45e17e3657dab257f8bf995766e8f633 to your computer and use it in GitHub Desktop.
Save JCash/45e17e3657dab257f8bf995766e8f633 to your computer and use it in GitHub Desktop.
Separable box blur in GLSL
#version 410
#ifdef GL_ES
precision mediump float;
#define LOWP lowp
#else
#define LOWP
#endif
uniform sampler2D texture0;
#if __VERSION__ >= 140
in vec2 _texcoords[7];
out vec4 fragcolor;
#else
varying vec2 _texcoords[7];
#endif
void main ()
{
LOWP vec4 color = vec4(0.0);
color += texture(texture0, _texcoords[0]) * 0.08;
color += texture(texture0, _texcoords[1]) * 0.13;
color += texture(texture0, _texcoords[2]) * 0.18;
color += texture(texture0, _texcoords[3]) * 0.22;
color += texture(texture0, _texcoords[4]) * 0.18;
color += texture(texture0, _texcoords[5]) * 0.13;
color += texture(texture0, _texcoords[6]) * 0.08;
fragcolor = color;
}
#version 410
#ifdef GL_ES
precision mediump float;
#endif
#if __VERSION__ >= 140
in vec4 position;
in vec2 texcoord0;
out vec2 _texcoords[7];
#else
attribute vec4 position;
attribute vec2 texcoord0;
varying vec2 _texcoords[7];
#endif
uniform float radius;
uniform vec2 texelsize; // vec2(1,0) for horizontal, vec2(0,1) for vertical
void main()
{
gl_Position = position;
vec2 offset = vec2(texelsize.x, texelsize.y) * radius;
_texcoords[0] = texcoord0 - offset * 3.0;
_texcoords[1] = texcoord0 - offset * 2.0;
_texcoords[2] = texcoord0 - offset * 1.0;
_texcoords[3] = texcoord0;
_texcoords[4] = texcoord0 + offset * 1.0;
_texcoords[5] = texcoord0 + offset * 2.0;
_texcoords[6] = texcoord0 + offset * 3.0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment