Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement minimal reflection probes (fixed macOS, iOS, and Android). #11366

Merged
merged 64 commits into from
Jan 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
64 commits
Select commit Hold shift + click to select a range
ec71332
WIP reflection probes.
pcwalton Oct 9, 2023
3fcb91f
Remove mipmap generation
pcwalton Oct 11, 2023
1abe709
Implement view reflection probes and reflection probe selection
pcwalton Oct 12, 2023
9f2a33e
Add an example. Still need the actual maps
pcwalton Oct 12, 2023
5d9b49c
Revert changes to `pbr` example
pcwalton Oct 12, 2023
3179368
Remove obsolete comment
pcwalton Oct 12, 2023
8c8478b
Improve error messages a bit
pcwalton Oct 14, 2023
d61d305
Merge remote-tracking branch 'origin/main' into reflection-probes
pcwalton Oct 14, 2023
70643e1
Get reflection probes demo mostly working
pcwalton Oct 14, 2023
77c6510
Compress the textures
pcwalton Oct 15, 2023
9948839
Document everything and clean up
pcwalton Oct 15, 2023
cb739cf
Better documentation for light probes
pcwalton Oct 15, 2023
8cf4e7c
Update examples README
pcwalton Oct 15, 2023
f9c79eb
Update to be deferred compatible
pcwalton Oct 15, 2023
8240e1f
Various fixes
pcwalton Oct 16, 2023
6c8b9a2
Improve documentation
pcwalton Oct 16, 2023
d6fc1f8
Remove unused texture
pcwalton Oct 16, 2023
05cc37e
Fix compile error
pcwalton Oct 16, 2023
f55a372
Merge remote-tracking branch 'origin/main' into reflection-probes
pcwalton Oct 19, 2023
2b7df6c
Merge remote-tracking branch 'origin/main' into reflection-probes
pcwalton Nov 26, 2023
fcbfc04
WIP, not uploaded
pcwalton Nov 27, 2023
6220079
Merge remote-tracking branch 'origin/main' into reflection-probes
pcwalton Dec 11, 2023
46fff90
WIP, not pushed yet
pcwalton Dec 11, 2023
47b40a5
Get things mostly working again
pcwalton Dec 13, 2023
fccaf3c
Get things working, including without binding arrays
pcwalton Dec 15, 2023
6cc256f
Address some review comments
pcwalton Dec 16, 2023
1f6f47d
Merge remote-tracking branch 'origin/main' into reflection-probes
pcwalton Dec 16, 2023
2d6b3ab
Add some more documentation
pcwalton Dec 16, 2023
df2bfb8
Address a couple more review comments
pcwalton Dec 16, 2023
b074f44
Remove the half-extents from light probes
pcwalton Dec 16, 2023
dd63661
Address more review comments
pcwalton Dec 16, 2023
645b64b
Use a tighter bounding box in the example
pcwalton Dec 17, 2023
bc45758
Clippy police
pcwalton Dec 17, 2023
5dc6874
Address review comment
pcwalton Dec 17, 2023
35b8ad2
Merge `environment_map` and `light_probe` into one
pcwalton Dec 17, 2023
1ebc40b
rustfmt police
pcwalton Dec 17, 2023
ffe11df
Merge remote-tracking branch 'origin/main' into reflection-probes
pcwalton Dec 17, 2023
b30602f
Clippy police
pcwalton Dec 17, 2023
75794ae
Clippy police
pcwalton Dec 17, 2023
12ff889
TOML and `check-doc` police
pcwalton Dec 17, 2023
12463b4
Doc check police
pcwalton Dec 17, 2023
4e138cd
Merge remote-tracking branch 'origin/main' into reflection-probes
pcwalton Dec 17, 2023
63cb7cb
Try to unbreak D3D12
pcwalton Dec 17, 2023
a7a0980
Remove the skybox texture to save space in the Bevy repo
pcwalton Dec 17, 2023
0560924
Fix `assets` mistake
pcwalton Dec 17, 2023
d7c1b14
Merge remote-tracking branch 'origin/main' into reflection-probes
pcwalton Dec 30, 2023
38c0f00
Address review comments
pcwalton Dec 30, 2023
cdec3c5
Merge remote-tracking branch 'origin/main' into reflection-probes
pcwalton Jan 2, 2024
0da1086
Disable diffuse environment maps when lightmaps are present
pcwalton Jan 2, 2024
52aba03
Clippy police
pcwalton Jan 3, 2024
729824e
Doc-check police
pcwalton Jan 3, 2024
bd2bcc4
Split out the radiance and irradiance computation into a separate
pcwalton Jan 3, 2024
d03c6e5
Merge remote-tracking branch 'origin/main' into reflection-probes
pcwalton Jan 16, 2024
5daff87
Make the binding array fixed length
pcwalton Jan 16, 2024
99e94f6
Make the binding array fixed length to fix macOS.
pcwalton Jan 16, 2024
0fdd893
`#[cfg]` out iOS and Android
pcwalton Jan 16, 2024
9760a4a
Merge remote-tracking branch 'pcwalton/reflection-probes' into reflec…
pcwalton Jan 16, 2024
3c4276a
Do bindless detection at runtime instead of using `#[cfg]`
pcwalton Jan 18, 2024
06b5755
Merge remote-tracking branch 'origin/main' into reflection-probes
pcwalton Jan 18, 2024
13b3055
Merge remote-tracking branch 'origin/main' into reflection-probes
pcwalton Jan 18, 2024
cd90fab
Move the camera out of the glTF file
pcwalton Jan 18, 2024
a70d652
rustfmt police
pcwalton Jan 18, 2024
b0f5585
Add some more comments
pcwalton Jan 18, 2024
394fcea
Clippy police
pcwalton Jan 18, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2508,6 +2508,17 @@ name = "fallback_image"
path = "examples/shader/fallback_image.rs"
doc-scrape-examples = true

