summary refs log tree commit diff stats
path: root/shaders/bloom2.fragment
diff options
context:
space:
mode:
authorKelly Rauchenberger <fefferburbia@gmail.com>2015-02-23 10:49:56 -0500
committerKelly Rauchenberger <fefferburbia@gmail.com>2015-02-23 10:49:56 -0500
commit0751446e1d069263d25abcff49a32a380231709a (patch)
treeaf47582053b30d018c3f1d02e0462aa1eab1b6bb /shaders/bloom2.fragment
parentcecdba5cd996cea3ebd2534aea7a3e3a41205b9c (diff)
downloadtherapy-0751446e1d069263d25abcff49a32a380231709a.tar.gz
therapy-0751446e1d069263d25abcff49a32a380231709a.tar.bz2
therapy-0751446e1d069263d25abcff49a32a380231709a.zip
Rewrote bloom so it's not super slow, also removed the frame from the screen mesh
Diffstat (limited to 'shaders/bloom2.fragment')
-rw-r--r--shaders/bloom2.fragment58
1 files changed, 15 insertions, 43 deletions
diff --git a/shaders/bloom2.fragment b/shaders/bloom2.fragment index 1d9cac4..eca56ea 100644 --- a/shaders/bloom2.fragment +++ b/shaders/bloom2.fragment
@@ -4,58 +4,30 @@ in vec2 UV;
4 4
5out vec3 color; 5out vec3 color;
6 6
7uniform sampler2D screenTex; 7uniform sampler2D clearTex;
8uniform sampler2D downsampledTex; 8uniform sampler2D blurTex;
9uniform float iGlobalTime; 9uniform float iGlobalTime;
10uniform vec2 resolution;
11 10
12float nrand(vec2 n) 11float nrand(vec2 n)
13{ 12{
14 return fract(sin(dot(n.xy, vec2(19.9898, 78.233))) * 43758.5453); 13 return fract(sin(dot(n.xy, vec2(19.9898, 78.233))) * 43758.5453);
15} 14}
16 15
17vec2 rot2d(vec2 p, float a)
18{
19 vec2 sc = vec2(sin(a), cos(a));
20 return vec2(dot(p, vec2(sc.y, -sc.x)), dot(p, sc.xy));
21}
22
23void main() 16void main()
24{ 17{
25 const int NUM_TAPS = 12; 18 color = vec3(0.0);
26 float max_siz = 1.0; 19 //color += texture(tex2, UV).rgb / 2.0;
27 20 color += texture(blurTex, UV).rgb;
28 vec2 fTaps_Poisson[NUM_TAPS]; 21 color = max(vec3(0.0), color - 0.25);
29 fTaps_Poisson[0] = vec2(-.326, -.406); 22 //color *= color;
30 fTaps_Poisson[1] = vec2(-.840, -.074);
31 fTaps_Poisson[2] = vec2(-.696, .457);
32 fTaps_Poisson[3] = vec2(-.203, .621);
33 fTaps_Poisson[4] = vec2( .962, -.195);
34 fTaps_Poisson[5] = vec2( .473, -.480);
35 fTaps_Poisson[6] = vec2( .519, .767);
36 fTaps_Poisson[7] = vec2( .185, -.893);
37 fTaps_Poisson[8] = vec2( .507, .064);
38 fTaps_Poisson[9] = vec2( .896, .412);
39 fTaps_Poisson[10] = vec2(-.322, -.933);
40 fTaps_Poisson[11] = vec2(-.792, -.598);
41
42 vec4 sum = vec4(0);
43 float rnd = 6.28 * nrand(UV + fract(iGlobalTime));
44 vec4 basis = vec4(rot2d(vec2(1,0), rnd), rot2d(vec2(0,1), rnd));
45 for (int i=0; i<NUM_TAPS; i++)
46 {
47 vec2 ofs = fTaps_Poisson[i];
48 ofs = vec2(dot(ofs, basis.xz), dot(ofs, basis.yw));
49
50 vec2 texcoord = UV + max_siz * ofs / (resolution / vec2(16.0));
51 sum += texture(downsampledTex, texcoord, -10.0);
52 }
53 23
54 vec3 bloom_c = (sum / vec4(NUM_TAPS)).rgb; 24 float flicker = 0.5 + nrand(vec2(iGlobalTime));
55 bloom_c *= bloom_c; 25 //flicker *= (flicker);
56 //bloom_c = vec3(bloom_c.r*bloom_c.r, bloom_c.g*bloom_c.g, bloom_c.b*bloom_c.b); 26 flicker = sqrt(flicker);
57 //bloom_c = vec3(bloom_c.r*bloom_c.r, bloom_c.g*bloom_c.g, bloom_c.b*bloom_c.b); 27 //flicker = pow(flicker, 1.0/8.0);
58 //bloom_c = max(bloom_c - 0.25, vec3(0,0,0)); 28 color *= flicker;
29 //color *= mix(vec3(0.0), color, flicker);
59 30
60 color = texture(screenTex, UV).rgb + bloom_c; 31 color += texture(clearTex, UV).rgb;
32 //color = clamp(color, vec3(0.0), vec3(1.0));
61} 33}