Advertisement
Guest User

Untitled

a guest
May 13th, 2010
1,061
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.41 KB | None | 0 0
  1. Texture1D tex : WAVEFORMDATA;
  2. Texture2D seekTex < string filename = "seekbar.png"; >;
  3.  
  4. SamplerState sTex
  5. {
  6. Filter = MIN_MAG_MIP_LINEAR;
  7. AddressU = Clamp;
  8. };
  9.  
  10. struct VS_IN
  11. {
  12. float2 pos : POSITION;
  13. float2 tc : TEXCOORD0;
  14. };
  15.  
  16. struct PS_IN
  17. {
  18. float4 pos : SV_POSITION;
  19. float2 tc : TEXCOORD0;
  20. };
  21.  
  22.  
  23. float4 backgroundColor : BACKGROUNDCOLOR;
  24. float4 highlightColor : HIGHLIGHTCOLOR;
  25. float4 selectionColor : SELECTIONCOLOR;
  26. float4 textColor : TEXTCOLOR;
  27. float cursorPos : CURSORPOSITION;
  28. bool cursorVisible : CURSORVISIBLE;
  29. float seekPos : SEEKPOSITION;
  30. bool seeking : SEEKING;
  31. float4 replayGain : REPLAYGAIN; // album gain, track gain, album peak, track peak
  32. float2 viewportSize : VIEWPORTSIZE;
  33. bool horizontal : ORIENTATION;
  34. bool shade_played : SHADEPLAYED;
  35.  
  36. PS_IN VS( VS_IN input )
  37. {
  38. PS_IN output = (PS_IN)0;
  39.  
  40. float2 half_pixel = float2(1,-1) / viewportSize;
  41. output.pos = float4(input.pos - half_pixel, 0, 1);
  42. if (horizontal)
  43. output.tc = float2((input.tc.x + 1.0) / 2.0, input.tc.y);
  44. else
  45. output.tc = float2((-input.tc.y + 1.0) / 2.0, input.tc.x);
  46.  
  47. return output;
  48. }
  49.  
  50. float4 bar( float pos, float2 tc, float4 fg, float4 bg, float width, bool show )
  51. {
  52. float dist = abs(pos - tc.x);
  53. float4 c = (show && dist < width)
  54. ? lerp(fg, bg, smoothstep(0, width, dist))
  55. : bg;
  56. return c;
  57. }
  58.  
  59. float4 evaluate(float4 bg, float4 fg, float factor)
  60. {
  61. return saturate(lerp(bg, fg, factor));
  62. }
  63.  
  64. float4 played( float pos, float2 tc, float4 bg, float factor)
  65. {
  66. float4 c = bg;
  67. if (pos > tc.x)
  68. {
  69. c = evaluate(backgroundColor, highlightColor, factor);
  70. }
  71. return c;
  72. }
  73.  
  74. float RMSfactor( float2 tc, float border )
  75. {
  76. // alpha 1 indicates biased texture
  77. float4 minmaxrms = tex.Sample(sTex, tc.x);
  78. minmaxrms.rgb *= pow(10,(replayGain.g) / 20) * 2; //use track gain
  79. //minmaxrms.rgb *= pow(10,(replayGain.r) / 20) * 2; //use album gain
  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. if (shade_played)
  118. c0 = played(cursorPos, input.tc, c0, factor);
  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. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement