Advertisement
Guest User

Untitled

a guest
Dec 9th, 2016
173
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.31 KB | None | 0 0
  1. texture 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. struct VS_IN
  14. {
  15. float2 pos : POSITION;
  16. float2 tc : TEXCOORD0;
  17. };
  18.  
  19. struct PS_IN
  20. {
  21. float4 pos : SV_POSITION;
  22. float2 tc : TEXCOORD0;
  23. };
  24.  
  25.  
  26. float4 backgroundColor : BACKGROUNDCOLOR;
  27. float4 highlightColor : HIGHLIGHTCOLOR;
  28. float4 selectionColor : SELECTIONCOLOR;
  29. float4 textColor : TEXTCOLOR;
  30. float cursorPos : CURSORPOSITION;
  31. bool cursorVisible : CURSORVISIBLE;
  32. float seekPos : SEEKPOSITION;
  33. bool seeking : SEEKING;
  34. float4 replayGain : REPLAYGAIN; // album gain, track gain, album peak, track peak
  35. float2 viewportSize : VIEWPORTSIZE;
  36. bool horizontal : ORIENTATION;
  37. bool flipped : FLIPPED;
  38. bool shade_played : SHADEPLAYED;
  39. float3 track_magnitude : TRACKMAGNITUDE;
  40.  
  41. PS_IN VS( VS_IN input )
  42. {
  43. PS_IN output = (PS_IN)0;
  44.  
  45. float2 half_pixel = float2(1,-1) / viewportSize;
  46. output.pos = float4(input.pos - half_pixel, 0, 1);
  47.  
  48. if (horizontal)
  49. output.tc = float2((input.tc.x + 1.0) / 2.0, input.tc.y);
  50. else
  51. output.tc = float2((-input.tc.y + 1.0) / 2.0, input.tc.x);
  52.  
  53. if (flipped)
  54. output.tc.x = 1.0 - output.tc.x;
  55.  
  56. return output;
  57. }
  58.  
  59. float4 bar( float pos, float2 tc, float4 fg, float4 bg, float width, bool show )
  60. {
  61. float dist = abs(pos - tc.x);
  62. float4 c = (show && dist < width)
  63. ? lerp(fg, bg, smoothstep(0, width, dist))
  64. : bg;
  65. return c;
  66. }
  67.  
  68. float4 evaluate( float2 tc, float cursorPos )
  69. {
  70. // alpha 1 indicates biased texture
  71. float4 minmaxrms = tex1D(sTex, tc.x);
  72. minmaxrms.rgb -= 0.5 * minmaxrms.a;
  73. minmaxrms.rgb *= 1.0 + minmaxrms.a;
  74. float below = tc.y - minmaxrms.r;
  75. float above = tc.y - minmaxrms.g;
  76. float factor = min(abs(below), abs(above));
  77. bool outside = (below < 0 || above > 0);
  78. bool inside_rms = abs(tc.y) <= minmaxrms.b;
  79. bool played = cursorPos < tc.x;
  80. float4 inside_color = played ? textColor : highlightColor;
  81. float4 bgColor = backgroundColor;
  82.  
  83. float4 wave = outside
  84. ? bgColor
  85. : inside_color
  86. ;
  87.  
  88. return saturate(wave);
  89. }
  90.  
  91. float4 reflect_evaluate( float2 tc, float cursorPos)
  92. {
  93. float baseline = -1.0/3.0;
  94. float low_unscale = 3.0/2.0;
  95. float high_unscale = 3.0/4.0;
  96. bool mirrored = tc.y < baseline;
  97. if (mirrored) {
  98. tc.y = baseline - tc.y;
  99. tc.y = tc.y * low_unscale;
  100. }
  101. else {
  102. tc.y = tc.y - baseline;
  103. tc.y = tc.y * high_unscale;
  104. }
  105. float mag = max(-track_magnitude.r, track_magnitude.g);
  106. if (mag > 0.95) {
  107. tc.y = lerp(0, mag/0.95, tc.y);
  108. }
  109. float boost = mirrored ? 1.3 : 1.0;
  110. float gradient = lerp(0.7, 1.0, tc.y);
  111. return boost * gradient * evaluate(tc, cursorPos);
  112. }
  113.  
  114. float4 PS( PS_IN input ) : SV_Target
  115. {
  116. float dx, dy;
  117. if (horizontal) {
  118. dx = 1/viewportSize.x;
  119. dy = 1/viewportSize.y;
  120. }
  121. else {
  122. dx = 1/viewportSize.y;
  123. dy = 1/viewportSize.x;
  124. }
  125. float seekWidth = 2.5 * dx;
  126. float positionWidth = 2.5 * dx;
  127.  
  128. float4 c0 = reflect_evaluate(input.tc, cursorPos);
  129. c0 = bar(cursorPos, input.tc, selectionColor, c0, positionWidth, cursorVisible);
  130. c0 = bar(seekPos, input.tc, selectionColor, c0, seekWidth, seeking );
  131. return c0;
  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