Advertisement
Guest User

waveform Darkone4 flat

a guest
Mar 28th, 2013
423
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.83 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.  
  40. PS_IN VS( VS_IN input )
  41. {
  42.     PS_IN output = (PS_IN)0;
  43.  
  44.     float2 half_pixel = float2(1,-1) / viewportSize;
  45.     output.pos = float4(input.pos - half_pixel, 0, 1);
  46.  
  47.     if (horizontal)
  48.     {
  49.         output.tc = float2((input.tc.x + 1.0) / 2.0, input.tc.y);
  50.     }
  51.     else
  52.     {
  53.         output.tc = float2((-input.tc.y + 1.0) / 2.0, input.tc.x);
  54.     }
  55.  
  56.     if (flipped)
  57.         output.tc.x = 1.0 - output.tc.x;
  58.  
  59.     return output;
  60. }
  61.  
  62. float4 bar( float pos, float2 tc, float4 fg, float4 bg, float width, bool show )
  63. {
  64.     float dist = abs(pos - tc.x);
  65.     float4 c = (show && dist < width)
  66.         ? lerp(fg, bg, smoothstep(0, width, dist))
  67.         : bg;
  68.     return c;
  69. }
  70.  
  71.  
  72. float4 evaluate(float4 bg, float4 fg, float factor)
  73. {
  74.         return saturate(lerp(bg, fg, factor));
  75. }
  76.  
  77. float4 played( float pos, float2 tc, float4 bg, float factor)
  78. {
  79.         float4 c = bg;
  80.         if (pos > tc.x)
  81.         {
  82.                 c = evaluate(backgroundColor, highlightColor, factor);
  83.         }
  84.         return c;
  85. }
  86.  
  87. float RMSfactor( float2 tc, float border )
  88. {
  89.         float4 minmaxrms = tex1D(sTex, tc.x);
  90.  
  91.         minmaxrms.rgb -= 0.1 * minmaxrms.a;
  92.         minmaxrms.rgb *= 0.8 + minmaxrms.a;
  93.    
  94.         float belowWave = tc.y + border - minmaxrms.r;
  95.         float aboveWave = tc.y - border - minmaxrms.g;
  96.         float factorWave = min(abs(belowWave), abs(aboveWave));
  97.         bool insideWave = (belowWave > 0 && aboveWave < 0);
  98.      
  99.         float diffRms = abs(tc.y) - border - minmaxrms.b;
  100.         float factorRms = abs(diffRms);
  101.         bool insideRms = diffRms < 0;
  102.      
  103.         float factor = insideRms ? ( 1 + 0.2 * saturate(factorRms / border / 2)): 1.0;
  104.         factor = insideWave ? (factor * saturate(factorWave / border / 1)) : 0.0; //1 = max sharp
  105.      
  106.         return factor;
  107. }
  108.  
  109. float4 PS( PS_IN input ) : SV_Target
  110. {
  111.         float dx, dy;
  112.         if (horizontal)
  113.         {
  114.                 dx = 1/viewportSize.x;
  115.                 dy = 1/viewportSize.y;
  116.         }
  117.         else
  118.         {
  119.                 dx = 1/viewportSize.y;
  120.                 dy = 1/viewportSize.x;
  121.         }
  122.         float seekWidth = 1 * dx;
  123.         float positionWidth = 1 * dx;
  124.  
  125.         float factor = RMSfactor(input.tc, 2.5 * dy);
  126.  
  127.         float4 c0 = evaluate(backgroundColor, textColor, factor);
  128.         if (shade_played)
  129.                 c0 = played(cursorPos, input.tc, c0, factor);
  130.         c0 = bar(cursorPos, input.tc, selectionColor, c0, positionWidth, cursorVisible);
  131.         c0 = bar(seekPos,   input.tc, selectionColor, c0, seekWidth,     seeking      );
  132.         return c0;
  133. }
  134.  
  135. technique10 Render10
  136. {
  137.     pass P0
  138.     {
  139.         SetGeometryShader( 0 );
  140.         SetVertexShader( CompileShader( vs_4_0, VS() ) );
  141.         SetPixelShader( CompileShader( ps_4_0, PS() ) );
  142.     }
  143. }
  144.  
  145. technique Render9
  146. {
  147.     pass
  148.     {
  149.         VertexShader = compile vs_2_0 VS();
  150.         PixelShader = compile ps_2_0 PS();
  151.     }
  152. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement