Using MipMap In GLSL

Hi everyone,
I want to know how to use mipmap in glsl, whether is that, I setup some parameters such as GL_LINEAR_MIPMAP_NEAREST to my texture, then call texture2DLod in glsl ? But how should I obian the derivative in shader, manually calculate them ?
Thanks !

There are the dFdx and dFdy functions in GLSL to get the derivative of some variables. There are a lot of cases in which the derivatives are undefined though e.g in some cases involving conditionals.

With texture2DLod you can specify the the texture coordinates and the additional mipmap level level to sample. The lod valus you calculated with the above functions can be used.

But you don’t actually have to use the texture2DLod functions to use mipmaps. The hardware will do the lod calculation automatically and use the proper lod for you with the texture2D functions. This will also be a lot faster. The dFdx and dFdx may also not work on all cards. Radeon X800 does not have them for instance and falls back to software rendering.

[ | vector_math (3d math library) | software renderer ]

texture2DLod is for the vertex shader or in the fragment shader (if GL_EXT_gpu_shader4 is supported). If the extension is not supported, you use the regular texture2D in the fragment shader (and the mipmap lod is computed automatically and used for indexing into the mipmap chain). Using derivatives in the vertex shader is not possible.

Hi Trenki & Nicolai, thanks for your replies.

I am trying to do deferred shading on my 8800GT, I have owned the fixed sized render target, such as P,N,st etc. Their formats are all FP32. So I want to shading better and faster, with FSAA, so I choose mipmap, but I am confused that how to calucate derivative correctly, is it correctly that hardware passes to fragment shader?

For anyone else stuck on this problem, I brought it up again in this post…5631#Post305631

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