0
votes

I'm using OpenTK wrapper in C# for OpenGL 3.1. I'm rendering a scene where the same textures are used for near and far away objects. When I don't use MipMap the textures are very sharp (even if the textured object is very small) but the scintillation (if I understand the term properly) is visible - pixels of the texture seems blinking when the textured object is moving far away. So I tried to to use mipmaps. After changing to TextureMinFilter to LinearMipmapLinear and calling GL.GenerateMipmap(GenerateMipmapTarget.Texture2D) the scintillation effects is gone, but the textures are very blurred, here are images for comparison:

no mipmapsmipmaps

It looks like automatic generation of mipmaps require some tweaking, but I couldn't find any way of telling OpenTK how many mipmaps should be build or what method should be used to downscale original images. This is a code used for loading textures:

var data = bmp.LockBits(new Rectangle(0, 0, bmp.Width, bmp.Height), System.Drawing.Imaging.ImageLockMode.ReadOnly, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
GL.BindTexture(TextureTarget.Texture2D, textures[idx]);
GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, (int)TextureMinFilter.LinearMipmapLinear);
GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMagFilter, (int)TextureMagFilter.Linear);
GL.TexImage2D(TextureTarget.Texture2D, 0, PixelInternalFormat.Rgba, bmp.Width, bmp.Height, 0, OpenTK.Graphics.OpenGL.PixelFormat.Bgra, PixelType.UnsignedByte, data.Scan0);
GL.GenerateMipmap(GenerateMipmapTarget.Texture2D);  
bmp.UnlockBits(data);

What could be done to improve texture sharpness when using mipmaps?

UPDATE:

After generating mipmaps manually the effect is exactly the same.

SOLUTION: I followed datenwolf's answer and used anisotropic texture filtering - that eliminated the problem. I enabled it with code:

        float maxAniso;
        GL.GetFloat((GetPName)ExtTextureFilterAnisotropic.MaxTextureMaxAnisotropyExt, out maxAniso);
        GL.TexParameter(TextureTarget.Texture2D, (TextureParameterName)ExtTextureFilterAnisotropic.TextureMaxAnisotropyExt, maxAniso);

List of supported extensions can be obtained with:

var extensions = GL.GetString(StringName.Extensions).Split(' ');
1
Regarding how many mipmaps are built, there's a very systematic way that is done. I have outlined that in another answer to a similar question. You may find glancing over that useful.Andon M. Coleman

1 Answers

1
votes

There are two main possible culprits here: There may be onla a low quality downscaling filter in the OpenGL implementation's glGenerateMipmap. A slight anisotropy in texture coordinates that may cause a blurrier filtering.

Remedies:

  • Implement your own image downscaling and pass each mipmap level individually (glTexImage2D level parameter) and not rely on glGenerateMipmaps

  • Use anisotropic texture filtering