View Full Version : using mipmap textures in glsl

04-09-2006, 03:06 AM
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?


04-09-2006, 02:39 PM
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.

Andrew Adinetz
04-16-2006, 07:54 AM
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.

04-19-2006, 04:13 AM
Thanks, I'll try that one