//! A scene showcasing screen space ambient occlusion. use bevy::{ core_pipeline::experimental::taa::{TemporalAntiAliasPlugin, TemporalAntiAliasing}, math::ops, pbr::{ScreenSpaceAmbientOcclusion, 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() }, ScreenSpaceAmbientOcclusion::default(), TemporalAntiAliasing::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(( Mesh3d(meshes.add(Cuboid::default())), MeshMaterial3d(material.clone()), Transform::from_xyz(0.0, 0.0, 1.0), )); commands.spawn(( Mesh3d(meshes.add(Cuboid::default())), MeshMaterial3d(material.clone()), Transform::from_xyz(0.0, -1.0, 0.0), )); commands.spawn(( Mesh3d(meshes.add(Cuboid::default())), MeshMaterial3d(material), Transform::from_xyz(1.0, 0.0, 0.0), )); commands.spawn(( Mesh3d(meshes.add(Sphere::new(0.4).mesh().uv(72, 36))), MeshMaterial3d(materials.add(StandardMaterial { base_color: Color::srgb(0.4, 0.4, 0.4), perceptual_roughness: 1.0, reflectance: 0.0, ..default() })), SphereMarker, )); commands.spawn(( DirectionalLight { shadows_enabled: true, ..default() }, Transform::from_rotation(Quat::from_euler(EulerRot::ZYX, 0.0, PI * -0.15, PI * -0.15)), )); 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