-
Notifications
You must be signed in to change notification settings - Fork 2
/
lens_distortion.glsl
58 lines (46 loc) · 1.24 KB
/
lens_distortion.glsl
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
/* Lens Distortion - Bola extrema
https://www.shadertoy.com/view/3tXczj
*/
#pragma shaderfilter set size__description Size
#pragma shaderfilter set size__step 0.01
#pragma shaderfilter set size__default 1.0
#pragma shaderfilter set size__min 0.0
#pragma shaderfilter set size__max 2.0
#pragma shaderfilter set size__slider true
uniform float size;
#define DARK_EDGES
#define TRANSPARENT 1
float4 render(vec2 uv )
{
vec2 disorsion = uv - 0.5;
float aspect = 16.0 / 9.0; //builtin_uv_size.x/builtin_uv_size.y;
disorsion[0] *= aspect; // aspect correction
// take distance from center
float len = length(disorsion);
// these are the lens parameters
float k1 = 1.2;
float k2 = 1.0;
float k3 = -3.2;
disorsion
= disorsion*k1
+ disorsion*len*k2
+ disorsion*len*len*k3;
// higher powers may be added if necessary
// aspect correction
disorsion[0] /= aspect;
vec4 col = texture(image, disorsion + 0.5);
#ifdef DARK_EDGES
{
float edge = 0.7;
float dispersion = 0.03;
float transp = pow(max(edge-len, 0.0), 0.05);
// transp = 1; // Para negro
col *= vec4(
pow(max(edge-len, 0.0), 0.2),
pow(max(edge-dispersion-len, 0.0), 0.2),
pow(max(edge-dispersion*2.0-len, 0.0), 0.2),
transp )*1.2;
}
#endif
return col;
}