Problems using mipmapping on 3d textures

Started by Martijn, October 06, 2014, 20:09:54

Previous topic - Next topic

Martijn

Hi guys,

I'm working on my engine for quite a well now, recently got a 3D textured terrain working, but I can't seem to get mipmapping working on 3D textures.

The problem is when i use auto-generate mipmaps I get really weird results:

Mipmapping off:


Mipmapping on:


The code used to make the textures is the same for both the water (texture2D) and terrain (texture3D)
GL11.glTexParameteri(t, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_LINEAR_MIPMAP_LINEAR);
GL11.glTexParameteri(t, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_LINEAR_MIPMAP_LINEAR);
GL11.glTexParameteri(t, GL12.GL_TEXTURE_MAX_LEVEL, mipMapCount);
GL11.glTexParameteri(t, GL14.GL_GENERATE_MIPMAP, (autoMipMap) ? GL11.GL_TRUE : GL11.GL_FALSE);


Is there something I'm missing or doing wrong? Or maybe somebody knows a tutorial about mipmapping 3D textures, please let me know.  :)

Cornix

Perhaps try to show all mipmap levels or maybe write them to an image file.
One problem might be that the mipmaps work just fine but they are so tiny that they become a single pixel because of how far you are zoomed out.

quew8

Make sure you're setting the GL_GENERATE_MIPMAP flag before calling glTexImage2D(). Looking at the docs, with this setting set to true, mipmaps will only be generated when there is a change to the level 0 image.

Also you could try using glGenerateMipmap() to see whether that produces the same effects.

Martijn

I've tried using glGenerateMipmap() on my code but it obviously failed.

Seems like I'm using legacy code to generate mipmaps after reading this: https://www.opengl.org/wiki/Common_Mistakes#Automatic_mipmap_generation

I will rewrite some of my code, read some stuff about texture storage (later opengl versions) and will let you guys know if it helped.

abcdef

Have you confirmed the image is indeed a mipmap image? My code is below, I do things slightly differently to you

private void registerTexture()
    {
        bindTexture();

        renderer.glTexImage2D(renderer.GL_TEXTURE_2D,0,image.getType(),width,height,0,image.getTarget(),renderer.GL_UNSIGNED_BYTE,textureData);

        if(hasMipsMaps)
        {
            renderer.glGenerateMipMaps(renderer.GL_TEXTURE_2D);
        }

        renderer.glPixelStorei(renderer.GL_UNPACK_ROW_LENGTH,0);
        renderer.glPixelStorei(renderer.GL_UNPACK_ALIGNMENT,1);

        renderer.glTexParameteri(renderer.GL_TEXTURE_2D,renderer.GL_TEXTURE_WRAP_S,clampModeS);
        renderer.glTexParameteri(renderer.GL_TEXTURE_2D,renderer.GL_TEXTURE_WRAP_T,clampModeT);

        renderer.glTexParameteri(renderer.GL_TEXTURE_2D,renderer.GL_TEXTURE_MAG_FILTER,filterModeMag);
        renderer.glTexParameteri(renderer.GL_TEXTURE_2D,renderer.GL_TEXTURE_MIN_FILTER,filterModeMin);

        unBindTexture();
    }