Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 5 of 5

Thread: accessing a specific mip level in OpenGL ES 2.0

  1. #1
    Intern Newbie
    Join Date
    May 2009
    Location
    Budapest, Hungary
    Posts
    32

    accessing a specific mip level in OpenGL ES 2.0

    Hi!

    I want to do environment mapping with selecting a specific mip level of a cube map in the sahder according to the roughness parameter of the material (per pixel).
    Since I target GL ES 2.0 (specifically webgl), I cannot use textureCubeLod (which is available on desktop GL and is working as expected), the only thing I can try is the bias parameter. In the cube map I store the mip level in the alpha channel. So first I do a lookup to find out for which mip level the hardware selecting, then do the bias in a second read. However I cannot select the specific mip level this way. To do some debugging, I put a specific color into each cube face mip level, like the entire 0. level for all faces is red, the 1. level is blue etc. With the following sample code, I wanted to access the 3rd mip level, but unfortunately it doesn't work:

    Code :
    float targetLevel = 3.0;
    vec4 color = textureCube(envmap, tc);
    float level = color.a * 255.0;
    float bias = targetLevel - level;
    gl_FragColor = textureCube(envmap, tc, bias);

    The result is a gradient transition across multiple mip levels, and also it's changing for minification/magnification. If I put the read level into gl_FragColor, it's ok. So I guess the bias is not working this way.

    Any help is appreciated.
    Thanks!

  2. #2
    Intern Newbie
    Join Date
    May 2009
    Location
    Budapest, Hungary
    Posts
    32
    Maybe this thread should be in the OpenGL Shading Language section and the title should be changed to "Sampling from a specific mip level in GLSL ES 1.0" or "how texture sampling bias parameter works".

  3. #3
    Advanced Member Frequent Contributor arekkusu's Avatar
    Join Date
    Nov 2003
    Posts
    781
    Quote Originally Posted by thekend View Post
    I target GL ES 2.0 (specifically webgl), I cannot use textureCubeLod
    That's your answer. If your implementation doesn't expose textureLod (i.e. via EXT_shader_texture_lod in ES2 on iOS) then you can't do it.

    For debugging only (i.e. visualizing unfolded cube map faces), you can force a specific LOD by carefully drawing with the right pixel-to-texel ratio. But you can't do it for general purpose environment maps.

  4. #4
    Advanced Member Frequent Contributor
    Join Date
    Apr 2003
    Posts
    664
    An approximate solution would be to use dFdx/dFdy to calculate the miplevel that the fragment is probably going to use.
    Use the negative of that as LoD bias and add your own targeted level. This should redirect the chosen miplevel to the one you intend to use.

  5. #5
    Intern Newbie
    Join Date
    May 2009
    Location
    Budapest, Hungary
    Posts
    32
    Quote Originally Posted by skynet View Post
    An approximate solution would be to use dFdx/dFdy to calculate the miplevel that the fragment is probably going to use.
    Use the negative of that as LoD bias and add your own targeted level. This should redirect the chosen miplevel to the one you intend to use.
    My code snippet exactly do that without using the dFdx/dFdy. I sample the texture two times, the first sample is used to read the miplevel that the fragment is going to use (the mip level is encoded into the alpha channel of the texture). But unfortunately bias = targetLevel - level is not good for accessing targetLevel.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •