glslfragment-shaderbicubic

Efficient Bicubic filtering code in GLSL?


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-Cubic-and-Bi-Linear-Interpolation-with-GLSL or https://github.com/visionworkbench/visionworkbench/blob/master/src/vw/GPU/Shaders/Interp/interpolation-bicubic.glsl

but both do 16 texture reads where only 4 are necessary:

https://groups.google.com/forum/#!topic/comp.graphics.api.opengl/kqrujgJfTxo

However the method above uses a missing "cubic()" function that I don't know what it is supposed to do, and also takes an unexplained "texscale" parameter.

There is also the NVidia version:

https://developer.nvidia.com/gpugems/gpugems2/part-iii-high-quality-rendering/chapter-20-fast-third-order-texture-filtering

but I believe this uses CUDA, which is specific to NVidia's cards. I need glsl.

I could probably port the nvidia version to glsl, but thought I'd ask first to see if anyone already has a complete, working glsl bicubic shader.


Solution

  • I decided to take a minute to dig my old Perforce activities and found the missing cubic() function; enjoy! :)

    vec4 cubic(float v)
    {
        vec4 n = vec4(1.0, 2.0, 3.0, 4.0) - v;
        vec4 s = n * n * n;
        float x = s.x;
        float y = s.y - 4.0 * s.x;
        float z = s.z - 4.0 * s.y + 6.0 * s.x;
        float w = 6.0 - x - y - z;
        return vec4(x, y, z, w);
    }