From c589cd2b3916941a61bcb7a837797307ed95e20e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ma=CC=81te=CC=81=20Homolya?= Date: Thu, 17 Jul 2025 01:01:41 -0700 Subject: [PATCH] Remove LioghtProbe requirement from example and doc --- crates/bevy_pbr/src/light_probe/generate.rs | 11 ++--- examples/3d/reflection_probes.rs | 49 +++++++++------------ 2 files changed, 26 insertions(+), 34 deletions(-) diff --git a/crates/bevy_pbr/src/light_probe/generate.rs b/crates/bevy_pbr/src/light_probe/generate.rs index b85d4a339d..da528a5ce2 100644 --- a/crates/bevy_pbr/src/light_probe/generate.rs +++ b/crates/bevy_pbr/src/light_probe/generate.rs @@ -2,14 +2,15 @@ //! //! A *generated environment map* converts a single, high-resolution cubemap //! into the pair of diffuse and specular cubemaps required by the PBR -//! shader. Add [`bevy_light::GeneratedEnvironmentMapLight`] (together with -//! [`bevy_light::LightProbe`]) to an entity and Bevy will, each frame: +//! shader. Add [`bevy_light::GeneratedEnvironmentMapLight`] to a camera +//! and Bevy will, each frame, generate the diffuse and specular cubemaps +//! required by the PBR shader. //! -//! 1. Copy the base mip (level 0) of the source cubemap into an -//! intermediate storage texture. +//! 1. Copy the base mip (level 0) of the source cubemap into an intermediate +//! storage texture. //! 2. Generate mipmaps using single-pass down-sampling (SPD). //! 3. Convolve the mip chain twice: -//! * a Lambertian convolution for the 32 × 32 diffuse cubemap; +//! * a Lambertian convolution for the 32 × 32 diffuse cubemap //! * a GGX convolution, once per mip level, for the specular cubemap. //! //! The filtered results are then consumed exactly like the textures supplied diff --git a/examples/3d/reflection_probes.rs b/examples/3d/reflection_probes.rs index ce6c5a6cfc..470176f4c9 100644 --- a/examples/3d/reflection_probes.rs +++ b/examples/3d/reflection_probes.rs @@ -152,18 +152,6 @@ fn spawn_reflection_probe(commands: &mut Commands, cubemaps: &Cubemaps) { )); } -fn spawn_generated_environment_map(commands: &mut Commands, cubemaps: &Cubemaps) { - commands.spawn(( - LightProbe, - GeneratedEnvironmentMapLight { - environment_map: cubemaps.specular_environment_map.clone(), - intensity: 5000.0, - ..default() - }, - Transform::from_scale(Vec3::splat(2.0)), - )); -} - // Spawns the help text. fn spawn_text(commands: &mut Commands, app_status: &AppStatus) { // Create the text. @@ -202,7 +190,6 @@ fn add_environment_map_to_camera( fn change_reflection_type( mut commands: Commands, light_probe_query: Query>, - sky_box_query: Query>, camera_query: Query>, keyboard: Res>, mut app_status: ResMut, @@ -217,34 +204,38 @@ fn change_reflection_type( app_status.reflection_mode = ReflectionMode::try_from((app_status.reflection_mode as u32 + 1) % 3).unwrap(); - // Add or remove the light probe. + // Remove light probes for light_probe in light_probe_query.iter() { commands.entity(light_probe).despawn(); } - for skybox in sky_box_query.iter() { - commands.entity(skybox).remove::(); - } match app_status.reflection_mode { ReflectionMode::EnvironmentMap => {} ReflectionMode::ReflectionProbe => spawn_reflection_probe(&mut commands, &cubemaps), - ReflectionMode::GeneratedEnvironmentMap => { - spawn_generated_environment_map(&mut commands, &cubemaps); - } + ReflectionMode::GeneratedEnvironmentMap => {} } - // Add or remove the environment map from the camera. + // Update the environment-map components on the camera entity/entities for camera in camera_query.iter() { + // Remove any existing environment-map components + commands + .entity(camera) + .remove::<(EnvironmentMapLight, GeneratedEnvironmentMapLight)>(); + match app_status.reflection_mode { - ReflectionMode::EnvironmentMap - | ReflectionMode::ReflectionProbe - | ReflectionMode::GeneratedEnvironmentMap => { - let image = cubemaps.specular_environment_map.clone(); + // A baked or reflection-probe environment map + ReflectionMode::EnvironmentMap | ReflectionMode::ReflectionProbe => { commands .entity(camera) - .insert(create_camera_environment_map_light(&cubemaps)) - .insert(Skybox { - image, - brightness: 5000.0, + .insert(create_camera_environment_map_light(&cubemaps)); + } + + // GPU-filtered environment map generated at runtime + ReflectionMode::GeneratedEnvironmentMap => { + commands + .entity(camera) + .insert(GeneratedEnvironmentMapLight { + environment_map: cubemaps.specular_environment_map.clone(), + intensity: 5000.0, ..default() }); }