Using mipmap textures in glsl

Hi there,

I need a simple sample of accessing mipmap levels of a single texture (float) inside a fragment shader. I know that I have to use the bias parameter, but it doesn’t work. I created all mipmap levels for a texture 64x64 downto 1x1 with different color settings, but when I try to access another level than 0, with:

col = texture2D( inputTexture, uv, 2.0 );

it doesn’t work.
What’s the range for the bias parameter?
Do I have to add something in the vertex shader to make mipmap access work in the fragment shader?
Is the mapping for the bias parameter 1.0 -> level 1, 2.0 -> level 2, etc. or something els?

thanks,
benjamin

Quote directly from the GLSL spec

For a fragment shader, if bias is present, it is added to the calculated level of
detail prior to performing the texture access operation.
so the bias value would displace the miplevel, a bias of 1 would pull it down a notch, but you can’t be 100% sure it’s the correct mip level.
It’s not until glsl spec 1.2 you get access to the lod functions in the fragment shader.

In reality, it is possible to access lod functions (texture2DLod()) in the fragment shaders. For NVIDIA cards, simply use the texture2DLod() function in the fragment shader. It will compile (and work OK, as I think, but I have not tested thus far). For ATI hardware, you have to use the GL_ATI_shader_texture_lod extension. Just add the following line to the beginning of your shader

#extension GL_ATI_shader_texture_lod : require

and use texture2DLod() functions in the fragment shader.

However, I do not know any way to make something like this on other cards.

Thanks, I’ll try that one

This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.