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 4 of 4

Thread: Access mipmap of a samplerCubeShadow in GLSL

  1. #1
    Junior Member Newbie
    Join Date
    Jul 2018
    Posts
    4

    Access mipmap of a samplerCubeShadow in GLSL

    I am rendering multiple lights per pass with shadows and use shadow cubemap mipmaps to store shadows of smaller, distant lights. This way I can pass way more shadow maps to a fragment shader considering the texture unit limit of 16 or 32 on most hardware. I then read those with textureLod() and samplerCube.

    Now the problem is that I want to use hardware PCF and for thar I would use a samplerCubeShadow. However textureLod() does not take samplerCubeShadow as one of its inputs what seems like an artificial limitation to me considering that it supports e.g. sampler2DShadow.

    Is there any workaround for this except doing a costly manual loop in the fragment shader?

  2. #2
    Senior Member OpenGL Guru
    Join Date
    Jun 2013
    Posts
    2,926
    Quote Originally Posted by duzenko View Post
    Now the problem is that I want to use hardware PCF and for thar I would use a samplerCubeShadow. However textureLod() does not take samplerCubeShadow as one of its inputs what seems like an artificial limitation to me considering that it supports e.g. sampler2DShadow.

    Is there any workaround for this except doing a costly manual loop in the fragment shader?
    textureGrad() accepts samplerCubeShadow, but calculating the derivatives which would select a particular LoD would require knowing which face will be used.

    Ultimately, the fact that the restriction exists suggests that some hardware simply doesn't allow the LoD to be overridden for shadow cube maps. The whole point of shadow maps is that they allow the hardware to do something other than the usual texture sampling followed by a depth comparison. My guess would be that it's related to how shadow filtering handles the situation where you're sampling on a seam, where the computed LoD could vary greatly between faces.

  3. #3
    Junior Member Newbie
    Join Date
    Jul 2018
    Posts
    4
    Quote Originally Posted by GClements View Post
    textureGrad() accepts samplerCubeShadow, but calculating the derivatives which would select a particular LoD would require knowing which face will be used.
    Thanks. Can you tell me how to sample from the nth mipmap of a samplerCubeShadow using textureGrad()? I.e. what ddx/ddy values do I pass for the nth mipmap?

    1.0*(1<<mipMapNo)/screen_width?
    Last edited by duzenko; 09-02-2018 at 04:58 AM.

  4. #4
    Senior Member OpenGL Guru
    Join Date
    Jun 2013
    Posts
    2,926
    Quote Originally Posted by duzenko View Post
    Thanks. Can you tell me how to sample from the nth mipmap of a samplerCubeShadow using textureGrad()? I.e. what ddx/ddy values do I pass for the nth mipmap?

    1.0*(1<<mipMapNo)/screen_width?
    That would be about right for a 2D texture (except that it should use the texture size, not the screen size). But for a cube map, you're passing 3D vectors which will be mapped onto one of the faces. Or possibly more than one. I'd suggest using vectors which are perpendicular to (1,1,1) so they have the same magnitude regardless of the face onto which they're projected. [√3+3,√3-3,-2√3]/6 and [√3-3,√3+3,-2√3]/6 satisfy this requirement (and are mutually perpendicular, and have unit length). You'd need to determine the constant factor experimentally.

    But it's far from certain that it's possible to reliably select a specific mipmap level this way. If your mipmap levels contain completely different data (i.e. they aren't actually mipmaps but distinct textures), you may just have to use a plain cube map and perform the depth comparison and filtering yourself.

Posting Permissions

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