   glsl access mipmap
  Hi,Does anyone know how to access a specific mipmap level in a glsl fragment shader?In case u are wondering why, i'm trying to create a blur effect by rendering to a texture, getting gl to automatically generate mipmaps, then in the blur shader, sample from the mipmaps. Does that make sense? good :)Cheers!   
  You can use texture2DLod (instead of texture2D) for that, however for your problem it is probably much easier to simply render to a smaller render target in the first place, or to scale the original scene down manually (google for aniso scaling for a fast technique).Auto-generated mip-maps are not without problems, in particular with render to FBO. You'd better scale manually in either case, because the outcome isn't defined otherwise.   ;  How does the bias parameter of texture2DLod() work?  What are sample values it takes?It seems whatever value i give it produces the same result. I can't seem to find any docs on it anywhere either :(;  texture2DLod() is only allowed in the vertex shaderQuote:The built-ins suffixed with “Lod” are allowed only in a vertex shader. For the “Lod” functions, lod isdirectly used as the level of detail.  page 63You can use GL_ATI_shader_texture_lod but the spec was somewhere in the ATI SDK.   ;Quote:Original post by V-mantexture2DLod() is only allowed in the vertex shaderOn NVidia, the Lod versions work fine in a fragment shader without any extension. On ATI, you have to specify the extension. On Mac, the extension is called GL_ARB_shader_texture_lod...Yay for the competence of the ARB to standarize common functionality !;Quote:Original post by Yann LQuote:Original post by V-mantexture2DLod() is only allowed in the vertex shaderOn NVidia, the Lod versions work fine in a fragment shader without any extension. On ATI, you have to specify the extension. On Mac, the extension is called GL_ARB_shader_texture_lod...Yay for the competence of the ARB to standarize common functionality !LOL. Ya, GL is a turned into a joke.Apple has also long offered functions for checking what features are hw accelerated while there is nothing available on other platforms.   ;I read somewhere texture2DLod() only works on GF8 and over cards in the fragment shader. From what i have gathered so far, in a glsl shader without extensions, you cannot sample from a mipmap level manually. The only thing i can think of is to use glGetTexImage() to copy a mipmap level, create a new texture from the returned data, then sample that from my fragment shader. I guess doing that per frame would suck though.;Quote:Original post by meatcowI read somewhere texture2DLod() only works on GF8 and over cards in the fragment shader. It works fine on my old 6800. Quote:The only thing i can think of is to use glGetTexImage() to copy a mipmap level, create a new texture from the returned data, then sample that from my fragment shader. I guess doing that per frame would suck though.That would suck indeed :) As long as you are sampling the same mipmap level all along (ie. not changing the amount of blurring per-fragment), you can use SGIS_texture_lod to restrict reading to a specific mipmap level. The extension is core since OpenGL 1.2. ;  So, by setting: glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_BASE_LEVEL_SGIS, nBaseLevel); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAX_LEVEL_SGIS, nMaxLevel); So fragments generated from this texture will only sample from mipmap level "nLevel" and less than "nMaxLevel"?btw, i never got that texture2DLod() function working; I just don't get what is supposed to go into that 3rd parameter.;  The 3rd parameter is an offset parameter.The GPU computes which mipmaps needs to be sampled. This is a floating point number, example : 0.7If the 3rd parameter is 0.2, then 0.7+0.2 = 0.9Assuming GL_NEAREST_MIPMAP_NEAREST is used0.9 --> 1so GPU must sample mipmap level 1Assuming GL_LINEAR_MIPMAP_NEAREST is usedso GPU must access mipmap level 0 and 1 and do a lerp calculationresult_Texel = Texel0*0.1 + Texel1*0.9;