diff options
author | Kelly Rauchenberger <fefferburbia@gmail.com> | 2015-02-15 15:23:19 -0500 |
---|---|---|
committer | Kelly Rauchenberger <fefferburbia@gmail.com> | 2015-02-15 15:23:19 -0500 |
commit | 783b308990e7c4ef0837a102a138778f73e4d2b7 (patch) | |
tree | 77931fcf919f8c8e7996430994c452376aae293f /shaders/bloom1.fragment | |
parent | 297c093d398e7d6e5fcc5dc6ba1056ede25abf6f (diff) | |
download | therapy-783b308990e7c4ef0837a102a138778f73e4d2b7.tar.gz therapy-783b308990e7c4ef0837a102a138778f73e4d2b7.tar.bz2 therapy-783b308990e7c4ef0837a102a138778f73e4d2b7.zip |
Added bloom!
Diffstat (limited to 'shaders/bloom1.fragment')
-rw-r--r-- | shaders/bloom1.fragment | 53 |
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 | |||
3 | in vec2 UV; | ||
4 | |||
5 | out vec3 color; | ||
6 | |||
7 | uniform sampler2D screenTex; | ||
8 | uniform float iGlobalTime; | ||
9 | |||
10 | float nrand(vec2 n) | ||
11 | { | ||
12 | return fract(sin(dot(n.xy, vec2(19.9898, 78.233))) * 43758.5453); | ||
13 | } | ||
14 | |||
15 | vec2 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 | |||
21 | void 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 | } | ||