]> git.tdb.fi Git - libs/demoscene.git/blob - data/vignette.glsl
Add a vignette postprocessor
[libs/demoscene.git] / data / vignette.glsl
1 import postprocess;
2
3 uniform Vignette
4 {
5         vec2 coord_scale;
6         vec4 optical;
7         vec2 optical_range;
8         float natural;
9 };
10
11 #pragma MSP stage(fragment)
12 void main()
13 {
14         vec4 incoming = texture(source, texcoord);
15         vec2 r = vertex.xy*coord_scale;
16         float r_sq = dot(r, r);
17
18         float vignette = 1.0;
19         if(r_sq>=optical_range.y)
20                 vignette = 0.0;
21         else if(r_sq>=optical_range.x)
22         {
23                 float r = sqrt(r_sq)-optical.x;
24                 float v = (optical.z*acos(r/optical.y)-sqrt(optical.z-r*r)*r);
25                 vignette = v/optical.w;
26         }
27
28         float c_sq = 1/(1+r_sq*natural);
29         vignette *= c_sq*c_sq;
30
31         frag_color = vec4(incoming.rgb*vignette, incoming.a);
32 }