I'm not quite sure, whether it's related to the new fb2k or the new waveform version, but today I recognized that the seekbar seems to ignore negative replay gain values (or, at least takes only its absolute value). As I'm scaling my waveform by replay gain values, the seekbar appears overscaled. (To be more precise: I'd like to display two waveforms over another, displaying the scaled and the original waveform, as well)
Here's the code of my seekbar.fx file which has worked fine before:
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( float2 tc )
{
// alpha 1 indicates biased texture
float4 minmaxrms = tex1D(sTex, tc.x);
float4 minmaxrms2 = tex1D(sTex, tc.x);
if (replayGain.g != -1000 && replayGain.g < -2.2)
{
float temp = pow(10,(replayGain.g + 2.2) / 20.0);
minmaxrms.rgb *= temp; //use track gain
}
if (replayGain.g != -1000 && replayGain.g > -2.2)
{
float temp = pow(10, (replayGain.g + 2.2) / 20.0);
minmaxrms2.rgb *= temp;
}
minmaxrms.rgb -= 0.5 * minmaxrms.a;
minmaxrms2.rgb -= 0.5 * minmaxrms2.a;
minmaxrms.rgb *= 1.0 + minmaxrms.a;
minmaxrms2.rgb *= 1.0 + minmaxrms2.a;
float below = tc.y - minmaxrms.r;
float above = tc.y - minmaxrms.g;
float below2 = tc.y - minmaxrms2.r;
float above2 = tc.y - minmaxrms2.g;
float factor = 1.5*min(abs(below), abs(above));
float factor2 = 1.5*min(abs(below2), abs(above2));
bool outside = (below < 0 || above > 0);
bool outside2 = (below2 < 0 || above2 > 0);
bool inside_rms = abs(tc.y) <= minmaxrms.b;
#if 1
float4 bgColor = backgroundColor;
#else
float a = viewportSize.x / viewportSize.y;
float2 aspect = horizontal ? float2(a, 1) : float2(1/a, 1);
float2 tcBg = float2(tc.x, -tc.y / 2 + 0.5) * aspect;
float4 bgColor = tex2D(sTexBg, tcBg);
#endif
float4 wave = (outside && outside2)
? backgroundColor
: (wave = (!outside2 && outside)
? (replayGain.g < -2.2
? lerp(bgColor, selectionColor, 2.0 * factor2 )
: lerp(bgColor, highlightColor, 3.0 * factor2) )
: (replayGain.g < -2.2
? lerp(bgColor, textColor, 6.0 * factor )
: lerp(bgColor, textColor, 6.0 * factor) )
);
// lerp(bgColor, textColor, 5.0 * factor2);
return saturate(wave);
}
float4 PS( PS_IN input ) : SV_Target
{
float dx, dy;
if (horizontal)
{
dx = 1/viewportSize.x;
dy = 1/viewportSize.y;
}
else
{
dx = 1/viewportSize.y;
dy = 1/viewportSize.x;
}
float seekWidth = 1.5 * dx;
float positionWidth = 1.5 * dx;
float4 c0 = evaluate(input.tc);
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;
}
technique10 Render10
{
pass P0
{
SetGeometryShader( 0 );
SetVertexShader( CompileShader( vs_4_0, VS() ) );
SetPixelShader( CompileShader( ps_4_0, PS() ) );
}
}
technique Render9
{
pass
{
VertexShader = compile vs_2_0 VS();
PixelShader = compile ps_3_0 PS();
}
}