Skip to content

Instantly share code, notes, and snippets.

@just-Addict
Created June 4, 2016 18:01
Show Gist options
  • Save just-Addict/d23be3cc9f8a63c84e41b32f67ab4126 to your computer and use it in GitHub Desktop.
Save just-Addict/d23be3cc9f8a63c84e41b32f67ab4126 to your computer and use it in GitHub Desktop.
Min, Max and RMS peak meter type effect
texture tex : WAVEFORMDATA;
sampler sTex = sampler_state
{
Texture = (tex);
MipFilter = LINEAR;
MinFilter = LINEAR;
MagFilter = LINEAR;
AddressU = Clamp;
};
struct VS_IN
{
float2 pos : POSITION;
float2 tc : TEXCOORD0;
};
struct PS_IN
{
float4 pos : SV_POSITION;
float2 tc : TEXCOORD0;
};
float4 backgroundColor : BACKGROUNDCOLOR;
float4 highlightColor : HIGHLIGHTCOLOR;
float4 selectionColor : SELECTIONCOLOR;
float4 textColor : TEXTCOLOR;
float cursorPos : CURSORPOSITION;
bool cursorVisible : CURSORVISIBLE;
float seekPos : SEEKPOSITION;
bool seeking : SEEKING;
float4 replayGain : REPLAYGAIN; // album gain, track gain, album peak, track peak
float2 viewportSize : VIEWPORTSIZE;
bool horizontal : ORIENTATION;
bool flipped : FLIPPED;
bool shade_played : SHADEPLAYED;
PS_IN VS( VS_IN input )
{
PS_IN output = (PS_IN)0;
float2 half_pixel = float2(1,-1) / viewportSize;
output.pos = float4(input.pos - half_pixel, 0, 1);
if (horizontal)
{
output.tc = float2((input.tc.x + 1.0) / 2.0, input.tc.y);
}
else
{
output.tc = float2((-input.tc.y + 1.0) / 2.0, input.tc.x);
}
if (flipped)
output.tc.x = 1.0 - output.tc.x;
return output;
}
float4 bar( float pos, float2 tc, float4 fg, float4 bg, float width, bool show )
{
float dist = abs(pos - tc.x);
float4 c = (show && dist < width)
? lerp(fg, bg, smoothstep(0, width, dist))
: bg;
return c;
}
float4 faded_bar( float pos, float2 tc, float4 fg, float4 bg, float width, bool show, float vert_from, float vert_to )
{
float dist = abs(pos - tc.x);
float fluff = smoothstep(vert_from, vert_to, abs(tc.y));
float4 c = show
? lerp(fg, bg, max(fluff, smoothstep(0, width, dist)))
: bg;
return c;
}
// #define BORDER_ON_HIGHLIGHT
float4 played( float pos, float2 tc, float4 fg, float4 bg, float alpha)
{
float4 c = bg;
float2 d = 1 / viewportSize;
if (pos > tc.x)
{
#ifdef BORDER_ON_HIGHLIGHT
if (tc.x < d.x || tc.y >= (1 - d.y) || tc.y <= (2 * d.y - 1))
c = selectionColor;
else
#endif
c = lerp(c, fg, saturate(alpha));
}
return c;
}
float4 evaluate( float pos, float2 tc, float4 c0, float2 d )
{
float xd = pos;
float y = -0.5;
float u = -(2*xd / 0.01) * (2*xd / 0.01);
float E = exp(u / 2);
float4 zoomedPos = float4(pos + xd*y*E, 0, 0, log2(2048*d.x*0.1 * (1 + y*E*(1+u/2))));
float4 minmaxrms = tex1Dbias(sTex,zoomedPos);
minmaxrms.rgb = (minmaxrms.rgb - 0.5) * 2;
tc.x = (tc.x-0.5) * 2;
float tickPos = 1.0 - abs(tc.y);
float tickOne = 0.1;
float tickTen = 0.01;
float deci = d.y*20;
float centi = d.y*10;
if ((abs(tc.x) % tickOne <= d.x*2 && tickPos < deci)
|| (abs(tc.x) % tickTen <= d.x*2 && tickPos < centi)
)
{
return 1-c0;
}
if (tc.x > minmaxrms.r && tc.x < minmaxrms.g)
{
float diffRms = abs(tc.x) - minmaxrms.b;
bool insideRms = diffRms < 0;
bool clipped = (minmaxrms.r < -1+(d.x/2) || minmaxrms.g > 1-(d.x/2));
float cntrPoint = abs(tc.x);
float cntrTick = d.x*2;
float linePoint = abs(tc.y);
float barThickness = 0.5;
if (linePoint < barThickness)
c0 = ( cntrPoint < cntrTick)
? float4(1.0,1.0,1.0,1)
: clipped
? float4(1.0, 0,0,1)
: insideRms
? highlightColor
: textColor;
}
return c0;
}
float4 PS( PS_IN input ) : SV_Target
{
float dx, dy;
float2 d, vp;
vp = 1/viewportSize;
if (horizontal)
{
d.xy = vp.xy;
}
else
{
d.xy = vp.yx;
}
float seekWidth = 2.5 * d.x;
float positionWidth = 2.5 * d.x;
float4 c0 = evaluate(cursorPos , input.tc, backgroundColor, d);
c0 = bar(cursorPos, input.tc, selectionColor, c0, positionWidth, cursorVisible);
c0 = bar(seekPos, input.tc, selectionColor, c0, seekWidth, seeking );
if (shade_played)
c0 = played(cursorPos, input.tc, highlightColor, c0, 0.3);
return c0;
}
technique Render9
{
pass
{
VertexShader = compile vs_3_0 VS();
PixelShader = compile ps_3_0 PS();
}
}
@just-Addict
Copy link
Author

seekbar-minmaxrms-peakmeter

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment