I’m rendering a terrain heightfield with a 3D texture to blend various textures depending upon the height. The third texture coordinate is adjusted according to the height, resulting in snow, rock, grass and then dirt, from highest to lowest.
However, when I apply a third coordinate of close to 0.0 or 1.0, the texture gets slightly darker (see screenshots). I think I may be doing something slightly wrong, but I can’t figure it out.
Here is my texture generation code:
GLuint num; glEnable(GL_TEXTURE_3D); glGenTextures(1, num); glBindTexture(GL_TEXTURE_3D, num); glTexEnvf( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE ); glTexParameteri( GL_TEXTURE_3D, GL_TEXTURE_MIN_FILTER, GL_LINEAR ); glTexParameteri( GL_TEXTURE_3D, GL_TEXTURE_MAG_FILTER, GL_LINEAR ); glTexParameterf( GL_TEXTURE_3D, GL_TEXTURE_WRAP_S, GL_REPEAT); glTexParameterf( GL_TEXTURE_3D, GL_TEXTURE_WRAP_T, GL_REPEAT); glTexParameterf( GL_TEXTURE_3D, GL_TEXTURE_WRAP_R, GL_CLAMP); glTexImage3D( GL_TEXTURE_3D, 0, bpp/8, w,h,d, 0, format, GL_UNSIGNED_BYTE, texture ); //bpp - bits per pixel //w - width //h - height //d - depth (# of layers) //format - either GL_BGR or GL_BGRA depending upon bpp //textuer - pointer to pixel data
As you can see, I’m using GL_CLAMP for the third wrapping coordinate, because with GL_REPEAT the snow would wrap around to dirt, and vice versa. Interestingly, the dark area is in the place of the wrapped texture.
I would think coordinate 0.0 would map to the first layer, and 1.0 would map to the last layer. It seems that 1/layercount maps to layer 0, though. Is that the way it is supposed to be? I could just limit my coordinates to make the dark areas go away, but I was wondering if that was indeed the way it is designed to work.