[Public WebGL] Indexing samplerCube(Shadow) causes shader compilation error.

Anton Sedov ([email protected]) [email protected]
Fri Jul 12 03:41:06 PDT 2019


Indexing samplerCube and samplerCubeShadow causes shader compilation error.

Consider the case below:

    #define LIGHTS_COUNT 4
    #define SHADOW_CASTERS_COUNT 3

    // Provides relations between shadow casters and lights
    uniform int shadowCastersMask[LIGHTS_COUNT];

    #ifdef GLES_3
        uniform highp samplerCubeShadow
shadowCastersSamplers[SHADOW_CASTERS_COUNT];
    #else
        uniform highp samplerCube
shadowCastersSamplers[SHADOW_CASTERS_COUNT];
    #endif

    ...

    for (int lightIndex = 0; lightIndex < LIGHTS_COUNT; ++lightIndex) {
        ...

        float shaded = 0.0;

        int shadowCasterIndex = shadowCastersMask[lightIndex];

        if (shadowCasterIndex == -1)
            continue;

        for (int samplingIndex = 0; samplingIndex < SHADOW_CASTERS_COUNT;
++samplingIndex) {
            if (samplingIndex != shadowCasterIndex) continue;

            float currentDepth = ...
            vec4 samplingVector = ...

    #ifdef GLES_3
            shaded = 1.0 - texture(shadowCastersSamplers[samplingIndex],
samplingVector);
    #else
            float closestDepth =
textureCube(shadowCastersSamplers[samplingIndex], vec3(samplingVector)).r;
            shaded = currentDepth > closestDepth ? 1.0 : 0.0;
    #endif
            break;
        }

        ...

        diffuseColor *= 1.0 - shaded;
        specularColor *= 1.0 - shaded;

        ...
    }

When you will try to compile the code above on android browser with WebGL 2
rendering context enabled you get:

    'samplerCubeShadow' : requires extension GL_EXT_gpu_shader5 to be
enabled
    '[' :  indexing into a sampler array using a non-constant expression is
not permitted

The same code works perfect on PC with WebGL 1 / WebGL 2 context, but on
android browsers with WebGL 1 rendering context only.

*Note that replacing 'samplerCubeShadow' by 'samplerCube' doesn't change
nothing.*
As you can see the code valid on WebGL 1 rendering context doesn't work on
second context.
Looks like a bug, isn't it?

Chrome version is 75.0.3770.101. Firefox version is 68.0.
Android versions: 7.0, 8.0, 9.0.

-- 
_ATTENTION: *This message with all the attachments contains confidential 
information. Review, transfer, distribution, disclosure or use of received 
information is prohibited for the unauthorized recipient.*_
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://khronos.org/pipermail/public_webgl_khronos.org/attachments/20190712/946d3610/attachment.html>


More information about the public_webgl mailing list