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?

[QUOTE=duzenko;1292428]
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?[/QUOTE]
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.

[QUOTE=GClements;1292430]textureGrad() accepts samplerCubeShadow, but calculating the derivatives which would select a particular LoD would require knowing which face will be used.
[/QUOTE]
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?

[QUOTE=duzenko;1292437]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?[/QUOTE]
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.