Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
opengl manual bilinear filter
// refer to Mesa sample_2d_linear() in s_texfilter.c
vec4 texture2D_bilinear(sampler2D sampler, vec2 tex_coord, vec2 tex_size) {
vec2 unit_texel = 1.0 / tex_size;
vec2 unnorm_tex_coord = (tex_coord * tex_size) - vec2(0.5);
vec2 f = fract(unnorm_tex_coord);
vec2 snap_tex_coord = (floor(unnorm_tex_coord) + vec2(0.5)) / tex_size;
vec4 s1 = texture2D(sampler, snap_tex_coord);
vec4 s2 = texture2D(sampler, snap_tex_coord + vec2(unit_texel.x, 0.));
vec4 s3 = texture2D(sampler, snap_tex_coord + vec2(0., unit_texel.y));
vec4 s4 = texture2D(sampler, snap_tex_coord + unit_texel);
return mix(mix(s1, s2, f.x), mix(s3, s4, f.x), f.y);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.