Android: How to fix aliasing or enable mipmaps?

Symptoms

  • Aliasing artifacts appear when the camera is moved farther from a webview.
  • Text becomes blurry or hard to read when the camera is moved farther from a webview.

Cause

Mipmaps aren't enabled for the OES textures used by 3D WebView's Android plugins.

Resolution

In order to achieve efficient rendering, 3D WebView's Android plugins use the GL_OES_EGL_image_external OpenGL extension. Normally, aliasing for a texture can be reduced by enabling mipmaps, however the specification for GL_OES_EGL_image_external declares that the extension doesn't support mipmaps:

Calling GenerateMipmaps with set to TEXTURE_EXTERNAL_OES results in an INVALID_ENUM.

However, there are still a couple of options for reducing aliasing:

  1. If your application uses XR, you can reduce aliasing by increasing XRSettings.eyeTextureResolutionScale, like this:
XRSettings.eyeTextureResolutionScale = 2;
  1. Another option is to blit the webview's texture to a RenderTexture with mipmaps enabled by using the script from this article and adding the following additional settings to the end of the script's Start() method:
_renderTexture.filterMode = FilterMode.Trilinear;
_renderTexture.anisoLevel = 8;
_renderTexture.useMipMap = true;