Skip to content

Commit ea15446

Browse files
ashivaram23mockersf
authored andcommitted
Fix binding in generated environment map downsampling pipeline (#21791)
# Objective When Bevy splits mip generation for environment maps into two passes due to limits, the second pass binds a view to the the original texture when it's supposed to be the 6th mip level of an intermediate one. This causes an error on WebGPU in browsers if that original texture doesn't already have mipmaps. This affects the atmosphere example on WebGPU, but there are other issues there too so it still won't work after this. ## Solution Create texture view from the texture in the `IntermediateTextures` component instead of in `RenderEnvironmentMap` ## Testing <details> <summary>Example that doesn't work on WebGPU before this (replace square.png with any power of 2 square image that doesn't store mipmaps)</summary> ```rust use bevy::prelude::*; fn main() { App::new() .add_plugins(DefaultPlugins) .add_systems(Startup, setup) .run(); } fn setup( mut commands: Commands, asset_server: Res<AssetServer>, mut meshes: ResMut<Assets<Mesh>>, mut materials: ResMut<Assets<StandardMaterial>>, ) { commands.spawn(( Camera3d::default(), Transform::from_xyz(0.0, 0.0, 5.0), GeneratedEnvironmentMapLight { environment_map: asset_server.load("square.png"), intensity: 1000.0, ..Default::default() }, )); commands.spawn(( Mesh3d(meshes.add(Sphere::new(1.0).mesh().build())), MeshMaterial3d(materials.add(StandardMaterial { perceptual_roughness: 0.1, metallic: 1.0, ..Default::default() })), )); } ``` </details>
1 parent 48556b7 commit ea15446

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

crates/bevy_pbr/src/light_probe/generate.rs

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -677,12 +677,16 @@ pub fn prepare_generated_environment_map_bind_groups(
677677
(bind_group.clone(), bind_group)
678678
} else {
679679
// Split path requires a separate view for mip6 input
680-
let input_env_map_second = env_map_texture.create_view(&TextureViewDescriptor {
681-
dimension: Some(TextureViewDimension::D2Array),
682-
base_mip_level: min(6, last_mip),
683-
mip_level_count: Some(1),
684-
..Default::default()
685-
});
680+
let input_env_map_second =
681+
textures
682+
.environment_map
683+
.texture
684+
.create_view(&TextureViewDescriptor {
685+
dimension: Some(TextureViewDimension::D2Array),
686+
base_mip_level: min(6, last_mip),
687+
mip_level_count: Some(1),
688+
..Default::default()
689+
});
686690

687691
// Split layout (current behavior)
688692
let first = render_device.create_bind_group(

0 commit comments

Comments
 (0)