Small question about cubic Tex SDK example

Hi all,

I am currently studying the BiCubicTex SDK example, I understand the concept of cubic B-spline interpolation, but I am having problems with a small portion of the code. they are below:

in function tex2DFastBicubic() in “SobelFilter_kernels.cuh”

x -= 0.5f;
y -= 0.5f;
float px = floor(x);
float py = floor(y);
float fx = x - px;
float fy = y - py;

I know these part of the code is trying to determine the integer part and the fractional part of the input coordinates, but why do we do these after x -= 0.5f; y -= 0.5f;? What is the meaning of shifting (0, extent) to (-0.5, extent-0.5)?

Thank you very much!

These operations compensate an intrinsic offset in the definition of the GPU’s texture fetching operation. Check appendix E of the (4.0) Programming Guide.

Thanks for the reply, now I know it’s not algorithm related maths, but in the Appendix E it only gives the statement:“i = floor(xB), a = frac(xB), xB = x - 0.5” without explanation, could you elaborate a little bit please?

Looking at the actual code it turns out I was wrong. The 0.5 off set in the texture definition is taken care of a few lines down the code. The “-=0.5” in the code is to find the nearest sample, not the interval the point is in, because the code uses the basis functions of the spline and not an interpolation formula.

You know what, I am starting to like the idea that the 0.5 off set is taking care of the texture definition… :tongue: I don’t see how this is going to be dealt with later… And I don’t think take a -0.5 off set is going to get the right nearest sample, for example, if x=3.3, then after the off set, x would be 2.8, and floor(2.8) = 2, while the right nearest point is actually 3, right?