Search code examples
iosopengl-estexturestexture-mapping

Interpolation in texture3D in OpenGL ES 3.0 on iOS


I am passing a GL_TEXTURE_3D to the fragment shader in an iOS application. I am using minification and magnification filters as GL_LINEAR for this texture. However, the resulting texture rendered in the app has blocks instead of having a smooth transition of colors, which implies that it is using GL_NEAREST interpolation. Here are the screenshots of the expected vs received output image expected output output received

PS: If I use a 2D texture instead, pass in the 3D texture as a flattened 2D texture and do the interpolation manually in the shader, it works all fine and I get the expected output.

Here is the code for setting up GL_LINEAR:

GLenum target, minificationFilter, magnificationFilter;
target = GL_TEXTURE_3D;
minificationFilter = GL_LINEAR;
magnificationFilter = GL_LINEAR;
glTexParameteri(target, GL_TEXTURE_MIN_FILTER, minificationFilter);
glTexParameteri(target, GL_TEXTURE_MAG_FILTER, magnificationFilter);

Solution

  • Linear filtering of textures with internal format GL_RGBA32F is not supported in ES 3.0.

    You can see which formats support linear filtering in table 3.13 of the ES 3.0 spec document, on pages 130-132. The last column, with header "Texture-filterable", indicates which formats support filtering. RGBA32F does not have a checkmark in that column.

    If you need linear filtering for float textures, you're limited to 16-bit component floats. RGBA16F in the same table has the checkmark in the last column.

    This limitation is still in place in the latest ES 3.2 spec.

    There is an extension to lift this limitation: OES_texture_float_linear. However, this extension is not listed under the supported extensions on iOS.