diff options
Diffstat (limited to 'shaders/bloom1.fragment')
-rw-r--r-- | shaders/bloom1.fragment | 50 |
1 files changed, 6 insertions, 44 deletions
diff --git a/shaders/bloom1.fragment b/shaders/bloom1.fragment index cfb2799..0a89ea1 100644 --- a/shaders/bloom1.fragment +++ b/shaders/bloom1.fragment | |||
@@ -4,51 +4,13 @@ in vec2 UV; | |||
4 | 4 | ||
5 | out vec3 color; | 5 | out vec3 color; |
6 | 6 | ||
7 | uniform sampler2D screenTex; | 7 | uniform vec2 offset; |
8 | uniform float iGlobalTime; | 8 | uniform sampler2D inTex; |
9 | uniform vec2 resolution; | ||
10 | |||
11 | float nrand(vec2 n) | ||
12 | { | ||
13 | return fract(sin(dot(n.xy, vec2(19.9898, 78.233))) * 43758.5453); | ||
14 | } | ||
15 | |||
16 | vec2 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 | 9 | ||
22 | void main() | 10 | void main() |
23 | { | 11 | { |
24 | const int NUM_TAPS = 12; | 12 | color = vec3(0.0); |
25 | float max_siz = 15.0; | 13 | color += (5.0/16.0) * texture(inTex, UV - offset).rgb; |
26 | 14 | color += (6.0/16.0) * texture(inTex, UV).rgb; | |
27 | vec2 fTaps_Poisson[NUM_TAPS]; | 15 | color += (5.0/16.0) * texture(inTex, UV + offset).rgb; |
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 / resolution; | ||
50 | sum += texture(screenTex, texcoord, -10.0); | ||
51 | } | ||
52 | |||
53 | color = (sum / vec4(NUM_TAPS)).rgb; | ||
54 | } | 16 | } |