|
|
发表于 2006-1-9 21:23:00
|
显示全部楼层
Re:双三次卷积插值
static float4x4 tco =
{
0, A, -2*A, A,
1, 0, -A-3, A+2,
0, -A, 2*A+3, -A-2,
0, 0, A, -A
};
float4 taps(float x)
{
return mul(tco, float4(1, x, x*x, x*x*x));
}
float4 c3sample(float4 taps, float2 t)
{
return
mul(taps,
float4x4(
tex2D(s0, t-dx),
tex2D(s0, t),
tex2D(s0, t+dx),
tex2D(s0, t+dx+dx)
)
);
}
float4 main_bicubic(float2 tex : TEXCOORD0) : COLOR
{
// not usable for 1:1 mapping!
// tex * size won't be 0, 1, 2, 3, .. as you might expect, but something like 0, 0.999, 2.001, 2.999, ...
// this means when the fractional part becomes 0.999 we will be interpolating with the wrong value!!!
tex -= 0.5*dxdy;
float2 dd = frac(tex * size);
float4 tx = taps(dd.x);
float4 c = mul(
taps(dd.y),
float4x4(
c3sample(tx, tex-dy),
c3sample(tx, tex),
c3sample(tx, tex+dy),
c3sample(tx, tex+dy+dy)
)
);
return c;
}
引自media player classic中的bi-cubic interpolation shader。
其中,-A即为cardinal spline中的tension parameter |
|