aboutsummaryrefslogtreecommitdiff
path: root/system/shaders/convolution-6x6.glsl
blob: 5cb060c78ba925351af26be957aa03d007ebb2ef (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
uniform sampler2D img;
uniform float     stepx;
uniform float     stepy;
uniform sampler2D kernelTex;

vec4 weight(float pos)
{
  return texture2D(kernelTex, vec2(pos, 0.5));
}

vec4 pixel(float xpos, float ypos)
{
  return texture2D(img, vec2(xpos, ypos));
}

vec4 line (float ypos, vec3 xpos1, vec3 xpos2, vec4 linetaps1, vec4 linetaps2)
{
  vec4  pixels;

  pixels  = pixel(xpos1.r, ypos) * linetaps1.r;
  pixels += pixel(xpos1.g, ypos) * linetaps2.r;
  pixels += pixel(xpos1.b, ypos) * linetaps1.g;
  pixels += pixel(xpos2.r, ypos) * linetaps2.g;
  pixels += pixel(xpos2.g, ypos) * linetaps1.b;
  pixels += pixel(xpos2.b, ypos) * linetaps2.b;

  return pixels;
}

void main()
{
  float xf = fract(gl_TexCoord[0].x / stepx);
  float yf = fract(gl_TexCoord[0].y / stepy);

  vec4 linetaps1   = weight((1.0 - xf) / 2.0);
  vec4 linetaps2   = weight((1.0 - xf) / 2.0 + 0.5);
  vec4 columntaps1 = weight((1.0 - yf) / 2.0);
  vec4 columntaps2 = weight((1.0 - yf) / 2.0 + 0.5);

  vec3 xpos1 = vec3(
      (-1.5 - xf) * stepx + gl_TexCoord[0].x,
      (-0.5 - xf) * stepx + gl_TexCoord[0].x,
      ( 0.5 - xf) * stepx + gl_TexCoord[0].x);
  vec3 xpos2 = vec3(
      ( 1.5 - xf) * stepx + gl_TexCoord[0].x,
      ( 2.5 - xf) * stepx + gl_TexCoord[0].x,
      ( 3.5 - xf) * stepx + gl_TexCoord[0].x);

  gl_FragColor  = line((-1.5 - yf) * stepy + gl_TexCoord[0].y, xpos1, xpos2, linetaps1, linetaps2) * columntaps1.r;
  gl_FragColor += line((-0.5 - yf) * stepy + gl_TexCoord[0].y, xpos1, xpos2, linetaps1, linetaps2) * columntaps2.r;
  gl_FragColor += line(( 0.5 - yf) * stepy + gl_TexCoord[0].y, xpos1, xpos2, linetaps1, linetaps2) * columntaps1.g;
  gl_FragColor += line(( 1.5 - yf) * stepy + gl_TexCoord[0].y, xpos1, xpos2, linetaps1, linetaps2) * columntaps2.g;
  gl_FragColor += line(( 2.5 - yf) * stepy + gl_TexCoord[0].y, xpos1, xpos2, linetaps1, linetaps2) * columntaps1.b;
  gl_FragColor += line(( 3.5 - yf) * stepy + gl_TexCoord[0].y, xpos1, xpos2, linetaps1, linetaps2) * columntaps2.b;

  gl_FragColor.a = gl_Color.a;
}