[[example]]
name = "reflection_probes"
path = "examples/3d/reflection_probes.rs"
doc-scrape-examples = true

[package.metadata.example.reflection_probes]
name = "Reflection Probes"
description = "Demonstrates reflection probes"
category = "3D Rendering"
wasm = false

[package.metadata.example.fallback_image]
hidden = true

Expand Down
Binary file not shown.
Binary file added assets/models/cubes/Cubes.glb
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
@group(0) @binding(3) var dt_lut_texture: texture_3d<f32>;
@group(0) @binding(4) var dt_lut_sampler: sampler;
#else
@group(0) @binding(15) var dt_lut_texture: texture_3d<f32>;
@group(0) @binding(16) var dt_lut_sampler: sampler;
@group(0) @binding(16) var dt_lut_texture: texture_3d<f32>;
@group(0) @binding(17) var dt_lut_sampler: sampler;
#endif

fn sample_current_lut(p: vec3<f32>) -> vec3<f32> {
Expand Down
5 changes: 4 additions & 1 deletion crates/bevy_internal/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,10 @@ symphonia-vorbis = ["bevy_audio/symphonia-vorbis"]
symphonia-wav = ["bevy_audio/symphonia-wav"]

# Shader formats
shader_format_glsl = ["bevy_render/shader_format_glsl"]
shader_format_glsl = [
"bevy_render/shader_format_glsl",
"bevy_pbr?/shader_format_glsl",
]
shader_format_spirv = ["bevy_render/shader_format_spirv"]

serialize = [
Expand Down
12 changes: 11 additions & 1 deletion crates/bevy_pbr/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ keywords = ["bevy"]

[features]
webgl = []
shader_format_glsl = ["naga_oil/glsl"]
pbr_transmission_textures = []

[dependencies]
Expand All @@ -34,8 +35,17 @@ fixedbitset = "0.4"
# direct dependency required for derive macro
bytemuck = { version = "1", features = ["derive"] }
radsort = "0.1"
naga_oil = "0.11"
smallvec = "1.6"
thread_local = "1.0"

[target.'cfg(target_arch = "wasm32")'.dependencies]
naga_oil = { version = "0.11" }

[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
# Omit the `glsl` feature in non-WebAssembly by default.
naga_oil = { version = "0.11", default-features = false, features = [
"test_shader",
] }

[lints]
workspace = true
44 changes: 20 additions & 24 deletions crates/bevy_pbr/src/deferred/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
use crate::{MeshPipeline, MeshViewBindGroup, ScreenSpaceAmbientOcclusionSettings};
use crate::{
environment_map::RenderViewEnvironmentMaps, MeshPipeline, MeshViewBindGroup,
ScreenSpaceAmbientOcclusionSettings, ViewLightProbesUniformOffset,
};
use bevy_app::prelude::*;
use bevy_asset::{load_internal_asset, Handle};
use bevy_core_pipeline::{
Expand All @@ -14,25 +17,17 @@ use bevy_render::{
extract_component::{
ComponentUniforms, ExtractComponent, ExtractComponentPlugin, UniformComponentPlugin,
},
render_asset::RenderAssets,
render_graph::{NodeRunError, RenderGraphContext, ViewNode, ViewNodeRunner},
render_resource::{
binding_types::uniform_buffer, Operations, PipelineCache, RenderPassDescriptor,
},
render_graph::{NodeRunError, RenderGraphApp, RenderGraphContext, ViewNode, ViewNodeRunner},
render_resource::binding_types::uniform_buffer,
render_resource::*,
renderer::{RenderContext, RenderDevice},
texture::Image,
view::{ViewTarget, ViewUniformOffset},
Render, RenderSet,
};

use bevy_render::{
render_graph::RenderGraphApp, render_resource::*, texture::BevyDefault, view::ExtractedView,
RenderApp,
texture::BevyDefault,
view::{ExtractedView, ViewTarget, ViewUniformOffset},
Render, RenderApp, RenderSet,
};

use crate::{
EnvironmentMapLight, MeshPipelineKey, ShadowFilteringMethod, ViewFogUniformOffset,
ViewLightsUniformOffset,
MeshPipelineKey, ShadowFilteringMethod, ViewFogUniformOffset, ViewLightsUniformOffset,
};

pub struct DeferredPbrLightingPlugin;
Expand Down Expand Up @@ -151,6 +146,7 @@ impl ViewNode for DeferredOpaquePass3dPbrLightingNode {
&'static ViewUniformOffset,
&'static ViewLightsUniformOffset,
&'static ViewFogUniformOffset,
&'static ViewLightProbesUniformOffset,
&'static MeshViewBindGroup,
&'static ViewTarget,
&'static DeferredLightingIdDepthTexture,
Expand All @@ -165,6 +161,7 @@ impl ViewNode for DeferredOpaquePass3dPbrLightingNode {
view_uniform_offset,
view_lights_offset,
view_fog_offset,
view_light_probes_offset,
mesh_view_bind_group,
target,
deferred_lighting_id_depth_texture,
Expand Down Expand Up @@ -218,6 +215,7 @@ impl ViewNode for DeferredOpaquePass3dPbrLightingNode {
view_uniform_offset.offset,
view_lights_offset.offset,
view_fog_offset.offset,
**view_light_probes_offset,
],
);
render_pass.set_bind_group(1, &bind_group_1, &[]);
Expand Down Expand Up @@ -403,28 +401,27 @@ pub fn prepare_deferred_lighting_pipelines(
&ExtractedView,
Option<&Tonemapping>,
Option<&DebandDither>,
Option<&EnvironmentMapLight>,
Option<&ShadowFilteringMethod>,
Has<ScreenSpaceAmbientOcclusionSettings>,
(
Has<NormalPrepass>,
Has<DepthPrepass>,
Has<MotionVectorPrepass>,
),
Has<RenderViewEnvironmentMaps>,
),
With<DeferredPrepass>,
>,
images: Res<RenderAssets<Image>>,
) {
for (
entity,
view,
tonemapping,
dither,
environment_map,
shadow_filter_method,
ssao,
(normal_prepass, depth_prepass, motion_vector_prepass),
has_environment_maps,
) in &views
{
let mut view_key = MeshPipelineKey::from_hdr(view.hdr);
Expand Down Expand Up @@ -471,11 +468,10 @@ pub fn prepare_deferred_lighting_pipelines(
view_key |= MeshPipelineKey::SCREEN_SPACE_AMBIENT_OCCLUSION;
}

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

Expand Down
50 changes: 0 additions & 50 deletions crates/bevy_pbr/src/environment_map/environment_map.wgsl

This file was deleted.

98 changes: 0 additions & 98 deletions crates/bevy_pbr/src/environment_map/mod.rs

This file was deleted.

12 changes: 7 additions & 5 deletions crates/bevy_pbr/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ pub mod wireframe;
mod alpha;
mod bundle;
pub mod deferred;
mod environment_map;
mod extended_material;
mod fog;
mod light;
mod light_probe;
mod lightmap;
mod material;
mod parallax;
Expand All @@ -17,10 +17,10 @@ mod ssao;

pub use alpha::*;
pub use bundle::*;
pub use environment_map::EnvironmentMapLight;
pub use extended_material::*;
pub use fog::*;
pub use light::*;
pub use light_probe::*;
pub use lightmap::*;
pub use material::*;
pub use parallax::*;
Expand All @@ -37,9 +37,12 @@ pub mod prelude {
DirectionalLightBundle, MaterialMeshBundle, PbrBundle, PointLightBundle,
SpotLightBundle,
},
environment_map::EnvironmentMapLight,
fog::{FogFalloff, FogSettings},
light::{AmbientLight, DirectionalLight, PointLight, SpotLight},
light_probe::{
environment_map::{EnvironmentMapLight, ReflectionProbeBundle},
LightProbe,
},
material::{Material, MaterialPlugin},
parallax::ParallaxMappingMethod,
pbr_material::StandardMaterial,
Expand Down Expand Up @@ -71,7 +74,6 @@ use bevy_render::{
ExtractSchedule, Render, RenderApp, RenderSet,
};
use bevy_transform::TransformSystem;
use environment_map::EnvironmentMapPlugin;

use crate::deferred::DeferredPbrLightingPlugin;

Expand Down Expand Up @@ -255,12 +257,12 @@ impl Plugin for PbrPlugin {
..Default::default()
},
ScreenSpaceAmbientOcclusionPlugin,
EnvironmentMapPlugin,
ExtractResourcePlugin::<AmbientLight>::default(),
FogPlugin,
ExtractResourcePlugin::<DefaultOpaqueRendererMethod>::default(),
ExtractComponentPlugin::<ShadowFilteringMethod>::default(),
LightmapPlugin,
LightProbePlugin,
))
.configure_sets(
PostUpdate,
Expand Down
Loading