-
Notifications
You must be signed in to change notification settings - Fork 411
/
Copy pathvignette.js
29 lines (27 loc) · 905 Bytes
/
vignette.js
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
/**
* @filter Vignette
* @description Adds a simulated lens edge darkening effect.
* @param size 0 to 1 (0 for center of frame, 1 for edge of frame)
* @param amount 0 to 1 (0 for no effect, 1 for maximum lens darkening)
*/
function vignette(size, amount) {
gl.vignette = gl.vignette || new Shader(null, '\
uniform sampler2D texture;\
uniform float size;\
uniform float amount;\
varying vec2 texCoord;\
void main() {\
vec4 color = texture2D(texture, texCoord);\
\
float dist = distance(texCoord, vec2(0.5, 0.5));\
color.rgb *= smoothstep(0.8, size * 0.799, dist * (amount + size));\
\
gl_FragColor = color;\
}\
');
simpleShader.call(this, gl.vignette, {
size: clamp(0, size, 1),
amount: clamp(0, amount, 1)
});
return this;
}