mirror of
https://github.com/bevyengine/bevy
synced 2024-11-13 00:17:27 +00:00
dd619a1087
# Objective After adding configurable exposure, we set the default ev100 value to `7` (indoor). This brought us out of sync with Blender's configuration and defaults. This PR changes the default to `9.7` (bright indoor or very overcast outdoors), as I calibrated in #11577. This feels like a very reasonable default. The other changes generally center around tweaking Bevy's lighting defaults and examples to play nicely with this number, alongside a few other tweaks and improvements. Note that for artistic reasons I have reverted some examples, which changed to directional lights in #11581, back to point lights. Fixes #11577 --- ## Changelog - Changed `Exposure::ev100` from `7` to `9.7` to better match Blender - Renamed `ExposureSettings` to `Exposure` - `Camera3dBundle` now includes `Exposure` for discoverability - Bumped `FULL_DAYLIGHT ` and `DIRECT_SUNLIGHT` to represent the middle-to-top of those ranges instead of near the bottom - Added new `AMBIENT_DAYLIGHT` constant and set that as the new `DirectionalLight` default illuminance. - `PointLight` and `SpotLight` now have a default `intensity` of 1,000,000 lumens. This makes them actually useful in the context of the new "semi-outdoor" exposure and puts them in the "cinema lighting" category instead of the "common household light" category. They are also reasonably close to the Blender default. - `AmbientLight` default has been bumped from `20` to `80`. ## Migration Guide - The increased `Exposure::ev100` means that all existing 3D lighting will need to be adjusted to match (DirectionalLights, PointLights, SpotLights, EnvironmentMapLights, etc). Or alternatively, you can adjust the `Exposure::ev100` on your cameras to work nicely with your current lighting values. If you are currently relying on default intensity values, you might need to change the intensity to achieve the same effect. Note that in Bevy 0.12, point/spot lights had a different hard coded ev100 value than directional lights. In Bevy 0.13, they use the same ev100, so if you have both in your scene, the _scale_ between these light types has changed and you will likely need to adjust one or both of them.
194 lines
5.9 KiB
Rust
194 lines
5.9 KiB
Rust
//! A scene showcasing screen space ambient occlusion.
|
|
|
|
use bevy::{
|
|
core_pipeline::experimental::taa::{TemporalAntiAliasBundle, TemporalAntiAliasPlugin},
|
|
pbr::{
|
|
ScreenSpaceAmbientOcclusionBundle, ScreenSpaceAmbientOcclusionQualityLevel,
|
|
ScreenSpaceAmbientOcclusionSettings,
|
|
},
|
|
prelude::*,
|
|
render::camera::TemporalJitter,
|
|
};
|
|
use std::f32::consts::PI;
|
|
|
|
fn main() {
|
|
App::new()
|
|
.insert_resource(AmbientLight {
|
|
brightness: 1000.,
|
|
..default()
|
|
})
|
|
.add_plugins((DefaultPlugins, TemporalAntiAliasPlugin))
|
|
.add_systems(Startup, setup)
|
|
.add_systems(Update, update)
|
|
.run();
|
|
}
|
|
|
|
fn setup(
|
|
mut commands: Commands,
|
|
mut meshes: ResMut<Assets<Mesh>>,
|
|
mut materials: ResMut<Assets<StandardMaterial>>,
|
|
asset_server: Res<AssetServer>,
|
|
) {
|
|
commands
|
|
.spawn(Camera3dBundle {
|
|
camera: Camera {
|
|
hdr: true,
|
|
..default()
|
|
},
|
|
transform: Transform::from_xyz(-2.0, 2.0, -2.0).looking_at(Vec3::ZERO, Vec3::Y),
|
|
..default()
|
|
})
|
|
.insert(ScreenSpaceAmbientOcclusionBundle::default())
|
|
.insert(TemporalAntiAliasBundle::default());
|
|
|
|
let material = materials.add(StandardMaterial {
|
|
base_color: Color::rgb(0.5, 0.5, 0.5),
|
|
perceptual_roughness: 1.0,
|
|
reflectance: 0.0,
|
|
..default()
|
|
});
|
|
commands.spawn(PbrBundle {
|
|
mesh: meshes.add(Cuboid::default()),
|
|
material: material.clone(),
|
|
transform: Transform::from_xyz(0.0, 0.0, 1.0),
|
|
..default()
|
|
});
|
|
commands.spawn(PbrBundle {
|
|
mesh: meshes.add(Cuboid::default()),
|
|
material: material.clone(),
|
|
transform: Transform::from_xyz(0.0, -1.0, 0.0),
|
|
..default()
|
|
});
|
|
commands.spawn(PbrBundle {
|
|
mesh: meshes.add(Cuboid::default()),
|
|
material,
|
|
transform: Transform::from_xyz(1.0, 0.0, 0.0),
|
|
..default()
|
|
});
|
|
commands.spawn((
|
|
PbrBundle {
|
|
mesh: meshes.add(Sphere::new(0.4).mesh().uv(72, 36)),
|
|
material: materials.add(StandardMaterial {
|
|
base_color: Color::rgb(0.4, 0.4, 0.4),
|
|
perceptual_roughness: 1.0,
|
|
reflectance: 0.0,
|
|
..default()
|
|
}),
|
|
..default()
|
|
},
|
|
SphereMarker,
|
|
));
|
|
|
|
commands.spawn(DirectionalLightBundle {
|
|
directional_light: DirectionalLight {
|
|
shadows_enabled: true,
|
|
..default()
|
|
},
|
|
transform: Transform::from_rotation(Quat::from_euler(
|
|
EulerRot::ZYX,
|
|
0.0,
|
|
PI * -0.15,
|
|
PI * -0.15,
|
|
)),
|
|
..default()
|
|
});
|
|
|
|
commands.spawn(
|
|
TextBundle::from_section(
|
|
"",
|
|
TextStyle {
|
|
font: asset_server.load("fonts/FiraMono-Medium.ttf"),
|
|
font_size: 26.0,
|
|
..default()
|
|
},
|
|
)
|
|
.with_style(Style {
|
|
position_type: PositionType::Absolute,
|
|
bottom: Val::Px(10.0),
|
|
left: Val::Px(10.0),
|
|
..default()
|
|
}),
|
|
);
|
|
}
|
|
|
|
fn update(
|
|
camera: Query<
|
|
(
|
|
Entity,
|
|
Option<&ScreenSpaceAmbientOcclusionSettings>,
|
|
Option<&TemporalJitter>,
|
|
),
|
|
With<Camera>,
|
|
>,
|
|
mut text: Query<&mut Text>,
|
|
mut sphere: Query<&mut Transform, With<SphereMarker>>,
|
|
mut commands: Commands,
|
|
keycode: Res<ButtonInput<KeyCode>>,
|
|
time: Res<Time>,
|
|
) {
|
|
let mut sphere = sphere.single_mut();
|
|
sphere.translation.y = (time.elapsed_seconds() / 1.7).sin() * 0.7;
|
|
|
|
let (camera_entity, ssao_settings, temporal_jitter) = camera.single();
|
|
|
|
let mut commands = commands.entity(camera_entity);
|
|
if keycode.just_pressed(KeyCode::Digit1) {
|
|
commands.remove::<ScreenSpaceAmbientOcclusionSettings>();
|
|
}
|
|
if keycode.just_pressed(KeyCode::Digit2) {
|
|
commands.insert(ScreenSpaceAmbientOcclusionSettings {
|
|
quality_level: ScreenSpaceAmbientOcclusionQualityLevel::Low,
|
|
});
|
|
}
|
|
if keycode.just_pressed(KeyCode::Digit3) {
|
|
commands.insert(ScreenSpaceAmbientOcclusionSettings {
|
|
quality_level: ScreenSpaceAmbientOcclusionQualityLevel::Medium,
|
|
});
|
|
}
|
|
if keycode.just_pressed(KeyCode::Digit4) {
|
|
commands.insert(ScreenSpaceAmbientOcclusionSettings {
|
|
quality_level: ScreenSpaceAmbientOcclusionQualityLevel::High,
|
|
});
|
|
}
|
|
if keycode.just_pressed(KeyCode::Digit5) {
|
|
commands.insert(ScreenSpaceAmbientOcclusionSettings {
|
|
quality_level: ScreenSpaceAmbientOcclusionQualityLevel::Ultra,
|
|
});
|
|
}
|
|
if keycode.just_pressed(KeyCode::Space) {
|
|
if temporal_jitter.is_some() {
|
|
commands.remove::<TemporalJitter>();
|
|
} else {
|
|
commands.insert(TemporalJitter::default());
|
|
}
|
|
}
|
|
|
|
let mut text = text.single_mut();
|
|
let text = &mut text.sections[0].value;
|
|
text.clear();
|
|
|
|
let (o, l, m, h, u) = match ssao_settings.map(|s| s.quality_level) {
|
|
None => ("*", "", "", "", ""),
|
|
Some(ScreenSpaceAmbientOcclusionQualityLevel::Low) => ("", "*", "", "", ""),
|
|
Some(ScreenSpaceAmbientOcclusionQualityLevel::Medium) => ("", "", "*", "", ""),
|
|
Some(ScreenSpaceAmbientOcclusionQualityLevel::High) => ("", "", "", "*", ""),
|
|
Some(ScreenSpaceAmbientOcclusionQualityLevel::Ultra) => ("", "", "", "", "*"),
|
|
_ => unreachable!(),
|
|
};
|
|
|
|
text.push_str("SSAO Quality:\n");
|
|
text.push_str(&format!("(1) {o}Off{o}\n"));
|
|
text.push_str(&format!("(2) {l}Low{l}\n"));
|
|
text.push_str(&format!("(3) {m}Medium{m}\n"));
|
|
text.push_str(&format!("(4) {h}High{h}\n"));
|
|
text.push_str(&format!("(5) {u}Ultra{u}\n\n"));
|
|
|
|
text.push_str("Temporal Antialiasing:\n");
|
|
text.push_str(match temporal_jitter {
|
|
Some(_) => "(Space) Enabled",
|
|
None => "(Space) Disabled",
|
|
});
|
|
}
|
|
|
|
#[derive(Component)]
|
|
struct SphereMarker;
|