TextureLod

Hi,

I try to manage the mipmap level of a texture by a uniform variable but I’ve some trouble with the textureLod function. The function retrieves me always the finest level of the mipmap (0).

uniform int Level;
uniform sampler2D Texture;

in  vec2 TexCoord;
out vec4 FragColor;

void main()
{
 FragColor = textureLod(Texture,TexCoord,Level);
}

If I use the texelFetch function instead of textureLod, I get the right result (but not interpolated of course).

void main()
{
 ivec2 iTexCoord = TexCoord*textureSize(Texture,Level);
 FragColor = texelFetch(Texture,iTexCoord,Level);
}

Do you have any idea where I’ve made a mistake ?

Thank you in advance.

lod parameter in textureLod is a float. Try:
uniform float Level;

Shouldn’t matter if he originally has it as int.

Did you set the texunit’s filtering to linear_mipmap_linear?
Could it be that you just needed lod-bias instead of explicitly resetting the coordinate gradients?

@randall : I tried, but it changes anything

@Ilian : Yes, the min filter attributes of the texture unit is set to trilinear interpolation (linear_mipmap_linear).

Could it be that you just needed lod-bias instead of explicitly resetting the coordinate gradients?

What do you mean ? Something like that by replacing 0.f by the targeted mipmap level ?


glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_LOD_BIAS,0.f); 

In this case what is the purpose/advantage of textureLod ?

I was convinced I had set min filter to linear_mipmap_linear, but I didn’t.

Thus, problem solved!

Sorry for this waste of time =/