Pastebin launched a little side project called VERYVIRAL.com, check it out ;-) Want more features on Pastebin? Sign Up, it's FREE!
Guest

Untitled

By: a guest on Oct 10th, 2011  |  syntax: None  |  size: 3.48 KB  |  views: 259  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. Texture1D tex : WAVEFORMDATA;
  2.  
  3. SamplerState sTex
  4. {
  5.     Filter = MIN_MAG_MIP_LINEAR;
  6.     AddressU = Clamp;
  7. };
  8.  
  9. struct VS_IN
  10. {
  11.         float2 pos : POSITION;
  12.         float2 tc : TEXCOORD0;
  13. };
  14.  
  15. struct PS_IN
  16. {
  17.         float4 pos : SV_POSITION;
  18.         float2 tc : TEXCOORD0;
  19. };
  20.  
  21.  
  22. float4 backgroundColor : BACKGROUNDCOLOR;
  23. float4 highlightColor  : HIGHLIGHTCOLOR;
  24. float4 selectionColor  : SELECTIONCOLOR;
  25. float4 textColor       : TEXTCOLOR;
  26. float cursorPos        : CURSORPOSITION;
  27. bool cursorVisible     : CURSORVISIBLE;
  28. float seekPos          : SEEKPOSITION;
  29. bool seeking           : SEEKING;
  30. float4 replayGain      : REPLAYGAIN; // album gain, track gain, album peak, track peak
  31. float2 viewportSize    : VIEWPORTSIZE;
  32. bool horizontal        : ORIENTATION;
  33. bool shade_played      : SHADEPLAYED;
  34.  
  35. PS_IN VS( VS_IN input )
  36. {
  37.         PS_IN output = (PS_IN)0;
  38.  
  39.         float2 half_pixel = float2(1,-1) / viewportSize;
  40.         output.pos = float4(input.pos - half_pixel, 0, 1);
  41.         if (horizontal)
  42.                 output.tc = float2((input.tc.x + 1.0) / 2.0, input.tc.y);
  43.         else
  44.                 output.tc = float2((-input.tc.y + 1.0) / 2.0, input.tc.x);
  45.  
  46.         return output;
  47. }
  48.  
  49. float4 bar( float pos, float2 tc, float4 fg, float4 bg, float width, bool show )
  50. {
  51.         float dist = abs(pos - tc.x);
  52.         float4 c = (show && dist < width)
  53.                 ? lerp(fg, bg, smoothstep(0, width, dist))
  54.                 : bg;
  55.         return c;
  56. }
  57.  
  58. float4 evaluate(float4 bg, float4 fg, float factor)
  59. {
  60.         return saturate(lerp(bg, fg, factor));
  61. }
  62.  
  63. float4 played( float pos, float2 tc, float4 bg, float factor)
  64. {
  65.         float4 c = bg;
  66.         if (pos > tc.x)
  67.         {
  68.                 if (shade_played)
  69.                         c = evaluate(backgroundColor, highlightColor, factor);
  70.                 else
  71.                         c = evaluate(highlightColor, textColor, factor);
  72.         }
  73.         return c;
  74. }
  75.  
  76. float RMSfactor( float2 tc, float border )
  77. {
  78.         // alpha 1 indicates biased texture
  79.         float4 minmaxrms = tex.Sample(sTex, tc.x);
  80.         if (replayGain.g != -1000) {
  81.                 minmaxrms.rgb *= pow(10,(replayGain.g) / 20) * 2; //use track gain
  82.         } else if (replayGain.r != -1000) {
  83.                 minmaxrms.rgb *= pow(10,(replayGain.r) / 20) * 2; //use album gain
  84.         }
  85.         minmaxrms.rgb -= 0.5 * minmaxrms.a;
  86.         minmaxrms.rgb *= 1.0 + minmaxrms.a;
  87.  
  88.         float belowWave = tc.y + border - minmaxrms.r;
  89.         float aboveWave = tc.y - border - minmaxrms.g;
  90.         float factorWave = min(abs(belowWave), abs(aboveWave));
  91.         bool insideWave = (belowWave > 0 && aboveWave < 0);
  92.  
  93.         float diffRms = abs(tc.y) - border - minmaxrms.b;
  94.         float factorRms = abs(diffRms);
  95.         bool insideRms = diffRms < 0;
  96.  
  97.         float factor = insideRms ? (1.0 - 0.5 * saturate(factorRms / border / 2)): 1.0;
  98.         factor = insideWave ? (factor * saturate(factorWave / border / 2)) : 0.0;
  99.  
  100.         return factor;
  101. }
  102.  
  103. float4 PS( PS_IN input ) : SV_Target
  104. {
  105.         float dx, dy;
  106.         if (horizontal)
  107.         {
  108.                 dx = 1/viewportSize.x;
  109.                 dy = 1/viewportSize.y;
  110.         }
  111.         else
  112.         {
  113.                 dx = 1/viewportSize.y;
  114.                 dy = 1/viewportSize.x;
  115.         }
  116.         float seekWidth = 2.5 * dx;
  117.         float positionWidth = 2.5 * dx;
  118.  
  119.         float factor = RMSfactor(input.tc, 2.5 * dy);
  120.  
  121.         float4 c0 = evaluate(backgroundColor, textColor, factor);
  122.         c0 = played(cursorPos, input.tc, c0, factor);
  123.  
  124.         c0 = bar(cursorPos, input.tc, selectionColor, c0, positionWidth, cursorVisible);
  125.         c0 = bar(seekPos,   input.tc, selectionColor, c0, seekWidth,     seeking      );
  126.         return c0;
  127. }
  128.  
  129. technique10 Render10
  130. {
  131.         pass P0
  132.         {
  133.                 SetGeometryShader( 0 );
  134.                 SetVertexShader( CompileShader( vs_4_0, VS() ) );
  135.                 SetPixelShader( CompileShader( ps_4_0, PS() ) );
  136.         }
  137. }
  138.  
  139. technique Render9
  140. {
  141.         pass
  142.         {
  143.                 VertexShader = compile vs_2_0 VS();
  144.                 PixelShader = compile ps_2_0 PS();
  145.         }
  146. }
  147.