# Thread: Bilinear filtering in fragment program using GLSL

1. ## Bilinear filtering in fragment program using GLSL

How to do custom subj in fragment program with filtering mode set to GL_NEAREST ?

2. ## Re: Bilinear filtering in fragment program using GLSL

What does "subj" mean in your question?

3. ## Re: Bilinear filtering in fragment program using GLSL

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.

4. ## Re: Bilinear filtering in fragment program using GLSL

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

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•