Fix potential out-of-bounds access in pbr_functions.wgsl (#12585)

# Objective

- Fix a potential out-of-bounds access in the `pbr_functions.wgsl`
shader.

## Solution

- Correctly compute the `GpuLights::directional_lights` array length.

## Comments

I think this solves this comment in the code, but need someone to test
it:
```rust
//NOTE: When running bevy on Adreno GPU chipsets in WebGL, any value above 1 will result in a crash
// when loading the wgsl "pbr_functions.wgsl" in the function apply_fog.
```
This commit is contained in:
UkoeHB 2024-04-08 12:00:09 -05:00 committed by GitHub
parent 0c78bf3bb0
commit 2ee69807b1
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -991,7 +991,8 @@ pub fn prepare_lights(
cluster_factors_zw.y,
),
cluster_dimensions: clusters.dimensions.extend(n_clusters),
n_directional_lights: directional_lights.iter().len() as u32,
n_directional_lights: directional_lights.iter().len().min(MAX_DIRECTIONAL_LIGHTS)
as u32,
// spotlight shadow maps are stored in the directional light array, starting at num_directional_cascades_enabled.
// the spot lights themselves start in the light array at point_light_count. so to go from light
// index to shadow map index, we need to subtract point light count and add directional shadowmap count.