mgsx-dev / gdx-gltf

GLTF 2.0 3D format support and PBR shader implementation for LibGDX
Apache License 2.0
214 stars 50 forks source link

Fix Cascaded Shadow Maps on WebGL #126

Closed MonstrousSoftware closed 4 months ago

MonstrousSoftware commented 4 months ago

The CascadedShadowMaps (CSM) don't work on the gdx-teavm platform, the application hangs due to errors GL_INVALID_OPERATION: Uniform type does not match uniform method.

One of the reasons is that WebGL does not allow setting uniforms which were not explicitly fetched, so it is not valid to use integer arithmetic to iterate through an array, e.g. . program.setUniformi(u_csmSamplers + i, unit);

Another reason is that even with the above caveat, setting elements of a uniform array of sampler2d, does not appear to work (apart from element 0). Using individual sampler2d uniforms does work (and there is already a limitation in place that no more than 8 cascades are supported).

The issue could be solved through minor changes in PBRShader.java and shadows.glsl.

See recent discussion on libgdx discord in the gdx-TeaVM thread and a demo of the fix at https://github.com/MonstrousSoftware/CascadedShadows

Presumably this will also fix the issue for the html/GWT platform but this has not been tested.

MonstrousSoftware commented 4 months ago

It also fixes the issue for html/GWT.

mgsx-dev commented 4 months ago

fixed by https://github.com/mgsx-dev/gdx-gltf/issues/127