0

I am rendering a texture in opengl-es-2.0 under a large angle with respect to the viewer (a floor plane). On hardware which supports anisotropic filtering, all is fine. However, I need to support some devices which do not have this in hardware (no GL_EXT_texture_filter_anisotropic).

With mipmap off, the texture is sharp in the distance, but I have Moiré patterns, as expected. With mipmap on, the Moiré patterns are gone, but the texture is blurred in the distance (again, as expected).

Is there any alternative on hardware without anisotropic filtering? Is it feasible to do this in the fragment shader (opengl-es-2.0 only I'm afraid)? Any sample code anywhere? I did find http://www.pmavridis.com/ewa.html on elliptic weighted average filtering, which I guess could be implemented, but the sample code uses underlying anisotropic hardware filtering, and anyhow uses loads of things not available on opengl-es-2.0.

I am not aiming for high frame rates, just good image quality.

genpfault
  • 47,669
  • 9
  • 68
  • 119
Kasper Peeters
  • 1,502
  • 2
  • 17
  • 35

1 Answers1

2

Trilinear filtering for your mipmaps improves things a little:

glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);

Mipmap bias will improve the sharpness. It may introduce some Moire, but nowhere near as much as disabling mipmapping altogether. It's done by invoking a different overload of texture2D in the fragment shader

texture2D(yourSampler, yourTexCoords, yourMipBias);

IIRC, a value of -1 for yourMipBias will sharpen up the texture sampling by 1 mip level, you'd have to tweak for your scene, but something around -0.5 to -1.5 might be good enough.

I believe it would be possible to write your own anisotropic filtering in the shader, but I have no first hand experience of it. I would try these easier and more efficient approaches first to see if you can get a decent visual quality that way.

Columbo
  • 6,065
  • 4
  • 13
  • 27