SHARE
TWEET

beam4.shader

a guest May 10th, 2011 3,390 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <shader language="GLSL">
  3. <fragment filter="nearest" outscale_x="1.0" outscale_y="1.0"><![CDATA[#version 130
  4. uniform sampler2D     rubyTexture;
  5. uniform vec2 rubyTextureSize;
  6. uniform vec2 rubyInputSize;
  7. uniform vec2 rubyOutputSize;
  8.  
  9. #define CRT_gamma 2.2
  10. #define display_gamma 2.2
  11. #define TEX2D(c) texture2D(rubyTexture,(c))
  12.  
  13. #define risetime 1.1
  14. #define falltime 0.3
  15. #define distortion 0.1
  16. #define offpeakiness 0.1
  17.  
  18. vec2 radialDistortion(vec2 coord) {
  19.  coord *= rubyTextureSize / rubyInputSize;
  20.  vec2 cc = coord - 0.5;
  21.   float dist = dot(cc, cc) * distortion;                               
  22.  return (coord + cc * (1.0 + dist) * dist) * rubyInputSize / rubyTextureSize;
  23. }
  24.  
  25. void main()
  26. {
  27.  vec2 xy = radialDistortion(gl_TexCoord[0].st - vec2(0.0, 0.5/rubyTextureSize.y));
  28.  
  29.  float emu_pos = xy.y * rubyTextureSize.y;
  30.  float screen_pos = emu_pos * rubyOutputSize.y / rubyInputSize.y;
  31.  float line_y = floor(emu_pos) * rubyOutputSize.y / rubyInputSize.y;
  32.  float line_y2 = ceil(emu_pos) * rubyOutputSize.y / rubyInputSize.y;
  33.  float x1 = screen_pos-line_y;
  34.  float x2 = line_y2-screen_pos;
  35.  
  36.  vec2 uv_ratio     = fract(xy*rubyTextureSize-vec2(0.5));
  37.  vec2 one          = 1.0/rubyTextureSize;
  38.  
  39.  xy = (floor(xy * rubyTextureSize - vec2(0.5)) + vec2(0.5)) / rubyTextureSize;
  40.  
  41.  float wrise = risetime*rubyInputSize.x/256.0;
  42.  float wfall = falltime*rubyInputSize.x/256.0;
  43.  
  44.  vec2 onex = vec2(one.x, 0.0);
  45.  
  46.  vec4 ct0= TEX2D(xy);
  47.  vec4 ct1= TEX2D(xy-onex);
  48.  vec4 ct2= TEX2D(xy-2*onex);
  49.  vec4 ct3= TEX2D(xy-3*onex);
  50.  vec4 ct4= TEX2D(xy-4*onex);
  51.  
  52.  vec4 col = ct4;
  53.  bvec4 rising = greaterThan(ct3, ct4);
  54.  col += (ct3 - col) * (1.0-exp(-vec4(1.0)/mix(vec4(wfall),vec4(wrise),rising)));
  55.  rising = greaterThan(ct2, ct3);
  56.  col += (ct2 - col) * (1.0-exp(-vec4(1.0)/mix(vec4(wfall),vec4(wrise),rising)));
  57.  rising = greaterThan(ct1, ct2);
  58.  col += (ct1 - col) * (1.0-exp(-vec4(1.0)/mix(vec4(wfall),vec4(wrise),rising)));
  59.  rising = greaterThan(ct0, ct1);
  60.  col += (ct0 - col) * (1.0-exp(-vec4(uv_ratio.x)/mix(vec4(wfall),vec4(wrise),rising)));
  61.  
  62.  col = pow(col, vec4(CRT_gamma));
  63.  
  64.  if (x1 < 1.0)
  65.    gl_FragColor = pow(col*vec4(offpeakiness/2+(1-offpeakiness)*(1-x1)),vec4(1/display_gamma));
  66.  else if(x2 < 1.0)
  67.    gl_FragColor = pow(col*vec4(offpeakiness/2+(1-offpeakiness)*(1-x2)),vec4(1/display_gamma));
  68.  else
  69.    gl_FragColor = vec4(0.0);
  70. }
  71. ]]></fragment>
  72. <fragment filter="nearest" outscale_x="1.0" outscale_y="1.0"><![CDATA[
  73. uniform sampler2D     rubyTexture;
  74. uniform vec2 rubyTextureSize;
  75. uniform vec2 rubyInputSize;
  76. uniform vec2 rubyOutputSize;
  77.  
  78. #define width 0.3
  79. #define display_gamma 2.2
  80. #define TEX2D(c) pow(texture2D(rubyTexture,(c)),vec4(display_gamma))
  81.  
  82. void main()
  83. {
  84.  vec2 xy = gl_TexCoord[0].st;
  85.  float oney = 1.0/rubyTextureSize.y;
  86.  
  87. //  float wid = width*rubyOutputSize.y/rubyInputSize.y;
  88.  float wid = width*4.0;
  89.  
  90.  float c1 = exp(-1.0/wid/wid);
  91.  float c2 = exp(-4.0/wid/wid);
  92.  float c3 = exp(-9.0/wid/wid);
  93.  float c4 = exp(-16.0/wid/wid);
  94.  //float norm = 1.0 / (1.0 + 2.0*(c1+c2+c3+c4));
  95.  float norm = 0.9;
  96.  
  97.  vec4 sum = vec4(0.0);
  98.  
  99.  sum += TEX2D(xy + vec2(0.0, -4.0 * oney)) * vec4(c4);
  100.  sum += TEX2D(xy + vec2(0.0, -3.0 * oney)) * vec4(c3);
  101.  sum += TEX2D(xy + vec2(0.0, -2.0 * oney)) * vec4(c2);
  102.  sum += TEX2D(xy + vec2(0.0, -1.0 * oney)) * vec4(c1);
  103.  sum += TEX2D(xy);
  104.  sum += TEX2D(xy + vec2(0.0, +1.0 * oney)) * vec4(c1);
  105.  sum += TEX2D(xy + vec2(0.0, +2.0 * oney)) * vec4(c2);
  106.  sum += TEX2D(xy + vec2(0.0, +3.0 * oney)) * vec4(c3);
  107.  sum += TEX2D(xy + vec2(0.0, +4.0 * oney)) * vec4(c4);
  108.  
  109.  gl_FragColor = pow(sum*vec4(norm),vec4(1.0/display_gamma));
  110. }
  111. ]]></fragment>
  112. <fragment filter="nearest" outscale_x="1.0" outscale_y="1.0"><![CDATA[
  113. uniform sampler2D     rubyTexture;
  114. uniform vec2 rubyTextureSize;
  115. uniform vec2 rubyInputSize;
  116. uniform vec2 rubyOutputSize;
  117.  
  118. #define width 0.3
  119. #define display_gamma 2.2
  120. #define TEX2D(c) pow(texture2D(rubyTexture,(c)),vec4(display_gamma))
  121.  
  122. void main()
  123. {
  124.  vec2 xy = gl_TexCoord[0].st;
  125.  float onex = 1.0/rubyTextureSize.x;
  126.  
  127. //  float wid = width*rubyOutputSize.y/rubyInputSize.y;
  128.  float wid = width*4.0;
  129.  
  130.  float c1 = exp(-1.0/wid/wid);
  131.  float c2 = exp(-4.0/wid/wid);
  132.  float c3 = exp(-9.0/wid/wid);
  133.  float c4 = exp(-16.0/wid/wid);
  134.  float norm = 1.0 / (1.0 + 2.0*(c1+c2+c3+c4));
  135.  
  136.  vec4 sum = vec4(0.0);
  137.  
  138.  sum += TEX2D(xy + vec2(-4.0 * onex, 0.0)) * vec4(c4);
  139.  sum += TEX2D(xy + vec2(-3.0 * onex, 0.0)) * vec4(c3);
  140.  sum += TEX2D(xy + vec2(-2.0 * onex, 0.0)) * vec4(c2);
  141.  sum += TEX2D(xy + vec2(-1.0 * onex, 0.0)) * vec4(c1);
  142.  sum += TEX2D(xy);
  143.  sum += TEX2D(xy + vec2(+1.0 * onex, 0.0)) * vec4(c1);
  144.  sum += TEX2D(xy + vec2(+2.0 * onex, 0.0)) * vec4(c2);
  145.  sum += TEX2D(xy + vec2(+3.0 * onex, 0.0)) * vec4(c3);
  146.  sum += TEX2D(xy + vec2(+4.0 * onex, 0.0)) * vec4(c4);
  147.  
  148.  gl_FragColor = pow(sum*vec4(norm),vec4(1.0/display_gamma));
  149. }
  150. ]]></fragment>
  151. </shader>
RAW Paste Data
Challenge yourself this year...
Learn something new in 2017
Top