Skip to content

Commit 75f49bd

Browse files
authored
Move IrradianceVolume to bevy_light (#20000)
# Objective - Reunite it with its family ## Solution - Immigration ## Testing - irradiance_volumes example
1 parent e281008 commit 75f49bd

File tree

5 files changed

+55
-58
lines changed

5 files changed

+55
-58
lines changed

crates/bevy_light/src/lib.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ use cluster::{
2727
mod ambient_light;
2828
pub use ambient_light::AmbientLight;
2929
mod probe;
30-
pub use probe::{EnvironmentMapLight, LightProbe};
30+
pub use probe::{EnvironmentMapLight, IrradianceVolume, LightProbe};
3131
mod volumetric;
3232
pub use volumetric::{FogVolume, VolumetricFog, VolumetricLight};
3333
pub mod cascade;
@@ -121,6 +121,7 @@ impl Plugin for LightPlugin {
121121
.register_type::<PointLight>()
122122
.register_type::<LightProbe>()
123123
.register_type::<EnvironmentMapLight>()
124+
.register_type::<IrradianceVolume>()
124125
.register_type::<VolumetricFog>()
125126
.register_type::<VolumetricLight>()
126127
.register_type::<PointLightShadowMap>()

crates/bevy_light/src/probe.rs

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,3 +107,50 @@ impl Default for EnvironmentMapLight {
107107
}
108108
}
109109
}
110+
111+
/// The component that defines an irradiance volume.
112+
///
113+
/// See `bevy_pbr::irradiance_volume` for detailed information.
114+
///
115+
/// This component requires the [`LightProbe`] component, and is typically used with
116+
/// [`bevy_transform::components::Transform`] to place the volume appropriately.
117+
#[derive(Clone, Reflect, Component, Debug)]
118+
#[reflect(Component, Default, Debug, Clone)]
119+
#[require(LightProbe)]
120+
pub struct IrradianceVolume {
121+
/// The 3D texture that represents the ambient cubes, encoded in the format
122+
/// described in `bevy_pbr::irradiance_volume`.
123+
pub voxels: Handle<Image>,
124+
125+
/// Scale factor applied to the diffuse and specular light generated by this component.
126+
///
127+
/// After applying this multiplier, the resulting values should
128+
/// be in units of [cd/m^2](https://en.wikipedia.org/wiki/Candela_per_square_metre).
129+
///
130+
/// See also <https://google.github.io/filament/Filament.html#lighting/imagebasedlights/iblunit>.
131+
pub intensity: f32,
132+
133+
/// Whether the light from this irradiance volume has an effect on meshes
134+
/// with lightmaps.
135+
///
136+
/// Set this to false if your lightmap baking tool bakes the light from this
137+
/// irradiance volume into the lightmaps in order to avoid counting the
138+
/// irradiance twice. Frequently, applications use irradiance volumes as a
139+
/// lower-quality alternative to lightmaps for capturing indirect
140+
/// illumination on dynamic objects, and such applications will want to set
141+
/// this value to false.
142+
///
143+
/// By default, this is set to true.
144+
pub affects_lightmapped_meshes: bool,
145+
}
146+
147+
impl Default for IrradianceVolume {
148+
#[inline]
149+
fn default() -> Self {
150+
IrradianceVolume {
151+
voxels: Handle::default(),
152+
intensity: 0.0,
153+
affects_lightmapped_meshes: true,
154+
}
155+
}
156+
}

crates/bevy_pbr/src/lib.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,9 @@ use bevy_light::SimulationLightSystems;
5151
pub use bevy_light::{
5252
light_consts, AmbientLight, CascadeShadowConfig, CascadeShadowConfigBuilder, Cascades,
5353
ClusteredDecal, DirectionalLight, DirectionalLightShadowMap, DirectionalLightTexture,
54-
FogVolume, LightPlugin, LightProbe, NotShadowCaster, NotShadowReceiver, PointLight,
55-
PointLightShadowMap, PointLightTexture, ShadowFilteringMethod, SpotLight, SpotLightTexture,
56-
TransmittedShadowReceiver, VolumetricFog, VolumetricLight,
54+
FogVolume, IrradianceVolume, LightPlugin, LightProbe, NotShadowCaster, NotShadowReceiver,
55+
PointLight, PointLightShadowMap, PointLightTexture, ShadowFilteringMethod, SpotLight,
56+
SpotLightTexture, TransmittedShadowReceiver, VolumetricFog, VolumetricLight,
5757
};
5858
pub use cluster::*;
5959
pub use components::*;

crates/bevy_pbr/src/light_probe/irradiance_volume.rs

Lines changed: 2 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -133,9 +133,8 @@
133133
//!
134134
//! [Why ambient cubes?]: #why-ambient-cubes
135135
136-
use bevy_ecs::{component::Component, reflect::ReflectComponent};
137136
use bevy_image::Image;
138-
use bevy_light::LightProbe;
137+
pub use bevy_light::IrradianceVolume;
139138
use bevy_render::{
140139
render_asset::RenderAssets,
141140
render_resource::{
@@ -145,11 +144,9 @@ use bevy_render::{
145144
renderer::{RenderAdapter, RenderDevice},
146145
texture::{FallbackImage, GpuImage},
147146
};
148-
use bevy_utils::default;
149147
use core::{num::NonZero, ops::Deref};
150148

151-
use bevy_asset::{AssetId, Handle};
152-
use bevy_reflect::{std_traits::ReflectDefault, Reflect};
149+
use bevy_asset::AssetId;
153150

154151
use crate::{
155152
add_cubemap_texture_view, binding_arrays_are_usable, RenderViewLightProbes,
@@ -163,53 +160,6 @@ use super::LightProbeComponent;
163160
/// (see issue #11885).
164161
pub(crate) const IRRADIANCE_VOLUMES_ARE_USABLE: bool = cfg!(not(target_arch = "wasm32"));
165162

166-
/// The component that defines an irradiance volume.
167-
///
168-
/// See [`crate::irradiance_volume`] for detailed information.
169-
///
170-
/// This component requires the [`LightProbe`] component, and is typically used with
171-
/// [`bevy_transform::components::Transform`] to place the volume appropriately.
172-
#[derive(Clone, Reflect, Component, Debug)]
173-
#[reflect(Component, Default, Debug, Clone)]
174-
#[require(LightProbe)]
175-
pub struct IrradianceVolume {
176-
/// The 3D texture that represents the ambient cubes, encoded in the format
177-
/// described in [`crate::irradiance_volume`].
178-
pub voxels: Handle<Image>,
179-
180-
/// Scale factor applied to the diffuse and specular light generated by this component.
181-
///
182-
/// After applying this multiplier, the resulting values should
183-
/// be in units of [cd/m^2](https://en.wikipedia.org/wiki/Candela_per_square_metre).
184-
///
185-
/// See also <https://google.github.io/filament/Filament.html#lighting/imagebasedlights/iblunit>.
186-
pub intensity: f32,
187-
188-
/// Whether the light from this irradiance volume has an effect on meshes
189-
/// with lightmaps.
190-
///
191-
/// Set this to false if your lightmap baking tool bakes the light from this
192-
/// irradiance volume into the lightmaps in order to avoid counting the
193-
/// irradiance twice. Frequently, applications use irradiance volumes as a
194-
/// lower-quality alternative to lightmaps for capturing indirect
195-
/// illumination on dynamic objects, and such applications will want to set
196-
/// this value to false.
197-
///
198-
/// By default, this is set to true.
199-
pub affects_lightmapped_meshes: bool,
200-
}
201-
202-
impl Default for IrradianceVolume {
203-
#[inline]
204-
fn default() -> Self {
205-
IrradianceVolume {
206-
voxels: default(),
207-
intensity: 0.0,
208-
affects_lightmapped_meshes: true,
209-
}
210-
}
211-
}
212-
213163
/// All the bind group entries necessary for PBR shaders to access the
214164
/// irradiance volumes exposed to a view.
215165
pub(crate) enum RenderViewIrradianceVolumeBindGroupEntries<'a> {

crates/bevy_pbr/src/light_probe/mod.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -288,8 +288,7 @@ impl Plugin for LightProbePlugin {
288288
load_shader_library!(app, "environment_map.wgsl");
289289
load_shader_library!(app, "irradiance_volume.wgsl");
290290

291-
app.register_type::<IrradianceVolume>()
292-
.add_plugins(ExtractInstancesPlugin::<EnvironmentMapIds>::new());
291+
app.add_plugins(ExtractInstancesPlugin::<EnvironmentMapIds>::new());
293292
}
294293

295294
fn finish(&self, app: &mut App) {

0 commit comments

Comments
 (0)