[1456] | 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 int screen_w; |
---|
| 17 | uniform int screen_h; |
---|
| 18 | uniform float time; |
---|
| 19 | uniform float flash; |
---|
| 20 | uniform float value; |
---|
| 21 | uniform float deform; |
---|
| 22 | uniform bool scanline; |
---|
| 23 | uniform float sync; |
---|
| 24 | |
---|
| 25 | const float PI=3.14159265358979323846; |
---|
| 26 | float lens=PI/(deform+sync*0.0625); |
---|
| 27 | |
---|
| 28 | vec2 zoom(in vec2 p,in float radius) |
---|
| 29 | { |
---|
| 30 | float zoom=1.5-(radius*cos(p.x*PI/lens)+radius*cos(p.y*PI/lens)); |
---|
| 31 | return vec2(p.x*zoom-0.5,p.y*zoom-0.5); |
---|
| 32 | } |
---|
| 33 | |
---|
| 34 | vec3 get_color(in sampler2D tex,in vec2 p) |
---|
| 35 | { |
---|
| 36 | return (p.x<-1.0||p.x>0.0||p.y<-1.0||p.y>0.0)?vec3(0.0,0.0,0.0):texture2D(tex,p).xyz; |
---|
| 37 | } |
---|
| 38 | |
---|
| 39 | float rand(in vec2 p) |
---|
| 40 | { |
---|
| 41 | return fract(sin(dot(p.xy,vec2(12.9898,78.233)))*43758.5453); |
---|
| 42 | } |
---|
| 43 | |
---|
| 44 | void main(void) |
---|
| 45 | { |
---|
| 46 | vec2 q=gl_TexCoord[0].xy; |
---|
| 47 | vec2 p=-1.0+2.0*gl_TexCoord[0].xy; |
---|
| 48 | p.y+=0.025*sync; |
---|
| 49 | vec2 z =zoom(p,0.5250); |
---|
| 50 | vec2 z1=zoom(p,0.5225); |
---|
| 51 | vec2 z2=zoom(p,0.5275); |
---|
| 52 | float g=(2.0-cos(PI/lens/2.0+z.x*PI/lens)-cos(PI/lens/2.0+z.y*PI/lens))*32.0; |
---|
| 53 | |
---|
| 54 | float rnd1=rand(vec2(p.x+time,p.y-time)); |
---|
| 55 | float rnd2=rand(vec2(p.x-time,p.y+time)); |
---|
| 56 | float d1=rnd1*value/float(screen_w); |
---|
| 57 | float d2=rnd2*value/float(screen_h); |
---|
| 58 | |
---|
| 59 | vec3 source;//=get_color(texture,z); |
---|
| 60 | source.x=get_color(texture,vec2(z.x+d1,z.y)).x; |
---|
| 61 | source.y=get_color(texture,vec2(z.x+d1,z.y)).y; |
---|
| 62 | source.z=get_color(texture,vec2(z.x+d1,z.y)).z; |
---|
| 63 | |
---|
| 64 | vec3 glass1=get_color(texture,z1); |
---|
| 65 | vec3 glass2=get_color(texture,z2); |
---|
| 66 | |
---|
| 67 | float v=value/float(screen_w)*g; |
---|
| 68 | |
---|
| 69 | vec3 noise; |
---|
| 70 | noise.x=get_color(texture,vec2(z.x+d1-v,z.y+d2)).x; |
---|
| 71 | noise.y=get_color(texture,vec2(z.x+d1 ,z.y-d2)).y; |
---|
| 72 | noise.z=get_color(texture,vec2(z.x+d1+v,z.y-d2)).z; |
---|
| 73 | |
---|
| 74 | vec3 color=source+glass1*glass1*0.25+glass2*glass2*0.25+(scanline?noise:source); |
---|
| 75 | |
---|
| 76 | color+=flash; // flash |
---|
| 77 | if(scanline) |
---|
| 78 | { |
---|
| 79 | color-=0.0125*mod(z.y*4.0+time*0.25,1.0); // electron beam |
---|
| 80 | color-=(vec3(rnd1,rnd1,rnd1)-vec3(rnd2,rnd2,rnd2))*0.1; // noise |
---|
| 81 | color*=0.75+0.25*sin(z.x*float(screen_w*2)); // scanline w |
---|
| 82 | color*=0.90+0.10*cos(z.y*float(screen_h))*sin(0.5+z.x*float(screen_w)); // scanline h |
---|
| 83 | } |
---|
| 84 | else |
---|
| 85 | { |
---|
| 86 | color*=0.675; |
---|
| 87 | } |
---|
| 88 | color=vec3(color.x*0.875,color.y*1.0,color.z*0.625); |
---|
| 89 | color*=q.x*(6.0-q.x*6.0)*q.y*(6.0-q.y*6.0); // vignetting |
---|
| 90 | gl_FragColor=vec4(color,1.0); |
---|
| 91 | } |
---|