fork download
  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. c = evaluate(backgroundColor, highlightColor, factor);
  69. }
  70. else
  71. {
  72. c = evaluate(highlightColor, backgroundColor, factor);
  73. }
  74. return c;
  75. }
  76.  
  77. float RMSfactor( float2 tc, float border )
  78. {
  79. // alpha 1 indicates biased texture
  80. float4 minmaxrms = tex.Sample(sTex, tc.x);
  81. if (replayGain.g != -1000) {
  82. minmaxrms.rgb *= pow(10,(replayGain.g) / 20) * 2; //use track gain
  83. } else if (replayGain.r != -1000) {
  84. minmaxrms.rgb *= pow(10,(replayGain.r) / 20) * 2; //use album gain
  85. }
  86. minmaxrms.rgb -= 0.5 * minmaxrms.a;
  87. minmaxrms.rgb *= 1.0 + minmaxrms.a;
  88.  
  89. float belowWave = tc.y + border - minmaxrms.r;
  90. float aboveWave = tc.y - border - minmaxrms.g;
  91. float factorWave = min(abs(belowWave), abs(aboveWave));
  92. bool insideWave = (belowWave > 0 && aboveWave < 0);
  93.  
  94. float factor = insideWave ? (saturate(factorWave / border / 2)) : 0.0;
  95.  
  96. return factor;
  97. }
  98.  
  99. float4 PS( PS_IN input ) : SV_Target
  100. {
  101. float dx, dy;
  102. if (horizontal)
  103. {
  104. dx = 1/viewportSize.x;
  105. dy = 1/viewportSize.y;
  106. }
  107. else
  108. {
  109. dx = 1/viewportSize.y;
  110. dy = 1/viewportSize.x;
  111. }
  112.  
  113. float factor = RMSfactor(input.tc, 2.5 * dy);
  114.  
  115. float4 c0 = evaluate(backgroundColor, textColor, factor);
  116. if (shade_played)
  117. c0 = played(cursorPos, input.tc, c0, factor);
  118. c0 = bar(cursorPos, input.tc, selectionColor, c0, dx, cursorVisible);
  119. c0 = bar(seekPos, input.tc, selectionColor, c0, dx, seeking );
  120. return c0;
  121. }
  122.  
  123. technique Render9
  124. {
  125. pass
  126. {
  127. VertexShader = compile vs_2_0 VS();
  128. PixelShader = compile ps_2_0 PS();
  129. }
  130. }
  131.  
Not running #stdin #stdout 0s 0KB
stdin
Standard input is empty
stdout
Standard output is empty