rastapasta/react-native-gl-model-view

Texture Flickering

Dylan-Wells-at-LION opened this issue · 0 comments

Hello again. This is related to GLView but since @PatriceVignola forked it I figure I'd post this issue here. I'm having issues with detailed textures flickering when the model is moving:

texture-flickering

It's a bit hard to tell from this GIF (couldn't upload video) but if you look closely there is a sort of static distortion on the detailed parts of the texture as the model rotates. It is quite visible on the device itself.

As far as I can tell the solution lies in altering initWithSize in GLImage.m. That or initWithData but changing that function hasn't done anything for me. I've tried messing around with this block in initWithSize:

//create texture
glGenTextures(1, &_texture);
glBindTexture(GL_TEXTURE_2D, self.texture);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, imageData);

I've tried passing GL_NEAREST, GL_NEAREST_MIPMAPNEAREST, and GL_LINEAR_MIPMAP_LINEAR where GL_LINEAR is but none of that has seemed to fix it. GL_NEAREST makes no difference whereas passing anything MIPMAP makes the texture white. Frankly I don't really know what I'm doing here so it's probably obvious why that didn't work.

Another solution I found was to implement anisotropic filtering by doing something like this:

float aniso = 0.0f;
glGetFloatv(GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, &aniso);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY_EXT, aniso);

The project builds fine with those lines but it doesn't seem to do anything, or I'm putting it in the wrong place.

Anyway those are the two most common solutions to the problem that I've found: mipmapping and anisotropic filtering. Does this sound right to you? Would appreciate your feedback when you get a chance.