//! A scene showcasing screen space ambient occlusion. use bevy::{ core_pipeline::experimental::taa::{TemporalAntiAliasBundle, TemporalAntiAliasPlugin}, pbr::{ ScreenSpaceAmbientOcclusion, ScreenSpaceAmbientOcclusionBundle, ScreenSpaceAmbientOcclusionQualityLevel, }, 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>, mut materials: ResMut>, ) { commands .spawn(Camera3dBundle { camera: Camera { hdr: true, ..default() }, transform: Transform::from_xyz(-2.0, 2.0, -2.0).looking_at(Vec3::ZERO, Vec3::Y), msaa: Msaa::Off, ..default() }) .insert(ScreenSpaceAmbientOcclusionBundle::default()) .insert(TemporalAntiAliasBundle::default()); let material = materials.add(StandardMaterial { base_color: Color::srgb(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::srgb(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::default()).with_style(Style { position_type: PositionType::Absolute, bottom: Val::Px(12.0), left: Val::Px(12.0), ..default() }), ); } fn update( camera: Query< ( Entity, Option<&ScreenSpaceAmbientOcclusion>, Option<&TemporalJitter>, ), With, >, mut text: Query<&mut Text>, mut sphere: Query<&mut Transform, With>, mut commands: Commands, keycode: Res>, time: Res