Skip to content

Commit 3d99663

Browse files
authored
Revert "Implement minimal reflection probes. (#10057)" (#11307)
# Objective - Fix working on macOS, iOS, Android on main - Fixes #11281 - Fixes #11282 - Fixes #11283 - Fixes #11299 ## Solution - Revert #10057
1 parent 64a15f1 commit 3d99663

File tree

24 files changed

+249
-1523
lines changed

24 files changed

+249
-1523
lines changed

Cargo.toml

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2456,17 +2456,6 @@ name = "fallback_image"
24562456
path = "examples/shader/fallback_image.rs"
24572457
doc-scrape-examples = true
24582458

2459-
[[example]]
2460-
name = "reflection_probes"
2461-
path = "examples/3d/reflection_probes.rs"
2462-
doc-scrape-examples = true
2463-
2464-
[package.metadata.example.reflection_probes]
2465-
name = "Reflection Probes"
2466-
description = "Demonstrates reflection probes"
2467-
category = "3D Rendering"
2468-
wasm = false
2469-
24702459
[package.metadata.example.fallback_image]
24712460
hidden = true
24722461

Binary file not shown.

assets/models/cubes/Cubes.glb

-6.32 KB
Binary file not shown.

crates/bevy_core_pipeline/src/tonemapping/tonemapping_shared.wgsl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
@group(0) @binding(3) var dt_lut_texture: texture_3d<f32>;
88
@group(0) @binding(4) var dt_lut_sampler: sampler;
99
#else
10-
@group(0) @binding(16) var dt_lut_texture: texture_3d<f32>;
11-
@group(0) @binding(17) var dt_lut_sampler: sampler;
10+
@group(0) @binding(15) var dt_lut_texture: texture_3d<f32>;
11+
@group(0) @binding(16) var dt_lut_sampler: sampler;
1212
#endif
1313

1414
fn sample_current_lut(p: vec3<f32>) -> vec3<f32> {

crates/bevy_internal/Cargo.toml

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,7 @@ symphonia-vorbis = ["bevy_audio/symphonia-vorbis"]
5858
symphonia-wav = ["bevy_audio/symphonia-wav"]
5959

6060
# Shader formats
61-
shader_format_glsl = [
62-
"bevy_render/shader_format_glsl",
63-
"bevy_pbr?/shader_format_glsl",
64-
]
61+
shader_format_glsl = ["bevy_render/shader_format_glsl"]
6562
shader_format_spirv = ["bevy_render/shader_format_spirv"]
6663

6764
serialize = [

crates/bevy_pbr/Cargo.toml

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ keywords = ["bevy"]
1010

1111
[features]
1212
webgl = []
13-
shader_format_glsl = ["naga_oil/glsl"]
1413
pbr_transmission_textures = []
1514

1615
[dependencies]
@@ -35,17 +34,8 @@ fixedbitset = "0.4"
3534
# direct dependency required for derive macro
3635
bytemuck = { version = "1", features = ["derive"] }
3736
radsort = "0.1"
38-
smallvec = "1.6"
37+
naga_oil = "0.11"
3938
thread_local = "1.0"
4039

41-
[target.'cfg(target_arch = "wasm32")'.dependencies]
42-
naga_oil = { version = "0.11" }
43-
44-
[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
45-
# Omit the `glsl` feature in non-WebAssembly by default.
46-
naga_oil = { version = "0.11", default-features = false, features = [
47-
"test_shader",
48-
] }
49-
5040
[lints]
5141
workspace = true

crates/bevy_pbr/src/deferred/mod.rs

Lines changed: 24 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
1-
use crate::{
2-
environment_map::RenderViewEnvironmentMaps, MeshPipeline, MeshViewBindGroup,
3-
ScreenSpaceAmbientOcclusionSettings, ViewLightProbesUniformOffset,
4-
};
1+
use crate::{MeshPipeline, MeshViewBindGroup, ScreenSpaceAmbientOcclusionSettings};
52
use bevy_app::prelude::*;
63
use bevy_asset::{load_internal_asset, Handle};
74
use bevy_core_pipeline::{
@@ -17,17 +14,25 @@ use bevy_render::{
1714
extract_component::{
1815
ComponentUniforms, ExtractComponent, ExtractComponentPlugin, UniformComponentPlugin,
1916
},
20-
render_graph::{NodeRunError, RenderGraphApp, RenderGraphContext, ViewNode, ViewNodeRunner},
21-
render_resource::binding_types::uniform_buffer,
22-
render_resource::*,
17+
render_asset::RenderAssets,
18+
render_graph::{NodeRunError, RenderGraphContext, ViewNode, ViewNodeRunner},
19+
render_resource::{
20+
binding_types::uniform_buffer, Operations, PipelineCache, RenderPassDescriptor,
21+
},
2322
renderer::{RenderContext, RenderDevice},
24-
texture::BevyDefault,
25-
view::{ExtractedView, ViewTarget, ViewUniformOffset},
26-
Render, RenderApp, RenderSet,
23+
texture::Image,
24+
view::{ViewTarget, ViewUniformOffset},
25+
Render, RenderSet,
26+
};
27+
28+
use bevy_render::{
29+
render_graph::RenderGraphApp, render_resource::*, texture::BevyDefault, view::ExtractedView,
30+
RenderApp,
2731
};
2832

2933
use crate::{
30-
MeshPipelineKey, ShadowFilteringMethod, ViewFogUniformOffset, ViewLightsUniformOffset,
34+
EnvironmentMapLight, MeshPipelineKey, ShadowFilteringMethod, ViewFogUniformOffset,
35+
ViewLightsUniformOffset,
3136
};
3237

3338
pub struct DeferredPbrLightingPlugin;
@@ -146,7 +151,6 @@ impl ViewNode for DeferredOpaquePass3dPbrLightingNode {
146151
&'static ViewUniformOffset,
147152
&'static ViewLightsUniformOffset,
148153
&'static ViewFogUniformOffset,
149-
&'static ViewLightProbesUniformOffset,
150154
&'static MeshViewBindGroup,
151155
&'static ViewTarget,
152156
&'static DeferredLightingIdDepthTexture,
@@ -161,7 +165,6 @@ impl ViewNode for DeferredOpaquePass3dPbrLightingNode {
161165
view_uniform_offset,
162166
view_lights_offset,
163167
view_fog_offset,
164-
view_light_probes_offset,
165168
mesh_view_bind_group,
166169
target,
167170
deferred_lighting_id_depth_texture,
@@ -215,7 +218,6 @@ impl ViewNode for DeferredOpaquePass3dPbrLightingNode {
215218
view_uniform_offset.offset,
216219
view_lights_offset.offset,
217220
view_fog_offset.offset,
218-
**view_light_probes_offset,
219221
],
220222
);
221223
render_pass.set_bind_group(1, &bind_group_1, &[]);
@@ -401,27 +403,28 @@ pub fn prepare_deferred_lighting_pipelines(
401403
&ExtractedView,
402404
Option<&Tonemapping>,
403405
Option<&DebandDither>,
406+
Option<&EnvironmentMapLight>,
404407
Option<&ShadowFilteringMethod>,
405408
Has<ScreenSpaceAmbientOcclusionSettings>,
406409
(
407410
Has<NormalPrepass>,
408411
Has<DepthPrepass>,
409412
Has<MotionVectorPrepass>,
410413
),
411-
Has<RenderViewEnvironmentMaps>,
412414
),
413415
With<DeferredPrepass>,
414416
>,
417+
images: Res<RenderAssets<Image>>,
415418
) {
416419
for (
417420
entity,
418421
view,
419422
tonemapping,
420423
dither,
424+
environment_map,
421425
shadow_filter_method,
422426
ssao,
423427
(normal_prepass, depth_prepass, motion_vector_prepass),
424-
has_environment_maps,
425428
) in &views
426429
{
427430
let mut view_key = MeshPipelineKey::from_hdr(view.hdr);
@@ -468,10 +471,11 @@ pub fn prepare_deferred_lighting_pipelines(
468471
view_key |= MeshPipelineKey::SCREEN_SPACE_AMBIENT_OCCLUSION;
469472
}
470473

471-
// We don't need to check to see whether the environment map is loaded
472-
// because [`gather_light_probes`] already checked that for us before
473-
// adding the [`RenderViewEnvironmentMaps`] component.
474-
if has_environment_maps {
474+
let environment_map_loaded = match environment_map {
475+
Some(environment_map) => environment_map.is_loaded(&images),
476+
None => false,
477+
};
478+
if environment_map_loaded {
475479
view_key |= MeshPipelineKey::ENVIRONMENT_MAP;
476480
}
477481

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
#define_import_path bevy_pbr::environment_map
2+
3+
#import bevy_pbr::mesh_view_bindings as bindings;
4+
5+
struct EnvironmentMapLight {
6+
diffuse: vec3<f32>,
7+
specular: vec3<f32>,
8+
};
9+
10+
fn environment_map_light(
11+
perceptual_roughness: f32,
12+
roughness: f32,
13+
diffuse_color: vec3<f32>,
14+
NdotV: f32,
15+
f_ab: vec2<f32>,
16+
N: vec3<f32>,
17+
R: vec3<f32>,
18+
F0: vec3<f32>,
19+
) -> EnvironmentMapLight {
20+
21+
// Split-sum approximation for image based lighting: https://cdn2.unrealengine.com/Resources/files/2013SiggraphPresentationsNotes-26915738.pdf
22+
// Technically we could use textureNumLevels(environment_map_specular) - 1 here, but we use a uniform
23+
// because textureNumLevels() does not work on WebGL2
24+
let radiance_level = perceptual_roughness * f32(bindings::lights.environment_map_smallest_specular_mip_level);
25+
let irradiance = textureSampleLevel(bindings::environment_map_diffuse, bindings::environment_map_sampler, vec3(N.xy, -N.z), 0.0).rgb;
26+
let radiance = textureSampleLevel(bindings::environment_map_specular, bindings::environment_map_sampler, vec3(R.xy, -R.z), radiance_level).rgb;
27+
28+
// No real world material has specular values under 0.02, so we use this range as a
29+
// "pre-baked specular occlusion" that extinguishes the fresnel term, for artistic control.
30+
// See: https://google.github.io/filament/Filament.html#specularocclusion
31+
let specular_occlusion = saturate(dot(F0, vec3(50.0 * 0.33)));
32+
33+
// Multiscattering approximation: https://www.jcgt.org/published/0008/01/03/paper.pdf
34+
// Useful reference: https://bruop.github.io/ibl
35+
let Fr = max(vec3(1.0 - roughness), F0) - F0;
36+
let kS = F0 + Fr * pow(1.0 - NdotV, 5.0);
37+
let Ess = f_ab.x + f_ab.y;
38+
let FssEss = kS * Ess * specular_occlusion;
39+
let Ems = 1.0 - Ess;
40+
let Favg = F0 + (1.0 - F0) / 21.0;
41+
let Fms = FssEss * Favg / (1.0 - Ems * Favg);
42+
let FmsEms = Fms * Ems;
43+
let Edss = 1.0 - (FssEss + FmsEms);
44+
let kD = diffuse_color * Edss;
45+
46+
var out: EnvironmentMapLight;
47+
out.diffuse = (FmsEms + kD) * irradiance;
48+
out.specular = FssEss * radiance;
49+
return out;
50+
}
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
use bevy_app::{App, Plugin};
2+
use bevy_asset::{load_internal_asset, Handle};
3+
use bevy_core_pipeline::prelude::Camera3d;
4+
use bevy_ecs::{prelude::Component, query::With};
5+
use bevy_reflect::Reflect;
6+
use bevy_render::{
7+
extract_component::{ExtractComponent, ExtractComponentPlugin},
8+
render_asset::RenderAssets,
9+
render_resource::{
10+
binding_types::{sampler, texture_cube},
11+
*,
12+
},
13+
texture::{FallbackImageCubemap, Image},
14+
};
15+
16+
pub const ENVIRONMENT_MAP_SHADER_HANDLE: Handle<Shader> =
17+
Handle::weak_from_u128(154476556247605696);
18+
19+
pub struct EnvironmentMapPlugin;
20+
21+
impl Plugin for EnvironmentMapPlugin {
22+
fn build(&self, app: &mut App) {
23+
load_internal_asset!(
24+
app,
25+
ENVIRONMENT_MAP_SHADER_HANDLE,
26+
"environment_map.wgsl",
27+
Shader::from_wgsl
28+
);
29+
30+
app.register_type::<EnvironmentMapLight>()
31+
.add_plugins(ExtractComponentPlugin::<EnvironmentMapLight>::default());
32+
}
33+
}
34+
35+
/// Environment map based ambient lighting representing light from distant scenery.
36+
///
37+
/// When added to a 3D camera, this component adds indirect light
38+
/// to every point of the scene (including inside, enclosed areas) based on
39+
/// an environment cubemap texture. This is similar to [`crate::AmbientLight`], but
40+
/// higher quality, and is intended for outdoor scenes.
41+
///
42+
/// The environment map must be prefiltered into a diffuse and specular cubemap based on the
43+
/// [split-sum approximation](https://cdn2.unrealengine.com/Resources/files/2013SiggraphPresentationsNotes-26915738.pdf).
44+
///
45+
/// To prefilter your environment map, you can use `KhronosGroup`'s [glTF-IBL-Sampler](https://github.com/KhronosGroup/glTF-IBL-Sampler).
46+
/// The diffuse map uses the Lambertian distribution, and the specular map uses the GGX distribution.
47+
///
48+
/// `KhronosGroup` also has several prefiltered environment maps that can be found [here](https://github.com/KhronosGroup/glTF-Sample-Environments).
49+
#[derive(Component, Reflect, Clone, ExtractComponent)]
50+
#[extract_component_filter(With<Camera3d>)]
51+
pub struct EnvironmentMapLight {
52+
pub diffuse_map: Handle<Image>,
53+
pub specular_map: Handle<Image>,
54+
}
55+
56+
impl EnvironmentMapLight {
57+
/// Whether or not all textures necessary to use the environment map
58+
/// have been loaded by the asset server.
59+
pub fn is_loaded(&self, images: &RenderAssets<Image>) -> bool {
60+
images.get(&self.diffuse_map).is_some() && images.get(&self.specular_map).is_some()
61+
}
62+
}
63+
64+
pub fn get_bindings<'a>(
65+
environment_map_light: Option<&EnvironmentMapLight>,
66+
images: &'a RenderAssets<Image>,
67+
fallback_image_cubemap: &'a FallbackImageCubemap,
68+
) -> (&'a TextureView, &'a TextureView, &'a Sampler) {
69+
let (diffuse_map, specular_map) = match (
70+
environment_map_light.and_then(|env_map| images.get(&env_map.diffuse_map)),
71+
environment_map_light.and_then(|env_map| images.get(&env_map.specular_map)),
72+
) {
73+
(Some(diffuse_map), Some(specular_map)) => {
74+
(&diffuse_map.texture_view, &specular_map.texture_view)
75+
}
76+
_ => (
77+
&fallback_image_cubemap.texture_view,
78+
&fallback_image_cubemap.texture_view,
79+
),
80+
};
81+
82+
(diffuse_map, specular_map, &fallback_image_cubemap.sampler)
83+
}
84+
85+
pub fn get_bind_group_layout_entries() -> [BindGroupLayoutEntryBuilder; 3] {
86+
[
87+
texture_cube(TextureSampleType::Float { filterable: true }),
88+
texture_cube(TextureSampleType::Float { filterable: true }),
89+
sampler(SamplerBindingType::Filtering),
90+
]
91+
}

crates/bevy_pbr/src/lib.rs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@ pub mod wireframe;
33
mod alpha;
44
mod bundle;
55
pub mod deferred;
6+
mod environment_map;
67
mod extended_material;
78
mod fog;
89
mod light;
9-
mod light_probe;
1010
mod lightmap;
1111
mod material;
1212
mod parallax;
@@ -17,10 +17,10 @@ mod ssao;
1717

1818
pub use alpha::*;
1919
pub use bundle::*;
20+
pub use environment_map::EnvironmentMapLight;
2021
pub use extended_material::*;
2122
pub use fog::*;
2223
pub use light::*;
23-
pub use light_probe::*;
2424
pub use lightmap::*;
2525
pub use material::*;
2626
pub use parallax::*;
@@ -37,12 +37,9 @@ pub mod prelude {
3737
DirectionalLightBundle, MaterialMeshBundle, PbrBundle, PointLightBundle,
3838
SpotLightBundle,
3939
},
40+
environment_map::EnvironmentMapLight,
4041
fog::{FogFalloff, FogSettings},
4142
light::{AmbientLight, DirectionalLight, PointLight, SpotLight},
42-
light_probe::{
43-
environment_map::{EnvironmentMapLight, ReflectionProbeBundle},
44-
LightProbe,
45-
},
4643
material::{Material, MaterialPlugin},
4744
parallax::ParallaxMappingMethod,
4845
pbr_material::StandardMaterial,
@@ -74,6 +71,7 @@ use bevy_render::{
7471
ExtractSchedule, Render, RenderApp, RenderSet,
7572
};
7673
use bevy_transform::TransformSystem;
74+
use environment_map::EnvironmentMapPlugin;
7775

7876
use crate::deferred::DeferredPbrLightingPlugin;
7977

@@ -257,12 +255,12 @@ impl Plugin for PbrPlugin {
257255
..Default::default()
258256
},
259257
ScreenSpaceAmbientOcclusionPlugin,
258+
EnvironmentMapPlugin,
260259
ExtractResourcePlugin::<AmbientLight>::default(),
261260
FogPlugin,
262261
ExtractResourcePlugin::<DefaultOpaqueRendererMethod>::default(),
263262
ExtractComponentPlugin::<ShadowFilteringMethod>::default(),
264263
LightmapPlugin,
265-
LightProbePlugin,
266264
))
267265
.configure_sets(
268266
PostUpdate,

0 commit comments

Comments
 (0)