Jump to content
  • Advertisement
Sign in to follow this  

Error in Bicubic Interpolation algorithm

This topic is 3423 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!