0
votes

I'm using texture3DLod in a glsl fragment shader to sample from arbitrary mipmap level of a 3D texture, but the sample I obtain is always from the base level (0). What is wrong?

These variables define my 3D texture in CPU memory:

// Dimensions of the 3D texture
GLsizei dim[3]
// Pointer to texture buffer
GLvoid * voxels;

This is the OpenGL code I use to setup the 3D texture and generate mipmaps:

GLuint texId = 0;
glEnable( GL_TEXTURE_3D );
glGenTextures( 1, &texId );
glBindTexture( GL_TEXTURE_3D, texId );
glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE );
glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE );
glTexImage3D( GL_TEXTURE_3D, 0, GL_LUMINANCE, dim[0], dim[1], dim[2], 0, GL_LUMINANCE, GL_UNSIGNED_BYTE, voxels );
glGenerateMipmap(GL_TEXTURE_3D);

In the fragment shader, we have:

#version 120
#extension GL_ARB_shader_texture_lod : require

uniform sampler3D volume;
variying vec3 position;

void main()
{
    gl_FragColor = texture3DLod( volume, position, 3.0 );
}

No matter what value I use for the last parameter of the texture3DLod function, I obtain the values sampled from level 0 of the 3D texture.

1
"I obtain the values sampled from level 0 of the 3D texture." How do you know that?Nicol Bolas
No matter what value I use for the LOD parameter, the rendered image on the screen remains the same.Simon Drouin

1 Answers

0
votes

you might be missing these two pretty important parameters:

glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);