This week only. Pastebin PRO Accounts Christmas Special! Don't miss out!Want more features on Pastebin? Sign Up, it's FREE!
Guest

Untitled

By: a guest on Feb 6th, 2012  |  syntax: None  |  size: 3.28 KB  |  views: 84  |  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.         minmaxrms.rgb -= 0.5 * minmaxrms.a;
  81.         minmaxrms.rgb *= 1.0 + minmaxrms.a;
  82.  
  83.         float belowWave = tc.y + border - minmaxrms.r;
  84.         float aboveWave = tc.y - border - minmaxrms.g;
  85.         float factorWave = min(abs(belowWave), abs(aboveWave));
  86.         bool insideWave = (belowWave > 0 && aboveWave < 0);
  87.  
  88.         float diffRms = abs(tc.y) - border - minmaxrms.b;
  89.         float factorRms = abs(diffRms);
  90.         bool insideRms = diffRms < 0;
  91.  
  92.         float factor = insideRms ? (1.0 - 0.5 * saturate(factorRms / border / 2)): 1.0;
  93.         factor = insideWave ? (factor * saturate(factorWave / border / 2)) : 0.0;
  94.  
  95.         return factor;
  96. }
  97.  
  98. float4 PS( PS_IN input ) : SV_Target
  99. {
  100.         float dx, dy;
  101.         if (horizontal)
  102.         {
  103.                 dx = 1/viewportSize.x;
  104.                 dy = 1/viewportSize.y;
  105.         }
  106.         else
  107.         {
  108.                 dx = 1/viewportSize.y;
  109.                 dy = 1/viewportSize.x;
  110.         }
  111.         float seekWidth = 2.5 * dx;
  112.         float positionWidth = 2.5 * dx;
  113.  
  114.         float factor = RMSfactor(input.tc, 2.5 * dy);
  115.  
  116.         float4 c0 = evaluate(backgroundColor, textColor, factor);
  117.         c0 = played(cursorPos, input.tc, c0, factor);
  118.  
  119.         c0 = bar(cursorPos, input.tc, selectionColor, c0, positionWidth, cursorVisible);
  120.         c0 = bar(seekPos,   input.tc, selectionColor, c0, seekWidth,     seeking      );
  121.         return c0;
  122. }
  123.  
  124. technique10 Render10
  125. {
  126.         pass P0
  127.         {
  128.                 SetGeometryShader( 0 );
  129.                 SetVertexShader( CompileShader( vs_4_0, VS() ) );
  130.                 SetPixelShader( CompileShader( ps_4_0, PS() ) );
  131.         }
  132. }
  133.  
  134. technique Render9
  135. {
  136.         pass
  137.         {
  138.                 VertexShader = compile vs_2_0 VS();
  139.                 PixelShader = compile ps_2_0 PS();
  140.         }
  141. }
clone this paste RAW Paste Data