mirror of
https://github.com/bevyengine/bevy
synced 2025-02-16 22:18:33 +00:00
# Objective
- The emissive color gets multiplied by the camera exposure value. But
this cancels out almost any emissive effect.
- Fixes #13133
- Closes PR #13337
## Solution
- Add emissive_exposure_weight to the StandardMaterial
- In the shader this value is stored in the alpha channel of the
emissive color.
- This value defines how much the exposure influences the emissive
color.
- It's equal to Google's Filament:
https://google.github.io/filament/Materials.html#emissive
4f021583f1/shaders/src/shading_lit.fs (L287)
## Testing
- The result of
[EmissiveStrengthTest](https://github.com/KhronosGroup/glTF-Sample-Models/tree/main/2.0/EmissiveStrengthTest)
with the default value of 0.0:
without bloom:
![emissive_fix](https://github.com/bevyengine/bevy/assets/688816/8f8c131a-464a-4d7b-a9e4-4e28d679ee5d)
with bloom:
![emissive_fix_bloom](https://github.com/bevyengine/bevy/assets/688816/89f200ee-3bd5-4daa-bf64-8999b56df3fa)
65 lines
2 KiB
Rust
65 lines
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::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 == "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;
|
|
}
|
|
}
|
|
}
|