Bilinear interpolation texture rendering

How do make my own fragment shader that draw a smooth texture?
I know I have to read 4 texels and interpolate them according to the texture coordinates and the value of the 4 texels but don’t know the details.
In general I wan’t to make my own filter.

Many thanks,


Here’s a Cg function that does bilinear filtering of a rectangular texture.

float4 texRECTBilinear(samplerRECT texture, float2 uv)
    float2 weight = frac(uv);
    float4 bottom = lerp(texRECT(texture, uv),
                         texRECT(texture, uv + float2(1, 0)),

    float4 top = lerp(texRECT(texture, uv + float2(0, 1)), 
                      texRECT(texture, uv + float2(1, 1)), 

    return lerp(bottom, top, weight.y);

Should be fairly simple to translate to GLSL.

This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.