Sign in to follow this  
garma83

Error in Bicubic Interpolation algorithm

Recommended Posts

Hi there, I'm implementing a bicubic interpolation algorithm that maps textures in a ray tracer. I'm using the algorithm as described in this post: http://www.gamedev.net/community/forums/topic.asp?topic_id=336744&whichpage=1#2197591 which seems very straightforward to me, and the results look great. However, for some values, the 'cubic' function returns values outside the input values, which should not be possible, but I'm unable to figure out what is wrong. Can anybody help me out and have a look at that function? I'll duplicate it here for convenience. A combination that returns a negative value is 254,8,8,8 and 0.3:
        public static float Cubic(int v0, int v1, int v2, int v3, float t)
        {
            int p = (v3 - v2) - (v0 - v1);
            int q = (v0 - v1) - p;
            int r = v2 - v0;
            int s = v1;
            float tSqrd = t * t;
            return (p * (tSqrd * t)) + (q * tSqrd) + (r * t) + s;
        }

Share this post


Link to post
Share on other sites
I'm not a math genius, but isn't this expected for cubic interpolation? With the step from 254 to 8, you'll get a very steep tangent at v1, so the interpolated value will first sweep downward a bit from v1 before catching up and aiming for v2 again.

Are you by any chance mixing this up with quadratic interpolation?

Quadratic interpolation would be guaranteed to stay between the left and right interpolated values because it doesn't use tangents.


public static float quadraticInterpolate(float a, float b, float t) {
float t2 = t * t;
float t3 = t2 * t;

return a * (2 * t3 - 3 * t2 + 1) + b * (3 * t2 - 2 * t3);
}

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this