summary refs log tree commit diff stats
path: root/shaders/bloom1.fragment
blob: cfb27994dd07d79cf0ac693abe00b2224beac2b2 (plain) (blame)
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
#version 330 core

in vec2 UV;

out vec3 color;

uniform sampler2D screenTex;
uniform float iGlobalTime;
uniform vec2 resolution;

float nrand(vec2 n)
{
  return fract(sin(dot(n.xy, vec2(19.9898, 78.233))) * 43758.5453);
}

vec2 rot2d(vec2 p, float a)
{
  vec2 sc = vec2(sin(a), cos(a));
  return vec2(dot(p, vec2(sc.y, -sc.x)), dot(p, sc.xy));
}

void main()
{
  const int NUM_TAPS = 12;
  float max_siz = 15.0;
  
  vec2 fTaps_Poisson[NUM_TAPS];
  fTaps_Poisson[0]  = vec2(-.326, -.406);
  fTaps_Poisson[1]  = vec2(-.840, -.074);
  fTaps_Poisson[2]  = vec2(-.696,  .457);
  fTaps_Poisson[3]  = vec2(-.203,  .621);
  fTaps_Poisson[4]  = vec2( .962, -.195);
  fTaps_Poisson[5]  = vec2( .473, -.480);
  fTaps_Poisson[6]  = vec2( .519,  .767);
  fTaps_Poisson[7]  = vec2( .185, -.893);
  fTaps_Poisson[8]  = vec2( .507,  .064);
  fTaps_Poisson[9]  = vec2( .896,  .412);
  fTaps_Poisson[10] = vec2(-.322, -.933);
  fTaps_Poisson[11] = vec2(-.792, -.598);
  
  vec4 sum = vec4(0);
  float rnd = 6.28 * nrand(UV + fract(iGlobalTime));
  vec4 basis = vec4(rot2d(vec2(1,0), rnd), rot2d(vec2(0,1), rnd));
  for (int i=0; i<NUM_TAPS; i++)
  {
    vec2 ofs = fTaps_Poisson[i];
    ofs = vec2(dot(ofs, basis.xz), dot(ofs, basis.yw));
    
    vec2 texcoord = UV + max_siz * ofs / resolution;
    sum += texture(screenTex, texcoord, -10.0);
  }
  
  color = (sum / vec4(NUM_TAPS)).rgb;
}