PDA

View Full Version : Bilinear filtering in fragment program using GLSL

Sergey K.
11-10-2004, 12:43 PM
How to do custom subj in fragment program with filtering mode set to GL_NEAREST ?

jwatte
11-11-2004, 05:56 PM
What does "subj" mean in your question?

V-man
11-11-2004, 08:29 PM
I think subj is an alias for the title.

You can do something quick and cheap with clamping the texcoord, then do sampling at the 4 local texels :

{x, y)
(x+1, y)
(x, y+1)
(x+1, y+1)

then do a weighted blend between the 4.

Sergey K.
11-11-2004, 11:21 PM
I've understood how to do it!

float OneTexel = 1.0/TextureSize;

vec2 coord1 = TexCoord0+vec2(0.0, OneTexel);
vec2 coord2 = TexCoord0+vec2(OneTexel, 0.0 );
vec2 coord3 = TexCoord0+vec2(OneTexel, OneTexel);
vec2 coord4 = TexCoord0;

vec4 s1 = vec4(texture2D(Texture0, coord1));
vec4 s2 = vec4(texture2D(Texture0, coord2));
vec4 s3 = vec4(texture2D(Texture0, coord3));
vec4 s4 = vec4(texture2D(Texture0, coord4));

vec2 Dimensions = vec2(TexCoord0) * TextureSize;

float fu = fract(Dimensions.x);
float fv = fract(Dimensions.y);

vec4 tmp1 = mix(s4, s2, fu);
vec4 tmp2 = mix(s1, s3, fu);

vec4 t0 = mix(tmp1, tmp2, fv);