mirror of
https://github.com/bevyengine/bevy
synced 2024-11-10 07:04:33 +00:00
faa2ce4d55
# Objective - Since #12163 example lightmaps is more dull <img width="1280" alt="Screenshot 2024-03-02 at 23 04 36" src="https://github.com/bevyengine/bevy/assets/8672791/7736f420-b9c5-4870-93f6-b5b992c4768a"> ## Solution - Use a srgba color, as it was before:b24ab2e9fb/examples/3d/lightmaps.rs (L39)
b24ab2e9fb/crates/bevy_render/src/color/mod.rs (L132)
<img width="1280" alt="Screenshot 2024-03-02 at 23 05 09" src="https://github.com/bevyengine/bevy/assets/8672791/451187ed-8612-456f-ad25-180d5f774188">
70 lines
2.1 KiB
Rust
70 lines
2.1 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::NONE)
|
|
.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::Srgba(Srgba::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;
|
|
}
|
|
}
|
|
}
|