mirror of
https://github.com/bevyengine/bevy
synced 2024-11-10 15:14:50 +00:00
fcd7c0fc3d
Rebased and finished version of https://github.com/bevyengine/bevy/pull/8407. Huge thanks to @GitGhillie for adjusting all the examples, and the many other people who helped write this PR (@superdump , @coreh , among others) :) Fixes https://github.com/bevyengine/bevy/issues/8369 --- ## Changelog - Added a `brightness` control to `Skybox`. - Added an `intensity` control to `EnvironmentMapLight`. - Added `ExposureSettings` and `PhysicalCameraParameters` for controlling exposure of 3D cameras. - Removed the baked-in `DirectionalLight` exposure Bevy previously hardcoded internally. ## Migration Guide - If using a `Skybox` or `EnvironmentMapLight`, use the new `brightness` and `intensity` controls to adjust their strength. - All 3D scene will now have different apparent brightnesses due to Bevy implementing proper exposure controls. You will have to adjust the intensity of your lights and/or your camera exposure via the new `ExposureSettings` component to compensate. --------- Co-authored-by: Robert Swain <robert.swain@gmail.com> Co-authored-by: GitGhillie <jillisnoordhoek@gmail.com> Co-authored-by: Marco Buono <thecoreh@gmail.com> Co-authored-by: vero <email@atlasdostal.com> Co-authored-by: atlas dostal <rodol@rivalrebels.com>
73 lines
2.2 KiB
Rust
73 lines
2.2 KiB
Rust
//! Rendering a scene with baked lightmaps.
|
|
|
|
use bevy::pbr::Lightmap;
|
|
use bevy::prelude::*;
|
|
|
|
fn main() {
|
|
App::new()
|
|
.add_plugins(DefaultPlugins)
|
|
.insert_resource(AmbientLight {
|
|
color: Color::WHITE,
|
|
brightness: 0.0,
|
|
})
|
|
.add_systems(Startup, setup)
|
|
.add_systems(Update, add_lightmaps_to_meshes)
|
|
.run();
|
|
}
|
|
|
|
fn setup(mut commands: Commands, asset_server: Res<AssetServer>) {
|
|
commands.spawn(SceneBundle {
|
|
scene: asset_server.load("models/CornellBox/CornellBox.glb#Scene0"),
|
|
..default()
|
|
});
|
|
|
|
commands.spawn(Camera3dBundle {
|
|
transform: Transform::from_xyz(-278.0, 273.0, 800.0),
|
|
..default()
|
|
});
|
|
}
|
|
|
|
fn add_lightmaps_to_meshes(
|
|
mut commands: Commands,
|
|
asset_server: Res<AssetServer>,
|
|
mut materials: ResMut<Assets<StandardMaterial>>,
|
|
meshes: Query<
|
|
(Entity, &Name, &Handle<StandardMaterial>),
|
|
(With<Handle<Mesh>>, Without<Lightmap>),
|
|
>,
|
|
) {
|
|
let exposure = 250.0;
|
|
for (entity, name, material) in meshes.iter() {
|
|
if &**name == "Light" {
|
|
materials.get_mut(material).unwrap().emissive = Color::WHITE * exposure;
|
|
continue;
|
|
}
|
|
|
|
if &**name == "large_box" {
|
|
materials.get_mut(material).unwrap().lightmap_exposure = exposure;
|
|
commands.entity(entity).insert(Lightmap {
|
|
image: asset_server.load("lightmaps/CornellBox-Large.zstd.ktx2"),
|
|
..default()
|
|
});
|
|
continue;
|
|
}
|
|
|
|
if &**name == "small_box" {
|
|
materials.get_mut(material).unwrap().lightmap_exposure = exposure;
|
|
commands.entity(entity).insert(Lightmap {
|
|
image: asset_server.load("lightmaps/CornellBox-Small.zstd.ktx2"),
|
|
..default()
|
|
});
|
|
continue;
|
|
}
|
|
|
|
if name.starts_with("cornell_box") {
|
|
materials.get_mut(material).unwrap().lightmap_exposure = exposure;
|
|
commands.entity(entity).insert(Lightmap {
|
|
image: asset_server.load("lightmaps/CornellBox-Box.zstd.ktx2"),
|
|
..default()
|
|
});
|
|
continue;
|
|
}
|
|
}
|
|
}
|