Reputation: 45
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
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);
Upvotes: 0
Views: 1264
Reputation: 54602
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.
Upvotes: 1
Reputation: 36084
If you switch from the single precision float format GL_RGBA32F
to the half-float format GL_RGBA16F
then GL_LINEAR
magnification works fine.
I can't find any documentation to suggest why this shouldn't work, and the only limitation on single precision float textures seems to be when used as render targets, so I guess this is a bug to be filed under "GL_RGBA32F
ignores GL_LINEAR
magnification on iOS 9".
If it genuinely is a bug, then be understanding - I imagine an OpenGLES 3
implementation to be one of the largest, most awful switch-statement-driven pieces of code that one could possibly have the misfortune to work on. If you consider that whatever glamour the job might have entailed previously has since been sucked out by the release of the faster, sexier and legacy-free Metal then you're probably talking about a very unloved codebase, maintained by some very unhappy people. You're lucky flat shaded triangles even work.
p.s. when using GL_TEXTURE_3D
don't forget to clamp in the third coordinate (GL_TEXTURE_WRAP_R
)
p.p.s test this on a device. neither GL_RGBA32F
nor GL_RGBA16F
seem to work with GL_LINEAR
on the simulator
Upvotes: 0