summary refs log tree commit diff stats
path: root/shaders/bloom1.fragment
diff options
context:
space:
mode:
Diffstat (limited to 'shaders/bloom1.fragment')
-rw-r--r--shaders/bloom1.fragment53
1 files changed, 53 insertions, 0 deletions
diff --git a/shaders/bloom1.fragment b/shaders/bloom1.fragment new file mode 100644 index 0000000..77031f2 --- /dev/null +++ b/shaders/bloom1.fragment
@@ -0,0 +1,53 @@
1#version 330 core
2
3in vec2 UV;
4
5out vec3 color;
6
7uniform sampler2D screenTex;
8uniform float iGlobalTime;
9
10float nrand(vec2 n)
11{
12 return fract(sin(dot(n.xy, vec2(19.9898, 78.233))) * 43758.5453);
13}
14
15vec2 rot2d(vec2 p, float a)
16{
17 vec2 sc = vec2(sin(a), cos(a));
18 return vec2(dot(p, vec2(sc.y, -sc.x)), dot(p, sc.xy));
19}
20
21void main()
22{
23 const int NUM_TAPS = 12;
24 float max_siz = 1.0;
25
26 vec2 fTaps_Poisson[NUM_TAPS];
27 fTaps_Poisson[0] = vec2(-.326, -.406);
28 fTaps_Poisson[1] = vec2(-.840, -.074);
29 fTaps_Poisson[2] = vec2(-.696, .457);
30 fTaps_Poisson[3] = vec2(-.203, .621);
31 fTaps_Poisson[4] = vec2( .962, -.195);
32 fTaps_Poisson[5] = vec2( .473, -.480);
33 fTaps_Poisson[6] = vec2( .519, .767);
34 fTaps_Poisson[7] = vec2( .185, -.893);
35 fTaps_Poisson[8] = vec2( .507, .064);
36 fTaps_Poisson[9] = vec2( .896, .412);
37 fTaps_Poisson[10] = vec2(-.322, -.933);
38 fTaps_Poisson[11] = vec2(-.792, -.598);
39
40 vec4 sum = vec4(0);
41 float rnd = 6.28 * nrand(UV + fract(iGlobalTime));
42 vec4 basis = vec4(rot2d(vec2(1,0), rnd), rot2d(vec2(0,1), rnd));
43 for (int i=0; i<NUM_TAPS; i++)
44 {
45 vec2 ofs = fTaps_Poisson[i];
46 ofs = vec2(dot(ofs, basis.xz), dot(ofs, basis.yw));
47
48 vec2 texcoord = UV + max_siz * ofs / vec2(1024.0,768.0);
49 sum += texture(screenTex, texcoord, -10.0);
50 }
51
52 color = (sum / vec4(NUM_TAPS)).rgb;
53}