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