source: trunk/tools/neercs/video/postfx.lolfx @ 1806

Last change on this file since 1806 was 1806, checked in by rez, 11 years ago

moved noise/offset/retrace into a new shader

File size: 2.4 KB
Line 
1-- GLSL.Vert --
2
3#version 120
4
5void main()
6        {
7        gl_Position=gl_Vertex;
8        gl_TexCoord[0]=gl_MultiTexCoord0;
9        }
10
11-- GLSL.Frag --
12
13#version 120
14
15uniform sampler2D texture;
16uniform vec2 screen_size;
17uniform float time;
18uniform vec2 deform;
19uniform vec4 ghost1;
20uniform vec4 ghost2;
21uniform vec3 filter;
22uniform vec3 color;
23uniform float aberration;
24uniform vec4 moire_h;
25uniform vec4 moire_v;
26uniform vec4 scanline_h;
27uniform vec4 scanline_v;
28uniform vec2 corner;
29uniform float vignetting;
30uniform float flash;
31uniform float sync;
32
33vec2 screen(in vec2 p,in float radius)
34        {
35        float d=deform.x+sync*0.0625;
36        return p*(1.5-(radius*cos(p.x*d)+radius*cos(p.y*d)))-0.5;
37        }
38
39vec3 get_color(in sampler2D tex,in vec2 p)
40        {
41        return texture2D(tex,clamp(p,-1.0,0.0)).xyz;
42        }
43
44float letterbox(in vec2 p,in float radius,in float smooth)
45        {
46        return 1.0-smoothstep(smooth,1.0,length(max(abs(p*2.0+1.0)-vec2(radius),0.0))+radius);
47        }
48
49void main(void)
50        {
51        vec2 q=gl_FragCoord.xy/screen_size.xy;
52        vec2 p=-1.0+2.0*gl_FragCoord.xy/screen_size.xy;
53        p.y+=0.025*sync;
54        vec2 z =screen(p,deform.y);
55        vec2 z1=screen(p,deform.y+ghost1.z*0.01);
56        vec2 z2=screen(p,deform.y+ghost2.z*0.01);
57        float mask=q.x*(6.0-q.x*6.0)*q.y*(6.0-q.y*6.0);
58
59        vec3 source=get_color(texture,z);
60        vec3 g1=get_color(texture,z1-ghost1.xy);
61        vec3 g2=get_color(texture,z2-ghost2.xy);
62
63        float v=aberration/float(screen_size.x)+aberration/float(screen_size.x)*(2.0-mask);
64
65        vec3 ca;
66        ca.x=get_color(texture,vec2(z.x-v,z.y)).x;
67        ca.y=get_color(texture,vec2(z.x  ,z.y)).y;
68        ca.z=get_color(texture,vec2(z.x+v,z.y)).z;
69
70        vec3 c=source+g1*g1*ghost1.w+g2*g2*ghost2.w;                    // mix
71
72        float a=(c.x+c.y+c.z)/3.0;
73        vec3 g=vec3(a,a,a);
74        c=mix(c,g,color.z);                                                                             // gray
75        c*=filter;                                                                                              // filter
76        c*=color.x;                                                                                             // brightness
77        c=0.5+(c-0.5)*color.y;                                                                  // contrast
78
79        c+=flash;                                                                                               // flash
80        c+=ca;                                                                                                  // chromatic aberration
81        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
82        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
83        c*=scanline_h.x+scanline_h.y*cos(z.y*float(screen_size.y*scanline_h.z+scanline_h.w));   // scanline h
84        c*=scanline_v.x+scanline_v.y*cos(z.x*float(screen_size.x*scanline_v.z+scanline_v.w));   // scanline v
85        c*=(mask-vignetting);                                                                   // vignetting
86        c*=letterbox(z,corner.x,corner.y);                                              // letterbox
87        gl_FragColor=vec4(c,1.0);
88        }
Note: See TracBrowser for help on using the repository browser.