Efficient Bicubic filtering code in GLSL?

前端 未结 8 1812
感动是毒
感动是毒 2021-01-30 06:11

I\'m wondering if anyone has complete, working, and efficient code to do bicubic texture filtering in glsl. There is this:

http://www.codeproject.com/Articles/236394/Bi-

8条回答
  •  -上瘾入骨i
    2021-01-30 06:14

    I've been using @Maf 's cubic spline recipe for over a year, and I recommend it, if a cubic B-spline meets your needs.

    But I recently realized that, for my particular application, it is important for the intensities to match exactly at the sample points. So I switched to using a Catmull-Rom spline, which uses a slightly different recipe like so:

    // Catmull-Rom spline actually passes through control points
    vec4 cubic(float x) // cubic_catmullrom(float x)
    {
        const float s = 0.5; // potentially adjustable parameter
        float x2 = x * x;
        float x3 = x2 * x;
        vec4 w;
        w.x =    -s*x3 +     2*s*x2 - s*x + 0;
        w.y = (2-s)*x3 +   (s-3)*x2       + 1;
        w.z = (s-2)*x3 + (3-2*s)*x2 + s*x + 0;
        w.w =     s*x3 -       s*x2       + 0;
        return w;
    }
    

    I found these coefficients, plus those for a number of other flavors of cubic splines, in the lecture notes at: http://www.cs.cmu.edu/afs/cs/academic/class/15462-s10/www/lec-slides/lec06.pdf

提交回复
热议问题