PDA

View Full Version : GLSL textureLod(): proper values for the lod parameter?



RealtimeSlave
06-04-2015, 09:37 AM
Hello,

I am using textureLod to draw a texture using a specific mip map level.

The mip map level is controlled via the parameter lod and I can see that
setting lod to 0.0 selects the highest resolution. Increasing lod to 1.0,
2.0 and 3.0 and so on seems to select the lower resolution mip maps
because the image gets more and more blurry.

But what is the exact range for lod? Because I don't want to
pass a value which might be too high.

I searched for it and found 4 different variables which I might need to query?

GL_TEXTURE_MIN_LOD
GL_TEXTURE_MAX_LOD
GL_TEXTURE_BASE_LEVEL
GL_TEXTURE_MAX_LEVEL

But I don't really know how to use them because they return values beetwen
-1000 and 1000 and 0 and 1000 and also I don't know what for example
the difference is between GL_TEXTURE_MAX_LEVEL and GL_TEXTURE_MAX_LOD
or between GL_TEXTURE_BASE_LEVEL and GL_TEXTURE_MIN_LOD.

To make it short, my goal is to just be able to tell the shader with a relative value
(for example 0.5) that I want to draw the image blurred by using a mip map level
(for example which is half the size of the original). And in the shader I don't want
to care how many mip map levels exist.

Help is really appreciated!

Alfonse Reinheart
06-04-2015, 10:02 AM
The base/max levels specify which images can be accessed through the texture object (https://www.opengl.org/wiki/Texture#Mipmap_range). The lod parameter to textureLod is relative to the base mipmap. So 0.0 is always the base level. There is no value for textureLod which is "too high", as the choosen mipmap will always be between clamped by the system to be between the base and max levels.

RealtimeSlave
06-04-2015, 10:43 AM
Thanks!

GL_TEXTURE_BASE_LEVEL == 0
GL_TEXTURE_MAX_LEVEL == 1000

Does this mean 1000 mip maps will be generated by glGenerateMipmap() if the image size would allow it (that must be a huge image)?

And what is the purpose of GL_TEXTURE_MIN_LOD and GL_TEXTURE_MAX_LOD in the whole story?

Alfonse Reinheart
06-04-2015, 11:00 AM
Thanks!

GL_TEXTURE_BASE_LEVEL == 0
GL_TEXTURE_MAX_LEVEL == 1000

Does this mean 1000 mip maps will be generated by glGenerateMipmap() if the image size would allow it (that must be a huge image)?

Yes.


And what is the purpose of GL_TEXTURE_MIN_LOD and GL_TEXTURE_MAX_LOD in the whole story?

It specifies a second range that the LOD is clamped to (https://www.opengl.org/wiki/Sampler_Object#LOD_range). This range is not absolute relative to the texture's storage. It is relative to the base level. So setting MIN_LOD to 1 means that the largest mipmap that will be sampled from is the mipmap level below the base level.

The base/max clamping happens last, so the min/max LOD settings cannot cause sampling outside of the texture's mipmap range.

Think of the base/max level as saying, "the valid & useful data in this texture lies in this mipmap range", while the min/max LOD says, "when sampling from a texture, don't venture outside of these mipmap levels".

RealtimeSlave
06-06-2015, 12:06 AM
Ok got it, thanks a lot!