You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

113 regels
3.8 KiB

  1. [vert.glsl]
  2. #version 120
  3. attribute vec4 in_Position;
  4. void main()
  5. {
  6. gl_Position = in_Position;
  7. }
  8. [frag.glsl]
  9. #version 120
  10. uniform sampler2D texture;
  11. uniform vec2 screen_size;
  12. uniform vec2 ratio_2d;
  13. uniform float time;
  14. uniform vec2 deform;
  15. uniform vec4 ghost1;
  16. uniform vec4 ghost2;
  17. uniform vec4 glass;
  18. uniform vec3 gradient;
  19. uniform vec3 gradient_color;
  20. uniform float vignetting;
  21. uniform float aberration;
  22. uniform vec4 moire_h;
  23. uniform vec4 moire_v;
  24. uniform vec4 scanline_h;
  25. uniform vec4 scanline_v;
  26. uniform vec3 corner;
  27. uniform float sync;
  28. uniform float beat;
  29. const float PI=3.14159265358979323846;
  30. vec2 angle=screen_size*PI;
  31. vec2 screen(in vec2 p,in float bend,in float radius)
  32. {
  33. float d=bend+sync*0.0625+beat*0.0375;
  34. return p*(1.5-(radius*cos(p.x*d)+radius*cos(p.y*d)))-0.5;
  35. }
  36. vec3 get_color(in sampler2D tex,in vec2 p)
  37. {
  38. return texture2D(tex,clamp(p,-1.0,0.0)).xyz;
  39. }
  40. float letterbox(in vec2 p,in float w,in float radius,in float smooth)
  41. {
  42. return 1.0-smoothstep(smooth,1.0,length(max(abs(p*w+w/2.0)-vec2(radius),0.0))+radius);
  43. }
  44. void main(void)
  45. {
  46. vec2 q=gl_FragCoord.xy/screen_size.xy;
  47. vec2 p=-1.0+2.0*gl_FragCoord.xy/screen_size.xy;
  48. p.y+=0.025*sync;
  49. vec2 z=screen(p,deform.x,deform.y);
  50. vec2 z1=screen(p,deform.x,deform.y+ghost1.z);
  51. vec2 z2=screen(p,deform.x,deform.y+ghost2.z);
  52. vec2 z3=screen(p,glass.w,deform.y+glass.x-glass.y);
  53. vec2 z4=screen(p,glass.w,deform.y+glass.x+glass.y);
  54. float mask=q.x*(6.0-q.x*6.0)*q.y*(6.0-q.y*6.0);
  55. vec3 source=get_color(texture,z);
  56. vec3 g1=get_color(texture,z1-ghost1.xy);
  57. vec3 g2=get_color(texture,z2-ghost2.xy);
  58. vec3 g3=get_color(texture,z3);
  59. vec3 g4=get_color(texture,z4);
  60. vec3 c=source+g1*ghost1.w+g2*ghost2.w; // mix
  61. float v=aberration/float(screen_size.x/ratio_2d.x); //+aberration/float(screen_size.x)*(2.0-mask);
  62. vec3 ca1=get_color(texture,vec2(z.x-v,z.y));
  63. vec3 ca2=get_color(texture,vec2(z.x+v,z.y));
  64. c+=vec3(ca1.x,c.y,ca2.z); // chromatic aberration
  65. vec3 c1=vec3(gradient_color.x,gradient_color.y,gradient_color.z);
  66. vec3 c2=vec3(gradient_color.x,gradient_color.y,gradient_color.z)/4;
  67. vec3 c3=vec3(1.0,1.0,1.0);
  68. vec3 c4=vec3(gradient_color.z,gradient_color.y,gradient_color.x);
  69. vec3 c5=vec3(gradient_color.z,gradient_color.y,gradient_color.x)/4;
  70. vec3 r;
  71. float r_p=gradient.x;
  72. float r_h=gradient.y;
  73. float r_h2=gradient.y/2;
  74. float k=z.y+1.0;
  75. if (k <= r_p - r_h2)
  76. r = mix(c1,c2,k*(1/(r_p-r_h2)));
  77. else if (k <= r_p)
  78. r = mix(c2,c3,(k-(r_p-r_h2))*(1/r_h2));
  79. else if (k < r_p + r_h)
  80. r = mix(c3,c4,(k-r_p)*(1/r_h));
  81. else
  82. r = mix(c4,c5,k*((k-(r_p+r_h))/(r_p-r_h)));
  83. //c*=moire_h.x+moire_h.y*sin(z.y*float(screen_size.y*moire_h.z)/ratio_2d.y)*sin(0.5+z.x*float(screen_size.x*moire_h.w)/ratio_2d.x); // moire h
  84. //c*=moire_v.x+moire_v.y*sin(z.x*float(screen_size.x*moire_v.z)/ratio_2d.x)*sin(0.5+z.y*float(screen_size.y*moire_v.w)/ratio_2d.y); // moire v
  85. c*=moire_h.x+moire_h.y*sin(z.y*float(angle.y*moire_h.z)/ratio_2d.y)*sin(PI+z.x*float(screen_size.x*moire_h.w)/ratio_2d.x); // moire h
  86. c*=moire_v.x+moire_v.y*sin(z.x*float(angle.x*moire_v.z)/ratio_2d.x)*sin(PI+z.y*float(screen_size.y*moire_v.w)/ratio_2d.y); // moire v
  87. c*=scanline_h.x+scanline_h.y*cos(z.y*float(angle.y*scanline_h.z+scanline_h.w)/ratio_2d.y); // scanline h
  88. c*=scanline_v.x+scanline_v.y*cos(z.x*float(angle.x*scanline_v.z+scanline_v.w)/ratio_2d.x); // scanline v
  89. c+=r*gradient.z; // gradient
  90. c*=mix(1.0,mask,vignetting); // vignetting
  91. c*=letterbox(z,corner.x+2.0,corner.y,corner.z); // corner
  92. c+=(g3+g4)*glass.z; // glass
  93. gl_FragColor=vec4(c,1.0);
  94. }