Advertisement
Guest User

Untitled

a guest
Oct 9th, 2011
309
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.42 KB | None | 0 0
  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. return c;
  71. }
  72.  
  73. float RMSfactor( float2 tc, float border )
  74. {
  75. // alpha 1 indicates biased texture
  76. float4 minmaxrms = tex.Sample(sTex, tc.x);
  77. if (replayGain.g != -1000) {
  78. minmaxrms.rgb *= pow(10,(replayGain.g) / 20) * 2; //use track gain
  79. } else if (replayGain.r != -1000) {
  80. minmaxrms.rgb *= pow(10,(replayGain.r) / 20) * 2; //use album gain
  81. }
  82. minmaxrms.rgb -= 0.5 * minmaxrms.a;
  83. minmaxrms.rgb *= 1.0 + minmaxrms.a;
  84.  
  85. float belowWave = tc.y + border - minmaxrms.r;
  86. float aboveWave = tc.y - border - minmaxrms.g;
  87. float factorWave = min(abs(belowWave), abs(aboveWave));
  88. bool insideWave = (belowWave > 0 && aboveWave < 0);
  89.  
  90. float diffRms = abs(tc.y) - border - minmaxrms.b;
  91. float factorRms = abs(diffRms);
  92. bool insideRms = diffRms < 0;
  93.  
  94. float factor = insideRms ? (1.0 - 0.5 * saturate(factorRms / border / 2)): 1.0;
  95. factor = insideWave ? (factor * saturate(factorWave / border / 2)) : 0.0;
  96.  
  97. return factor;
  98. }
  99.  
  100. float4 PS( PS_IN input ) : SV_Target
  101. {
  102. float dx, dy;
  103. if (horizontal)
  104. {
  105. dx = 1/viewportSize.x;
  106. dy = 1/viewportSize.y;
  107. }
  108. else
  109. {
  110. dx = 1/viewportSize.y;
  111. dy = 1/viewportSize.x;
  112. }
  113. float seekWidth = 2.5 * dx;
  114. float positionWidth = 2.5 * dx;
  115.  
  116. float factor = RMSfactor(input.tc, 2.5 * dy);
  117.  
  118. float4 c0 = evaluate(backgroundColor, textColor, factor);
  119. if (shade_played)
  120. c0 = played(cursorPos, input.tc, c0, factor);
  121. c0 = bar(cursorPos, input.tc, selectionColor, c0, positionWidth, cursorVisible);
  122. c0 = bar(seekPos, input.tc, selectionColor, c0, seekWidth, seeking );
  123. return c0;
  124. }
  125.  
  126. technique10 Render10
  127. {
  128. pass P0
  129. {
  130. SetGeometryShader( 0 );
  131. SetVertexShader( CompileShader( vs_4_0, VS() ) );
  132. SetPixelShader( CompileShader( ps_4_0, PS() ) );
  133. }
  134. }
  135.  
  136. technique Render9
  137. {
  138. pass
  139. {
  140. VertexShader = compile vs_2_0 VS();
  141. PixelShader = compile ps_2_0 PS();
  142. }
  143. }
  144.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement