Advertisement
Guest User

Untitled

a guest
Oct 20th, 2010
185
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.17 KB | None | 0 0
  1. Texture1D tex : WAVEFORMDATA;
  2.  
  3. sampler sTex = sampler_state
  4. {
  5. Texture = <tex>;
  6. MipFilter = LINEAR;
  7. MinFilter = LINEAR;
  8. MagFilter = LINEAR;
  9.  
  10. AddressU = Clamp;
  11. };
  12.  
  13. #if 0
  14. Texture2D bgTex < string ResourceName = "074.jpg"; >;
  15. Texture2D seekTex < string ResourceName = "seekbar.png"; >;
  16.  
  17. sampler sTexBg = sampler_state
  18. {
  19. Texture = <bgTex>;
  20. MipFilter = LINEAR;
  21. MinFilter = LINEAR;
  22. MagFilter = LINEAR;
  23. AddressU = Wrap;
  24. AddressV = Wrap;
  25. };
  26. #endif
  27.  
  28. struct VS_IN
  29. {
  30. float2 pos : POSITION;
  31. float2 tc : TEXCOORD0;
  32. };
  33.  
  34. struct PS_IN
  35. {
  36. float4 pos : SV_POSITION;
  37. float2 tc : TEXCOORD0;
  38. };
  39.  
  40.  
  41. float4 backgroundColor : BACKGROUNDCOLOR;
  42. float4 highlightColor : HIGHLIGHTCOLOR;
  43. float4 selectionColor : SELECTIONCOLOR;
  44. float4 textColor : TEXTCOLOR;
  45. float cursorPos : CURSORPOSITION;
  46. bool cursorVisible : CURSORVISIBLE;
  47. float seekPos : SEEKPOSITION;
  48. bool seeking : SEEKING;
  49. float4 replayGain : REPLAYGAIN; // album gain, track gain, album peak, track peak
  50. float2 viewportSize : VIEWPORTSIZE;
  51. bool horizontal : ORIENTATION;
  52. bool shade_played : SHADEPLAYED;
  53.  
  54. PS_IN VS( VS_IN input )
  55. {
  56. PS_IN output = (PS_IN)0;
  57.  
  58. float2 half_pixel = float2(1,-1) / viewportSize;
  59. output.pos = float4(input.pos - half_pixel, 0, 1);
  60. if (horizontal)
  61. output.tc = float2((input.tc.x + 1.0) / 2.0, input.tc.y);
  62. else
  63. output.tc = float2((-input.tc.y + 1.0) / 2.0, input.tc.x);
  64.  
  65. return output;
  66. }
  67.  
  68. float4 bar( float pos, float2 tc, float4 fg, float4 bg, float width, bool show )
  69. {
  70. float dist = abs(pos - tc.x);
  71. float4 c = (show && dist < width)
  72. ? lerp(fg, bg, smoothstep(0, width, dist))
  73. : bg;
  74. return c;
  75. }
  76.  
  77. float4 faded_bar( float pos, float2 tc, float4 fg, float4 bg, float width, bool show, float vert_from, float vert_to )
  78. {
  79. float dist = abs(pos - tc.x);
  80. float fluff = smoothstep(vert_from, vert_to, abs(tc.y));
  81. float4 c = show
  82. ? lerp(fg, bg, max(fluff, smoothstep(0, width, dist)))
  83. : bg;
  84. return c;
  85. }
  86.  
  87. // #define BORDER_ON_HIGHLIGHT
  88.  
  89. float4 played( float pos, float2 tc, float4 fg, float4 bg, float alpha)
  90. {
  91. float4 c = bg;
  92. float2 d = 1 / viewportSize;
  93. if (pos > tc.x)
  94. {
  95. #ifdef BORDER_ON_HIGHLIGHT
  96. if (tc.x < d.x || tc.y >= (1 - d.y) || tc.y <= (2 * d.y - 1))
  97. c = selectionColor;
  98. else
  99. #endif
  100. c = lerp(c, fg, saturate(alpha));
  101. }
  102. return c;
  103. }
  104.  
  105. float4 evaluate( float2 tc )
  106. {
  107. // alpha 1 indicates biased texture
  108. float4 minmaxrms = tex.Sample(sTex, tc.x);
  109.  
  110. if (replayGain.g != -1000) {
  111. minmaxrms.rgb *= pow(10,(replayGain.g) / 20) * 2; //use track gain
  112. } else if (replayGain.r != -1000) {
  113. minmaxrms.rgb *= pow(10,(replayGain.r) / 20) * 2; //use album gain
  114. }
  115.  
  116. minmaxrms.rgb -= 0.5 * minmaxrms.a;
  117. minmaxrms.rgb *= 1.0 + minmaxrms.a;
  118. float below = tc.y - minmaxrms.r;
  119. float above = tc.y - minmaxrms.g;
  120. float factor = min(abs(below), abs(above));
  121. bool outside = (below < 0 || above > 0);
  122. bool inside_rms = abs(tc.y) <= minmaxrms.b;
  123.  
  124. #if 1
  125. float4 bgColor = backgroundColor;
  126. #else
  127. float a = viewportSize.x / viewportSize.y;
  128. float2 aspect = horizontal ? float2(a, 1) : float2(1/a, 1);
  129. float2 tcBg = float2(tc.x, -tc.y / 2 + 0.5) * aspect;
  130. float4 bgColor = tex2D(sTexBg, tcBg);
  131. #endif
  132.  
  133. float4 wave = outside
  134. ? bgColor
  135. : lerp(bgColor, textColor, 7.0 * factor);
  136.  
  137. return saturate(wave);
  138. }
  139.  
  140. float4 PS( PS_IN input ) : SV_Target
  141. {
  142. float dx, dy;
  143. if (horizontal)
  144. {
  145. dx = 1/viewportSize.x;
  146. dy = 1/viewportSize.y;
  147. }
  148. else
  149. {
  150. dx = 1/viewportSize.y;
  151. dy = 1/viewportSize.x;
  152. }
  153. float seekWidth = 2.5 * dx;
  154. float positionWidth = 2.5 * dx;
  155.  
  156. float4 c0 = evaluate(input.tc);
  157. c0 = bar(cursorPos, input.tc, selectionColor, c0, positionWidth, cursorVisible);
  158. c0 = bar(seekPos, input.tc, selectionColor, c0, seekWidth, seeking );
  159. if (shade_played)
  160. c0 = played(cursorPos, input.tc, highlightColor, c0, 0.3);
  161. return c0;
  162. }
  163.  
  164. technique10 Render10
  165. {
  166. pass P0
  167. {
  168. SetGeometryShader( 0 );
  169. SetVertexShader( CompileShader( vs_4_0, VS() ) );
  170. SetPixelShader( CompileShader( ps_4_0, PS() ) );
  171. }
  172. }
  173.  
  174. technique Render9
  175. {
  176. pass
  177. {
  178. VertexShader = compile vs_2_0 VS();
  179. PixelShader = compile ps_2_0 PS();
  180. }
  181. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement