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 or this but both do 16 texture reads where only 4 are necessary.

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 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);
    }