PDA

View Full Version : mipmapping problem



Rarrum
03-07-2006, 03:17 PM
I'm having some a rather major problem I can't figure out, trying to get mipmapping working on 3D textures. I use a 3D texture for the terrain in a game I'm working on, sampled by a simple shader. When I don't use mipmapping it all renders correctly. However, when I do, it seems like the mipmap data is all garbage (only things sampled from the non-mip layers look right), such as this:
http://www.neoclaw.net/temp/grr_mip.jpg

Here's the basics of how I'm creating and then later loading the textures:


---- for creation ----

GLuint texHand=0;
glGenTextures(1,&texHand);

GLenum texTar=(depth==1?GL_TEXTURE_2D:GL_TEXTURE_3D);
glBindTexture(texTar,texHand);

glTexParameteri(texTar, GL_GENERATE_MIPMAP_SGIS, GL_TRUE);

if (texTar==GL_TEXTURE_2D)
glTexImage2D(GL_TEXTURE_2D,0,intFormat, width,height,0, srcFormat,GL_UNSIGNED_BYTE, 0);
else
glTexImage3DEXT(GL_TEXTURE_3D,0,intFormat, width,height,depth,0, srcFormat,GL_UNSIGNED_BYTE, 0);

glTexParameteri(texTar,GL_TEXTURE_WRAP_S,GL_REPEAT );
glTexParameteri(texTar,GL_TEXTURE_WRAP_T,GL_REPEAT );

glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);

glTexParameteri(texTar,GL_TEXTURE_MIN_FILTER,GL_LI NEAR_MIPMAP_LINEAR);
glTexParameteri(texTar,GL_TEXTURE_MAG_FILTER,GL_LI NEAR);


---- loading it later ----

glBindTexture(texTar,texHand);

glPixelStorei(GL_UNPACK_ALIGNMENT,1);

if (texTar==GL_TEXTURE_2D)
glTexImage2D(GL_TEXTURE_2D,0,intFormat, width,height, 0,srcFormat,GL_UNSIGNED_BYTE, pixels);
else
glTexImage3DEXT(GL_TEXTURE_3D,0,intFormat, width,height,depth, 0,srcFormat,GL_UNSIGNED_BYTE, pixels);


----

in this case:
intFormat is GL_RGBA
srcFormat is GL_BGRA_EXT

dorbie
03-07-2006, 03:55 PM
Well clearly this is not an application issue.

Either MIP map auto generation is broken or the rendering is.

I'd bet it's the autogen. Try manually loading MIP levels for your 3D images.

zed
03-07-2006, 05:09 PM
glTexParameteri(texTar, GL_GENERATE_MIPMAP_SGIS, GL_TRUE);
works with 3d textures on my nv3x

btw youre missing the 3rd wrapping mwthod i believe its GL_TEXTURE_WRAP_R

Rarrum
03-07-2006, 08:18 PM
The wrap r was actually being set at a later spot by the application, but I should probably set it there as a default also.

As for manually generating them, first I had tried glGenerateMipmaps() of the FBO extension... and it crashed in an ati .dll without really any explaination, which is why I tried the automatic extension.

I also looked into using glu to make them, but apparently windows' glu library are ancient, and GetProcAddress wasn't finding the 3D version either. I may just have to write a function to manually make the layers, unless anyone else has any ideas.

rgpc
03-07-2006, 09:10 PM
Rather than your Mipmap data being "garbage" it looks like the data is turned on it's side by the SGIS extension. (The Mipmapped data goes from "Snow" to "Grass" to "Dirt")

I think what Dorbie is getting at is to generate the Mipmap data yourself (eg. In code) and then set the levels yourself using the glTexImage3D function.

Chuck0
03-08-2006, 12:08 AM
just one comment on the use of 3d textures for the purpose of texturing a terrain...

when you use mipmaps and just use very few height levels in the texture (for example 256x256x8) you will get problems because all the levels will be blended together in the distance too early...

Rarrum
03-08-2006, 03:24 PM
you will get problems because all the levels will be blended together in the distance too early...I acually hadn't considered that... and that's roughly the ratio we're using. In light of that, I think I may just generate several 3D textures in which only the u,v dimensions shrink, and then select an appropriate texture based on how far the terrain block is (it's broken up into chunks).

Thanks for all your input on this.