From 0f54a82e3be0d2a21a23f5455d302443cfaafaca Mon Sep 17 00:00:00 2001 From: Robert Swain Date: Fri, 27 Oct 2023 03:35:19 +0200 Subject: [PATCH] Fix sampling of diffuse env map texture with non-uniform control flow (#10276) # Objective - `deferred_rendering` and `load_gltf` fail in WebGPU builds due to textureSample() being called on the diffuse environment map texture after non-uniform control flow ## Solution - The diffuse environment map texture only has one mip, so use `textureSampleLevel(..., 0.0)` to sample that mip and not require UV gradient calculation. --- crates/bevy_pbr/src/environment_map/environment_map.wgsl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/bevy_pbr/src/environment_map/environment_map.wgsl b/crates/bevy_pbr/src/environment_map/environment_map.wgsl index f188a578e4..0b05e352c2 100644 --- a/crates/bevy_pbr/src/environment_map/environment_map.wgsl +++ b/crates/bevy_pbr/src/environment_map/environment_map.wgsl @@ -22,7 +22,7 @@ fn environment_map_light( // Technically we could use textureNumLevels(environment_map_specular) - 1 here, but we use a uniform // because textureNumLevels() does not work on WebGL2 let radiance_level = perceptual_roughness * f32(bindings::lights.environment_map_smallest_specular_mip_level); - let irradiance = textureSample(bindings::environment_map_diffuse, bindings::environment_map_sampler, vec3(N.xy, -N.z)).rgb; + let irradiance = textureSampleLevel(bindings::environment_map_diffuse, bindings::environment_map_sampler, vec3(N.xy, -N.z), 0.0).rgb; let radiance = textureSampleLevel(bindings::environment_map_specular, bindings::environment_map_sampler, vec3(R.xy, -R.z), radiance_level).rgb; // No real world material has specular values under 0.02, so we use this range as a