PDA

View Full Version : Bilinear interpolation texture rendering



yossi
05-18-2004, 05:49 AM
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,

Yossi

jra101
05-18-2004, 08:52 AM
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)),
weight.x);

float4 top = lerp(texRECT(texture, uv + float2(0, 1)),
texRECT(texture, uv + float2(1, 1)),
weight.x);

return lerp(bottom, top, weight.y);
}Should be fairly simple to translate to GLSL.