# Manual bilinear filter

**URL:** <https://community.khronos.org/t/manual-bilinear-filter/58504>\
**Category:** OpenGL: Advanced Coding\
**Created:** [September 4, 2009, 10:46am UTC](https://community.khronos.org/t/manual-bilinear-filter/58504 "2009-09-04T10:46:12Z")\
**Posts on this page:** 1\
**Showing post:** 7

<div class="post-metadata">

**Author:** ![peterfilm](https://community.khronos.org/user_avatar/community.khronos.org/peterfilm/32/152_2.png) [@peterfilm](https://community.khronos.org/u/peterfilm)\
**Post date:** [September 9, 2009, 9:54am UTC](https://community.khronos.org/t/manual-bilinear-filter/58504/7 "2009-09-09T09:54:53Z")

</div>

Well, fixed it.  
Not happy with how though.

```auto

vec4 texture2D_bilinear(in sampler2D t, in vec2 uv, in vec2 textureSize, in vec2 texelSize)
{
    vec2 f = fract( uv * textureSize );
    uv += texelSize*0.06; // <--- precision hack (anything higher breaks it)
    vec4 tl = texture2D(t, uv);
    vec4 tr = texture2D(t, uv + vec2(texelSize.x, 0.0));
    vec4 bl = texture2D(t, uv + vec2(0.0, texelSize.y));
    vec4 br = texture2D(t, uv + vec2(texelSize.x, texelSize.y));
    vec4 tA = mix( tl, tr, f.x );
    vec4 tB = mix( bl, br, f.x );
    return mix( tA, tB, f.y );
}

```

Ugly, but it works in all cases now.  
It was obviously point sampling the same texels occasionally, so the slope was lost.  
Anyone shed any light on why?

NVidia Quadro 5800, driver: 190.38 OS: XP64,SP2

---

_[View the full topic](https://community.khronos.org/t/manual-bilinear-filter/58504)._
