Advertisement
Guest User

Untitled

a guest
Aug 28th, 2015
245
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.01 KB | None | 0 0
  1. //The x-component of tc indicates the position along the waveform.
  2. //0.0 is snugly against the left side of the window, 1.0 is to the far right of the window.
  3. //In the PS (pixel shader), a tc.x of 0.25 would be 25% from the left side of the window.
  4.  
  5. //The y-component of tc indicates at what absolute signal level the top and bottom of the window is at.
  6. //The default of 1.0 makes the vertical range of the window from -fullscale to +fullscale.
  7.  
  8. //The pixel shader function runs once for every pixel (fragment) of the window,
  9. //with the parameters interpolated from the values set in the corners by the vertex shader.
  10.  
  11. //The way the waveform is rasterised is that the x-component is used to
  12. //sample the texture representing the amplitude data. The resulting data is
  13. //then tested against the y-component to see if it's outside or inside the waveform,
  14. //and coloured appropriately. If you get rid of the interpolations/smoothsteps at that border,
  15. //you get an aliased sharp edge.
  16.  
  17. //You can have a predicate picking a particular colour for the fragment
  18. //if the sampled value (min/max) is larger than 1.0, instead of the default color.
  19. //As for the exact place to do that, you've got to find on your own as I do not use the default shader anymore.
  20.  
  21.  
  22. //lerp() = linear interpolation (draws curves)
  23.  
  24. Texture1D tex : WAVEFORMDATA;
  25.  
  26. SamplerState sTex
  27. {
  28. Filter = MIN_MAG_MIP_LINEAR;
  29. AddressU = Clamp;
  30. };
  31.  
  32. struct VS_IN
  33. {
  34. float2 pos : POSITION;
  35. float2 tc : TEXCOORD0;
  36. };
  37.  
  38. struct PS_IN
  39. {
  40. float4 pos : SV_POSITION;
  41. float2 tc : TEXCOORD0;
  42. };
  43.  
  44.  
  45. float4 backgroundColor : BACKGROUNDCOLOR;
  46. float4 highlightColor : HIGHLIGHTCOLOR;
  47. float4 selectionColor : SELECTIONCOLOR;
  48. float4 textColor : TEXTCOLOR;
  49. float cursorPos : CURSORPOSITION;
  50. bool cursorVisible : CURSORVISIBLE;
  51. float seekPos : SEEKPOSITION;
  52. bool seeking : SEEKING;
  53. float4 replayGain : REPLAYGAIN; // album gain, track gain, album peak, track peak
  54. float2 viewportSize : VIEWPORTSIZE;
  55. bool horizontal : ORIENTATION;
  56. bool shade_played : SHADEPLAYED;
  57.  
  58. PS_IN VS( VS_IN input )
  59. {
  60. PS_IN output = (PS_IN)0;
  61.  
  62. float2 half_pixel = float2(1,-1) / viewportSize;
  63. output.pos = float4(input.pos - half_pixel, 0, 1);
  64. if (horizontal)
  65. output.tc = float2((input.tc.x + 1.0) / 2.0, input.tc.y);
  66. else
  67. output.tc = float2((-input.tc.y + 1.0) / 2.0, input.tc.x);
  68.  
  69. return output;
  70. }
  71.  
  72. float4 bar( float pos, float2 tc, float4 fg, float4 bg, float width, bool show )
  73. {
  74. float dist = abs(pos - tc.x);
  75. float4 c = (show && dist < width)
  76. ? lerp(fg, bg, smoothstep(0, width, dist))
  77. : bg;
  78. return c;
  79. }
  80.  
  81. float4 evaluate(float4 bg, float4 fg, float factor)
  82. {
  83. return saturate(lerp(bg, fg, factor));
  84. }
  85.  
  86. float4 played( float pos, float2 tc, float4 bg, float factor)
  87. {
  88. float4 c = bg;
  89. if (pos > tc.x)
  90. {
  91. if (shade_played)
  92. c = evaluate(backgroundColor, highlightColor, factor);
  93. else
  94. c = evaluate(highlightColor, textColor, factor);
  95. }
  96. return c;
  97. }
  98.  
  99. float RMSfactor( float2 tc, float border )
  100. {
  101. // alpha 1 indicates biased texture
  102. float4 minmaxrms = tex.Sample(sTex, tc.x);
  103. if (replayGain.g != -1000) {
  104. minmaxrms.rgb *= pow(10,(replayGain.g) / 20) * 1.5; //use track gain
  105. } else if (replayGain.r != -1000) {
  106. minmaxrms.rgb *= pow(10,(replayGain.r) / 20) * 1.75; //use album gain
  107. }
  108. minmaxrms.rgb -= 0.5 * minmaxrms.a;
  109. minmaxrms.rgb *= 1.0 + minmaxrms.a;
  110.  
  111. float belowWave = tc.y + border - minmaxrms.r;
  112. float aboveWave = tc.y - border - minmaxrms.g;
  113. float factorWave = min(abs(belowWave), abs(aboveWave));
  114. bool insideWave = (belowWave > 0 && aboveWave < 0);
  115.  
  116. float diffRms = abs(tc.y) - border - minmaxrms.b;
  117. float factorRms = abs(diffRms);
  118. bool insideRms = diffRms < 0; //inner waveform. `= 0.0;` makes it go away
  119.  
  120. float factor = insideRms ? (1.0 - 0.5 * saturate(factorRms / border / 2)): 1.0;
  121. factor = insideWave ? (factor * saturate(factorWave / border / 2)) : 0.0;
  122.  
  123. return factor;
  124. }
  125.  
  126.  
  127. // I guess this function does the actual drawing?
  128. float4 PS( PS_IN input ) : SV_Target
  129. {
  130. float dx, dy;
  131. if (horizontal)
  132. {
  133. dx = 1/viewportSize.x;
  134. dy = 1/viewportSize.y;
  135. }
  136. else
  137. {
  138. dx = 1/viewportSize.y;
  139. dy = 1/viewportSize.x;
  140. }
  141. float seekWidth = 2.5 * dx;
  142. float positionWidth = 1.5 * dx;
  143.  
  144. float factor = RMSfactor(input.tc, 0.0 * dy); // makes the edge of the waveform fuzzy (default was 2.5*d.y)
  145.  
  146. float4 c0 = evaluate(backgroundColor, textColor, factor);
  147. c0 = played(cursorPos, input.tc, c0, factor);
  148.  
  149. c0 = bar(cursorPos, input.tc, selectionColor, c0, positionWidth, cursorVisible); //play position
  150. c0 = bar(seekPos, input.tc, selectionColor, c0, seekWidth, seeking );//seeking (mouse)
  151. return c0;
  152. }
  153.  
  154. technique10 Render10
  155. {
  156. pass P0
  157. {
  158. SetGeometryShader( 0 );
  159. SetVertexShader( CompileShader( vs_4_0, VS() ) );
  160. SetPixelShader( CompileShader( ps_4_0, PS() ) );
  161. }
  162. }
  163.  
  164. technique Render9
  165. {
  166. pass
  167. {
  168. VertexShader = compile vs_2_0 VS();
  169. PixelShader = compile ps_2_0 PS();
  170. }
  171. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement