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 vec2 deform; |
---|
19 | uniform vec4 ghost1; |
---|
20 | uniform vec4 ghost2; |
---|
21 | uniform vec3 filter; |
---|
22 | uniform vec3 color; |
---|
23 | uniform vec3 retrace; |
---|
24 | uniform vec2 offset; |
---|
25 | uniform float noise; |
---|
26 | uniform float aberration; |
---|
27 | uniform vec4 moire_h; |
---|
28 | uniform vec4 moire_v; |
---|
29 | uniform vec4 scanline_h; |
---|
30 | uniform vec4 scanline_v; |
---|
31 | uniform vec2 corner; |
---|
32 | uniform float vignetting; |
---|
33 | uniform float flash; |
---|
34 | uniform float sync; |
---|
35 | |
---|
36 | const float PI=3.14159265358979323846; |
---|
37 | |
---|
38 | vec2 screen(in vec2 p,in float radius) |
---|
39 | { |
---|
40 | float d=deform.x+sync*0.0625; |
---|
41 | return p*(1.5-(radius*cos(p.x*d)+radius*cos(p.y*d)))-0.5; |
---|
42 | } |
---|
43 | |
---|
44 | vec3 get_color(in sampler2D tex,in vec2 p) |
---|
45 | { |
---|
46 | return texture2D(tex,clamp(p,-1.0,0.0)).xyz; |
---|
47 | } |
---|
48 | |
---|
49 | float rand(in vec2 p) |
---|
50 | { |
---|
51 | return fract(sin(dot(p,vec2(12.9898,78.233)))*43758.5453); |
---|
52 | } |
---|
53 | |
---|
54 | float letterbox(in vec2 p,in float radius,in float smooth) |
---|
55 | { |
---|
56 | return 1.0-smoothstep(smooth,1.0,length(max(abs(p*2.0+1.0)-vec2(radius),0.0))+radius); |
---|
57 | } |
---|
58 | |
---|
59 | void main(void) |
---|
60 | { |
---|
61 | vec2 q=gl_FragCoord.xy/screen_size.xy; |
---|
62 | vec2 p=-1.0+2.0*gl_FragCoord.xy/screen_size.xy; |
---|
63 | p.y+=0.025*sync; |
---|
64 | vec2 z =screen(p,deform.y); |
---|
65 | vec2 z1=screen(p,deform.y+ghost1.z*0.01); |
---|
66 | vec2 z2=screen(p,deform.y+ghost2.z*0.01); |
---|
67 | float mask=q.x*(6.0-q.x*6.0)*q.y*(6.0-q.y*6.0); |
---|
68 | |
---|
69 | vec2 rnd=vec2(rand(vec2(p.x+time,p.y-time)),rand(vec2(p.x-time,p.y+time))); |
---|
70 | |
---|
71 | vec2 o=(offset-offset*2.0*rnd.x)/screen_size; // offset |
---|
72 | vec3 source=get_color(texture,z+o); // offset added to source |
---|
73 | vec3 g1=get_color(texture,z1-ghost1.xy); |
---|
74 | vec3 g2=get_color(texture,z2-ghost2.xy); |
---|
75 | |
---|
76 | float v=aberration/float(screen_size.x)+aberration/float(screen_size.x)*(2.0-mask); |
---|
77 | |
---|
78 | vec3 ca; |
---|
79 | ca.x=get_color(texture,vec2(z.x+o.x-v,z.y+o.y)).x; |
---|
80 | ca.y=get_color(texture,vec2(z.x+o.x ,z.y+o.y)).y; |
---|
81 | ca.z=get_color(texture,vec2(z.x+o.x+v,z.y+o.y)).z; |
---|
82 | |
---|
83 | vec3 c=source+g1*g1*ghost1.w+g2*g2*ghost2.w; // mix |
---|
84 | |
---|
85 | float a=(c.x+c.y+c.z)/3.0; |
---|
86 | vec3 g=vec3(a,a,a); |
---|
87 | c=mix(c,g,color.z); // gray |
---|
88 | c*=filter; // filter |
---|
89 | c*=color.x; // brightness |
---|
90 | c=0.5+(c-0.5)*color.y; // contrast |
---|
91 | |
---|
92 | c+=flash; // flash |
---|
93 | c+=ca; // chromatic aberration |
---|
94 | c-=retrace.x*mod(z.y*retrace.y+time*retrace.z,1.0); // retrace |
---|
95 | c-=(vec3(rnd.x-rnd.y))*noise; // noise |
---|
96 | 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 |
---|
97 | 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 |
---|
98 | c*=scanline_h.x+scanline_h.y*cos(z.y*float(screen_size.y*scanline_h.z+scanline_h.w)); // scanline h |
---|
99 | c*=scanline_v.x+scanline_v.y*cos(z.x*float(screen_size.x*scanline_v.z+scanline_v.w)); // scanline v |
---|
100 | c*=(mask-vignetting); // vignetting |
---|
101 | c*=letterbox(z,corner.x,corner.y); // letterbox |
---|
102 | gl_FragColor=vec4(c,1.0); |
---|
103 | } |
---|