-
Notifications
You must be signed in to change notification settings - Fork 0
/
bloom.frag
32 lines (23 loc) · 905 Bytes
/
bloom.frag
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
precision mediump float;
// texcoords from the vertex shader
varying vec2 vTexCoord;
// our textures coming from p5
uniform sampler2D tex0;
uniform sampler2D tex1;
// value between 0 and 1
uniform float bloomAmount;
void main() {
vec2 uv = vTexCoord;
// the texture is loaded upside down and backwards by default so lets flip it
uv = 1.0 - uv;
// get the camera and the blurred image as textures
vec4 cam = texture2D(tex0, uv);
vec4 blur = texture2D(tex1, uv);
// calculate an average color for the blurred image
// this is essentially the same as saying (blur.r + blur.g + blur.b) / 3.0;
float avg = dot(blur.rgb, vec3(0.33333));
// mix the blur and camera together according to how bright the blurred image is
// use the mouse to control the bloom
vec4 bloom = mix(cam, blur, clamp(avg*(1.0 + bloomAmount), 0.0, 1.0));
gl_FragColor = bloom;
}