From d90c65d25fa66fe6f8ace16977bb440ac5f6fb49 Mon Sep 17 00:00:00 2001 From: TotalKrill Date: Thu, 29 Jun 2023 06:32:04 +0200 Subject: [PATCH] Fix WebGL mode for Adreno GPUs (#8508) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit # Objective - This fixes a crash when loading shaders, when running an Adreno GPU and using WebGL mode. - Fixes #8506 - Fixes #8047 ## Solution - The shader pbr_functions.wgsl, will fail in apply_fog function, trying to access values that are null on Adreno chipsets using WebGL, these devices are commonly found in android handheld devices. --------- Co-authored-by: Carter Anderson Co-authored-by: François --- crates/bevy_pbr/src/render/light.rs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/crates/bevy_pbr/src/render/light.rs b/crates/bevy_pbr/src/render/light.rs index 23e866422d709..00beb05b5e91f 100644 --- a/crates/bevy_pbr/src/render/light.rs +++ b/crates/bevy_pbr/src/render/light.rs @@ -216,6 +216,12 @@ pub struct GpuLights { // NOTE: this must be kept in sync with the same constants in pbr.frag pub const MAX_UNIFORM_BUFFER_POINT_LIGHTS: usize = 256; + +//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. +#[cfg(all(feature = "webgl", target_arch = "wasm32"))] +pub const MAX_DIRECTIONAL_LIGHTS: usize = 1; +#[cfg(any(not(feature = "webgl"), not(target_arch = "wasm32")))] pub const MAX_DIRECTIONAL_LIGHTS: usize = 10; #[cfg(any(not(feature = "webgl"), not(target_arch = "wasm32")))] pub const MAX_CASCADES_PER_LIGHT: usize = 4;