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

Anton Sedov ([email protected]) [email protected]
Mon Jul 15 10:16:19 PDT 2019


Yes, solution with switch statement works fine. Thanks for advice.

сб, 13 июл. 2019 г. в 00:17, Ken Russell ([email protected]) <
[email protected]>:

> This limitation in OpenGL ES 3.00 is discussed in its specification
> available here:
> https://www.khronos.org/registry/OpenGL/index_es.php
>
> Section 12.30 "Dynamic Indexing" states:
>
> "Indexing of arrays of samplers by constant-index-expressions is supported
> in GLSL ES 1.00. A constant- index-expression is an expression formed from
> constant-expressions and certain loop indices, defined for a subset of loop
> constructs. Should this functionality be included in GLSL ES 3.00?
>
> RESOLUTION: No. Arrays of samplers may only be indexed by
> constant-integral-expressions."
>
> WebGL implementations should be doing a better job of rejecting this
> construct on all platforms. Thanks Jeff for putting together the test case.
>
> Anton, you could work around this using a switch statement and using a
> constant index into the array in each arm. Assuming all of the fragments
> for a given triangle go down the same path I think this won't cause
> divergent behavior in the shader and should be reasonably fast.
>
> -Ken
>
>
> On Fri, Jul 12, 2019 at 2:08 PM Jeff Gilbert ([email protected]) <
> [email protected]> wrote:
>
>>
>> I'm adding a test for this:
>> https://github.com/KhronosGroup/WebGL/pull/2910
>>
>> On Fri, Jul 12, 2019 at 1:45 PM Jeff Gilbert <[email protected]>
>> wrote:
>> >
>> > Unfortunately, the Android behavior is correct, and the desktop
>> > behavior is incorrect for essl300.
>> > I made a testcase: https://jsfiddle.net/7kbLg6v1/3/
>> >
>> > On Fri, Jul 12, 2019 at 3:42 AM Anton Sedov ([email protected])
>> > <[email protected]> wrote:
>> > >
>> > > 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.
>>
>> -----------------------------------------------------------
>> You are currently subscribed to [email protected]
>> To unsubscribe, send an email to [email protected] with
>> the following command in the body of your email:
>> unsubscribe public_webgl
>> -----------------------------------------------------------
>>
>>

-- 
_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/20190715/51bd0087/attachment.html>


More information about the public_webgl mailing list