1 | -- GLSL.Vert -- |
---|
2 | |
---|
3 | #version 120 |
---|
4 | |
---|
5 | void main() |
---|
6 | { |
---|
7 | gl_Position=gl_Vertex; |
---|
8 | gl_TexCoord[0]=gl_MultiTexCoord0; |
---|
9 | } |
---|
10 | |
---|
11 | -- GLSL.Frag -- |
---|
12 | |
---|
13 | #version 120 |
---|
14 | |
---|
15 | uniform sampler2D texture; |
---|
16 | uniform vec2 screen_size; |
---|
17 | uniform float time; |
---|
18 | uniform float deform; |
---|
19 | uniform vec3 filter; |
---|
20 | uniform vec3 color; |
---|
21 | uniform vec3 retrace; |
---|
22 | uniform vec2 offset; |
---|
23 | uniform float noise; |
---|
24 | uniform float aberration; |
---|
25 | uniform bool moire; |
---|
26 | uniform vec4 moire_h; |
---|
27 | uniform vec4 moire_v; |
---|
28 | uniform bool scanline; |
---|
29 | uniform vec4 scanline_h; |
---|
30 | uniform vec4 scanline_v; |
---|
31 | uniform float flash; |
---|
32 | uniform float sync; |
---|
33 | |
---|
34 | const float PI=3.14159265358979323846; |
---|
35 | |
---|
36 | vec2 zoom(in vec2 p,in float radius) |
---|
37 | { |
---|
38 | float d=deform+sync*0.0625; |
---|
39 | float zoom=1.5-(radius*cos(p.x*d)+radius*cos(p.y*d)); |
---|
40 | return p*zoom-0.5; |
---|
41 | } |
---|
42 | |
---|
43 | vec3 get_color(in sampler2D tex,in vec2 p) |
---|
44 | { |
---|
45 | return texture2D(tex,clamp(p,-1.0,0.0)).xyz; |
---|
46 | } |
---|
47 | |
---|
48 | float rand(in vec2 p) |
---|
49 | { |
---|
50 | return fract(sin(dot(p,vec2(12.9898,78.233)))*43758.5453); |
---|
51 | } |
---|
52 | |
---|
53 | float letterbox(in vec2 p,in float radius,in float smooth) |
---|
54 | { |
---|
55 | return 1.0-smoothstep(smooth,1.0,length(max(abs(p*2.0+1.0)+vec2(radius),0.0))-radius); |
---|
56 | } |
---|
57 | |
---|
58 | void main(void) |
---|
59 | { |
---|
60 | vec2 q=gl_FragCoord.xy/screen_size.xy; |
---|
61 | vec2 p=-1.0+2.0*gl_FragCoord.xy/screen_size.xy; |
---|
62 | p.y+=0.025*sync; |
---|
63 | vec2 z =zoom(p,0.5250); |
---|
64 | vec2 z1=zoom(p,0.5225); |
---|
65 | vec2 z2=zoom(p,0.5275); |
---|
66 | float mask=q.x*(6.0-q.x*6.0)*q.y*(6.0-q.y*6.0); |
---|
67 | |
---|
68 | vec2 rnd=vec2(rand(vec2(p.x+time,p.y-time)),rand(vec2(p.x-time,p.y+time))); |
---|
69 | |
---|
70 | vec2 o=(offset-offset*2.0*rnd.x)/screen_size; // offset |
---|
71 | vec3 source=get_color(texture,z+o); // offset added to source |
---|
72 | vec3 glass1=get_color(texture,z1); |
---|
73 | vec3 glass2=get_color(texture,z2); |
---|
74 | |
---|
75 | float v=aberration/float(screen_size.x)+aberration/float(screen_size.x)*(2.0-mask); |
---|
76 | |
---|
77 | vec3 ca; |
---|
78 | ca.x=get_color(texture,vec2(z.x+o.x-v,z.y+o.y)).x; |
---|
79 | ca.y=get_color(texture,vec2(z.x+o.x ,z.y+o.y)).y; |
---|
80 | ca.z=get_color(texture,vec2(z.x+o.x+v,z.y+o.y)).z; |
---|
81 | |
---|
82 | vec3 c=source+glass1*glass1*0.25+glass2*glass2*0.25; |
---|
83 | |
---|
84 | float a=(c.x+c.y+c.z)/3.0; |
---|
85 | vec3 g=vec3(a,a,a); |
---|
86 | c=mix(c,g,color.z); // gray |
---|
87 | c*=filter; // filter |
---|
88 | c*=color.x; // brightness |
---|
89 | c=0.5+(c-0.5)*color.y; // contrast |
---|
90 | |
---|
91 | c+=flash; // flash |
---|
92 | c+=ca; // chromatic aberration |
---|
93 | c-=retrace.x*mod(z.y*retrace.y+time*retrace.z,1.0); // retrace |
---|
94 | c-=(vec3(rnd.x-rnd.y))*noise; // noise |
---|
95 | if(moire) |
---|
96 | { |
---|
97 | c*=moire_h.x+moire_h.y*sin(z.y*float(screen_size.y*moire_h.z))*sin(0.5+z.x*float(screen_size.x*moire_h.w)); // moire h |
---|
98 | c*=moire_v.x+moire_v.y*sin(z.x*float(screen_size.x*moire_v.z))*sin(0.5+z.y*float(screen_size.y*moire_v.w)); // moire v |
---|
99 | } |
---|
100 | else |
---|
101 | { |
---|
102 | c*=(moire_h.x+moire_v.x)*0.5; |
---|
103 | } |
---|
104 | if(scanline) |
---|
105 | { |
---|
106 | c*=scanline_h.x+scanline_h.y*cos(z.y*float(screen_size.y*scanline_h.z+scanline_h.w)); // scanline h |
---|
107 | c*=scanline_v.x+scanline_v.y*cos(z.x*float(screen_size.x*scanline_v.z+scanline_v.w)); // scanline v |
---|
108 | } |
---|
109 | else |
---|
110 | { |
---|
111 | c*=(scanline_h.x+scanline_v.x)*0.5; |
---|
112 | } |
---|
113 | c*=mask; // vignetting |
---|
114 | c*=letterbox(z,-0.75,0.95); // letnoiseterbox |
---|
115 | gl_FragColor=vec4(c,1.0); |
---|
116 | } |
---|