diff options
Diffstat (limited to 'shaders/bloom2.fragment')
-rw-r--r-- | shaders/bloom2.fragment | 58 |
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 | ||
5 | out vec3 color; | 5 | out vec3 color; |
6 | 6 | ||
7 | uniform sampler2D screenTex; | 7 | uniform sampler2D clearTex; |
8 | uniform sampler2D downsampledTex; | 8 | uniform sampler2D blurTex; |
9 | uniform float iGlobalTime; | 9 | uniform float iGlobalTime; |
10 | uniform vec2 resolution; | ||
11 | 10 | ||
12 | float nrand(vec2 n) | 11 | float 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 | ||
17 | vec2 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 | |||
23 | void main() | 16 | void 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 | } |