Trilinear interpolation in 3d textures

Hello everyone,

I generated a 2x2x2 (8 voxels) 3d texture. What I want to do is to be able to trilinearly interpolate in a fragment shader.

So I want to get a mix color when I index for (0.5,0.5,0.5). Is there a way I can tell OpenGL to do this or do I need to implement it myself?

Thanks,

Ok, it looks like GL_LINEAR does trilinear interp. on 3d textures. Am I wrong? The one below looks like it is trilinear, what do you think? (All corners are assigned different colors, again a 2x2x2 texture)

And I don’t understand why the colors fall to black on the corners.

I got rid of the blackness by switching to GL_CLAMP_TO_EDGE.
I tried GL_LINEAR_MIPMAP_LINEAR and it gives me a completely black box.

Make sure you supply all mip levels of a texture before attempting to use GL_LINEAR_MIPMAP_LINEAR.

Ehm… how can you create mipmaps for 3D textures? And is it possible to do trilinear interp. without using mipmaps? I don’t want level of detail for now.

:slight_smile: “trilinear” basically means “a bilinear between two bilinear lerps from adjacent mips”. So, you must have mipmaps.
glGenerateMipmap(target); // the driver could generate them for you.

The code below gives me a black box:

glGenTextures( 1, &tex3DData_ );
glBindTexture( GL_TEXTURE_3D, tex3DData_);
glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAG_FILTER, GL_LINEAR_MIPMAP_LINEAR);
glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE);
glGenerateMipmapEXT( GL_TEXTURE_3D );
glTexImage3D( GL_TEXTURE_3D, 0, GL_RGBA8, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, vData );

I don’t see what’s wrong with it.

Edit: I see :slight_smile: should be
glTexImage3D( GL_TEXTURE_3D, 0, GL_RGBA8, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, vData );

glGenerateMipmapEXT( GL_TEXTURE_3D );

“trilinear” basically means “a bilinear between two bilinear lerps from adjacent mips”. So, you must have mipmaps.

No. There’s a reason why OpenGL doesn’t have a GL_TRILINEAR blend mode. That’s because blending between mip levels is different from blending on a single mip level.

Using GL_LINEAR means that the texture operation will pick a mip level, and linearly blend between the adjacent texels. In a 1D texture, this means blending between 2 pixels (linear). In a 2D texture, this means blending between 4 pixels (bilinear). In a 3D texture, this means blending between 8 pixels (trilinear).

Trilinear is an overloaded term. In the vernacular, it means 2D bilinear filtering with mipmap filtering. However, when talking about 3D texturing, it means what was said above: linear filtering for a 3D texel within a single mip layer. Applying GL_LINEAR_MIPMAP_LINEAR to a 3D texture is called, in the vernacular, “quadrilinear” filtering.

I don’t see what’s wrong with it.

You generated the mipmaps before you actually put the texture data in it.

Also, you have a 2x2x2 texture. Why do you need mipmaps to begin with? All you’ll get is a 1x1x1 mip level, which is just a single color.

I thought LINEAR_MIPMAP_LINEAR did the trilinear interpolation, so I was just trying to get it to work. Thanks for the explanation.

Okay, so in 2D GL_LINEAR_MIPMAP_LINEAR is trilinear and in 3D GL_LINEAR is trilinear; pardon the 2D/DX mindset.
Mincing of words >_>