-
Notifications
You must be signed in to change notification settings - Fork 128
/
chromatic-aberration-fs.glsl
executable file
·52 lines (42 loc) · 1.07 KB
/
chromatic-aberration-fs.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
uniform sampler2D tInput;
uniform vec2 resolution;
vec2 barrelDistortion(vec2 coord, float amt) {
vec2 cc = coord - 0.5;
float dist = dot(cc, cc);
return coord + cc * dist * amt;
}
float sat( float t )
{
return clamp( t, 0.0, 1.0 );
}
float linterp( float t ) {
return sat( 1.0 - abs( 2.0*t - 1.0 ) );
}
float remap( float t, float a, float b ) {
return sat( (t - a) / (b - a) );
}
vec4 spectrum_offset( float t ) {
vec4 ret;
float lo = step(t,0.5);
float hi = 1.0-lo;
float w = linterp( remap( t, 1.0/6.0, 5.0/6.0 ) );
ret = vec4(lo,1.0,hi, 1.) * vec4(1.0-w, w, 1.0-w, 1.);
return pow( ret, vec4(1.0/2.2) );
}
const float max_distort = 2.2;
const int num_iter = 12;
const float reci_num_iter_f = 1.0 / float(num_iter);
void main()
{
vec2 uv=(gl_FragCoord.xy/resolution.xy*.5)+.25;
vec4 sumcol = vec4(0.0);
vec4 sumw = vec4(0.0);
for ( int i=0; i<num_iter;++i )
{
float t = float(i) * reci_num_iter_f;
vec4 w = spectrum_offset( t );
sumw += w;
sumcol += w * texture2D( tInput, barrelDistortion(uv, .6 * max_distort*t ) );
}
gl_FragColor = sumcol / sumw;
}