resizer.psh
资源名称:bfyy.rar [点击查看]
上传用户:tangyu_668
上传日期:2014-02-27
资源大小:678k
文件大小:2k
源码类别:
多媒体编程
开发平台:
Visual C++
- sampler s0 : register(s0);
- sampler s1 : register(s1);
- sampler s2 : register(s2);
- sampler s3 : register(s3);
- sampler s4 : register(s4);
- float4 p0 : register(c0);
- float2 dxdy : register(c1);
- float2 dx : register(c2);
- float2 dy : register(c3);
- #define A _The_Value_Of_A_Is_Set_Here_
- // none of the resizers here can be used 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!!!
- struct PS_INPUT
- {
- float2 t0 : TEXCOORD0;
- float2 t1 : TEXCOORD1;
- float2 t2 : TEXCOORD2;
- float2 t3 : TEXCOORD3;
- float2 t4 : TEXCOORD4;
- };
- float4 main_bilinear(PS_INPUT input) : COLOR
- {
- float2 dd = frac(input.t4);
- float4 c = lerp(
- lerp(tex2D(s0, input.t0), tex2D(s1, input.t1), dd.x),
- lerp(tex2D(s2, input.t2), tex2D(s3, input.t3), dd.x),
- dd.y);
- return c;
- }
- 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 t)
- {
- return mul(tco, float4(1, t, t*t, t*t*t));
- }
- float4 SampleX(float4 tx, float2 t0)
- {
- return
- mul(tx,
- float4x4(
- tex2D(s0, t0 - dx),
- tex2D(s0, t0),
- tex2D(s0, t0 + dx),
- tex2D(s0, t0 + dx + dx)
- )
- );
- }
- float4 SampleY(float4 tx, float4 ty, float2 t0)
- {
- return
- mul(ty,
- float4x4(
- SampleX(tx, t0 - dy),
- SampleX(tx, t0),
- SampleX(tx, t0 + dy),
- SampleX(tx, t0 + dy + dy)
- )
- );
- }
- float4 main_bicubic1pass(PS_INPUT input) : COLOR
- {
- float2 dd = frac(input.t1);
- return SampleY(taps(dd.x), taps(dd.y), input.t0);
- // return SampleY(tex1D(s1, dd.x), tex1D(s1, dd.y), input.t0);
- }
- float4 Sample(float4 t, PS_INPUT input)
- {
- return
- mul(t,
- float4x4(
- tex2D(s0, input.t0),
- tex2D(s1, input.t1),
- tex2D(s2, input.t2),
- tex2D(s3, input.t3)
- )
- );
- }
- float4 main_bicubic2pass(PS_INPUT input) : COLOR
- {
- float2 dd = frac(input.t4);
- return Sample(taps(dd.x), input);
- // return Sample(tex1D(s4, dd.x), input);
- }