bevy/crates/bevy_pbr/src
Máté Homolya a616ffa8ac
Web support for atmosphere (#18582)
# Objective

Add web support to atmosphere by gating dual source blending and using a
macro to determine the target platform.
The main objective of this PR is to ensure that users of Bevy's
atmosphere feature can also run it in a web-based context where WebGPU
support is enabled.

## Solution

- Make use of the `#[cfg(not(target_arch = "wasm32"))]` macro to gate
the dual source blending, as this is not (yet) supported in web
browsers.
- Rename the function `sample_sun_illuminance` to `sample_sun_radiance`
and move calls out of conditionals to ensure the shader compiles and
runs in both native and web-based contexts.
- Moved the multiplication of the transmittance out when calculating the
sun color, because calling the `sample_sun_illuminance` function was
causing issues in web. Overall this results in cleaner code and more
readable.

## Testing

- Tested by building a wasm target and loading it in a web page with
Vite dev server using `mate-h/bevy-webgpu` repo template.
- Tested the native build with `cargo run --example atmosphere` to
ensure it still works with dual source blending.

---

## Showcase

Screenshots show the atmosphere example running in two different
contexts:

<img width="1281" alt="atmosphere-web-showcase"
src="https://github.com/user-attachments/assets/40b1ee91-89ae-41a6-8189-89630d1ca1a6"
/>

---------

Co-authored-by: JMS55 <47158642+JMS55@users.noreply.github.com>
2025-04-06 20:06:55 +00:00
..
atmosphere Web support for atmosphere (#18582) 2025-04-06 20:06:55 +00:00
cluster reexport entity set collections in entity module (#18413) 2025-03-30 03:51:14 +00:00
decal reexport entity set collections in entity module (#18413) 2025-03-30 03:51:14 +00:00
deferred Add required shader defs for environment map binding arrays in deferred (#18634) 2025-03-31 18:07:54 +00:00
light reexport entity set collections in entity module (#18413) 2025-03-30 03:51:14 +00:00
light_probe bevy_reflect: Add clone registrations project-wide (#18307) 2025-03-17 18:32:35 +00:00
lightmap bevy_reflect: Add clone registrations project-wide (#18307) 2025-03-17 18:32:35 +00:00
meshlet Fix mesh extraction for meshes without associated material. (#18631) 2025-03-31 18:09:27 +00:00
prepass Fix motion blur on skinned meshes (#18712) 2025-04-04 22:36:03 +00:00
render Fix many_foxes + motion blur = crash on WebGL (#18715) 2025-04-06 17:51:22 +00:00
ssao Add bevy_anti_aliasing (#18323) 2025-03-19 18:40:32 +00:00
ssr bevy_reflect: Add clone registrations project-wide (#18307) 2025-03-17 18:32:35 +00:00
volumetric_fog bevy_reflect: Add clone registrations project-wide (#18307) 2025-03-17 18:32:35 +00:00
components.rs reexport entity set collections in entity module (#18413) 2025-03-30 03:51:14 +00:00
extended_material.rs bevy_reflect: Add clone registrations project-wide (#18307) 2025-03-17 18:32:35 +00:00
fog.rs bevy_reflect: Add clone registrations project-wide (#18307) 2025-03-17 18:32:35 +00:00
lib.rs Add missing system ordering constraint to prepare_lights (#18308) 2025-03-15 22:57:52 +00:00
material_bind_groups.rs bevy_reflect: Add clone registrations project-wide (#18307) 2025-03-17 18:32:35 +00:00
material.rs Fix motion blur on skinned meshes (#18712) 2025-04-04 22:36:03 +00:00
mesh_material.rs bevy_reflect: Add clone registrations project-wide (#18307) 2025-03-17 18:32:35 +00:00
parallax.rs bevy_reflect: Add clone registrations project-wide (#18307) 2025-03-17 18:32:35 +00:00
pbr_material.rs Make bindings behind pbr_specular_textures flag consistent with other gated fields (#18645) 2025-03-31 18:49:12 +00:00
wireframe.rs bevy_reflect: Add clone registrations project-wide (#18307) 2025-03-17 18:32:35 +00:00