mapbox / mapbox-gl-js

Interactive, thoroughly customizable maps in the browser, powered by vector tiles and WebGL
https://docs.mapbox.com/mapbox-gl-js/
Other
11.07k stars 2.21k forks source link

Remove mipmapping + anisotropic filtering for raster tiles #4580

Open kkaefer opened 7 years ago

kkaefer commented 7 years ago

We added a call to generateMipMap on a hunch in #112 a few years ago, and it has remained in the raster drawing code ever since. Mipmaps only make sense when the texture is scaled down significantly (way below 50% of its original size), as a mean to improve the quality of the texels used to calculate the fragment color. A few weeks ago, we added anisotropic filtering to improve the quality.

We never added mipmapping for raster tiles in Native, and I don't think we need to, given that we almost always draw the textures in a size that isn't smaller than half the original dimensions. Since we don't mipmap raster tiles, we also don't need anisotropic filtering.

We should remove the call to generateMipMap and consequently remove anisotropic filtering for raster tiles. This should achieve the near identical visual quality while reducing memory usage and making the code less complex.

https://github.com/mapbox/mapbox-gl-native/issues/8688

andrewharvey commented 7 years ago

Do you propose to use gl.LINEAR/gl.NEAREST? Based on that the current behaviour looks smoother than whan I'm seeing with gl.LINEAR without Anisotropic Filtering.

TEXTURE_MIN_FILTER = gl.LINEAR_MIPMAP_NEAREST with Anisotropic Filtering (master) selection_558

TEXTURE_MIN_FILTER = gl.LINEAR without mipmaps without Anisotropic Filtering selection_555

TEXTURE_MIN_FILTER = gl.LINEAR_MIPMAP_NEAREST without Anisotropic Filtering selection_557

TEXTURE_MIN_FILTER = gl.NEAREST without mipmaps without Anisotropic Filtering selection_556

kkaefer commented 7 years ago

Ah interesting; I was developing this from a GL native side, and didn't add mipmapping, which means anisotropic filtering has no effect, so I concluded that it doesn't have an effect. When comparing the images, you'll notice that anisotropic filtering + mipmapping only has an effect when the image is scaled down by more than 50% (in the upper half of the image). The ideal solution would be to make the mipmap generation conditional, and only start generating mipmaps and render with anisotropic filtering when we tilt the map, and render without mipmaps and anisotropic filtering otherwise.