diff --git a/assets/environment_maps/goegap_road_2k.ktx2 b/assets/environment_maps/goegap_road_2k.ktx2 deleted file mode 100644 index 50bf6201d6..0000000000 Binary files a/assets/environment_maps/goegap_road_2k.ktx2 and /dev/null differ diff --git a/assets/environment_maps/spiaggia_di_mondello_2k_diffuse.ktx2 b/assets/environment_maps/spiaggia_di_mondello_2k_diffuse.ktx2 new file mode 100644 index 0000000000..ea522467ab Binary files /dev/null and b/assets/environment_maps/spiaggia_di_mondello_2k_diffuse.ktx2 differ diff --git a/assets/environment_maps/spiaggia_di_mondello_2k_skybox.ktx2 b/assets/environment_maps/spiaggia_di_mondello_2k_skybox.ktx2 new file mode 100644 index 0000000000..79585af16b Binary files /dev/null and b/assets/environment_maps/spiaggia_di_mondello_2k_skybox.ktx2 differ diff --git a/assets/environment_maps/spiaggia_di_mondello_2k_specular.ktx2 b/assets/environment_maps/spiaggia_di_mondello_2k_specular.ktx2 new file mode 100644 index 0000000000..d13f575d23 Binary files /dev/null and b/assets/environment_maps/spiaggia_di_mondello_2k_specular.ktx2 differ diff --git a/crates/bevy_pbr/src/light_probe/environment_filter.wgsl b/crates/bevy_pbr/src/light_probe/environment_filter.wgsl index 0b576b6305..addc2c1e55 100644 --- a/crates/bevy_pbr/src/light_probe/environment_filter.wgsl +++ b/crates/bevy_pbr/src/light_probe/environment_filter.wgsl @@ -140,7 +140,7 @@ fn importance_sample_ggx(xi: vec2f, roughness: f32, normal: vec3f) -> vec3f { let a = roughness * roughness; // Sample in spherical coordinates - let phi = 2.0 * PI * xi.x; + let phi = PI_2 * xi.x; // GGX mapping from uniform random to GGX distribution let cos_theta = fast_sqrt((1.0 - xi.y) / (1.0 + (a * a - 1.0) * xi.y)); @@ -343,9 +343,6 @@ fn generate_irradiance_map(@builtin(global_invocation_id) global_id: vec3u) { // Normalize by total weight irradiance = irradiance / total_weight; - // Scale by PI to account for the Lambert BRDF normalization factor - irradiance *= PI; - // Reverse tonemap to restore HDR range irradiance = reverse_tonemap(irradiance); diff --git a/crates/bevy_pbr/src/light_probe/generate.rs b/crates/bevy_pbr/src/light_probe/generate.rs index 71f6ab2c40..dbff008e86 100644 --- a/crates/bevy_pbr/src/light_probe/generate.rs +++ b/crates/bevy_pbr/src/light_probe/generate.rs @@ -335,7 +335,7 @@ impl Default for GeneratedEnvironmentMapLight { intensity: 0.0, rotation: Quat::IDENTITY, affects_lightmapped_mesh_diffuse: true, - white_point: 2.0, + white_point: 1.0, } } } @@ -568,20 +568,10 @@ pub fn prepare_generator_bind_groups( let mut radiance_bind_groups = Vec::with_capacity(num_mips); for mip in 0..num_mips { - let roughness = mip as f32 / (num_mips - 1) as f32; - - // For higher roughness values, use importance sampling with optimized sample count - let sample_count = if roughness < 0.01 { - 1 // Mirror reflection - } else if roughness < 0.25 { - 16 - } else if roughness < 0.5 { - 32 - } else if roughness < 0.75 { - 64 - } else { - 128 - }; + // Calculate roughness from 0.0 (mip 0) to 0.889 (mip 8) + // We don't need roughness=1.0 as a mip level because it's handled by the separate diffuse irradiance map + let roughness = mip as f32 / num_mips as f32; + let sample_count = 32u32 * 2u32.pow((roughness * 4.0) as u32); let radiance_constants = FilteringConstants { mip_level: mip as f32, diff --git a/examples/3d/reflection_probes.rs b/examples/3d/reflection_probes.rs index 1c9fb97937..33e73e19dd 100644 --- a/examples/3d/reflection_probes.rs +++ b/examples/3d/reflection_probes.rs @@ -167,6 +167,15 @@ fn spawn_generated_environment_map(commands: &mut Commands, cubemaps: &Cubemaps) }, Transform::from_scale(Vec3::splat(2.0)), )); + + // spawn directional light + commands.spawn(( + DirectionalLight { + illuminance: 30_000.0, + ..default() + }, + Transform::from_xyz(1.0, 0.5, 0.6).looking_at(Vec3::ZERO, Vec3::Y), + )); } // Spawns the help text. @@ -209,6 +218,7 @@ fn change_reflection_type( light_probe_query: Query>, sky_box_query: Query>, camera_query: Query>, + directional_light_query: Query>, keyboard: Res>, mut app_status: ResMut, cubemaps: Res, @@ -229,6 +239,9 @@ fn change_reflection_type( for skybox in sky_box_query.iter() { commands.entity(skybox).remove::(); } + for directional_light in directional_light_query.iter() { + commands.entity(directional_light).despawn(); + } match app_status.reflection_mode { ReflectionMode::None | ReflectionMode::EnvironmentMap => {} ReflectionMode::ReflectionProbe => spawn_reflection_probe(&mut commands, &cubemaps), @@ -369,7 +382,8 @@ impl FromWorld for Cubemaps { specular_reflection_probe: world .load_asset("environment_maps/cubes_reflection_probe_specular_rgb9e5_zstd.ktx2"), specular_environment_map: specular_map.clone(), - unfiltered_environment_map: world.load_asset("environment_maps/goegap_road_2k.ktx2"), + unfiltered_environment_map: world + .load_asset("environment_maps/spiaggia_di_mondello_2k_skybox.ktx2"), skybox: specular_map, } }