two_passes/
two_passes.rs

1//! Renders two 3d passes to the same window from different perspectives.
2
3use bevy::prelude::*;
4
5fn main() {
6    App::new()
7        .add_plugins(DefaultPlugins)
8        .add_systems(Startup, setup)
9        .run();
10}
11
12/// Set up a simple 3D scene
13fn setup(
14    mut commands: Commands,
15    mut meshes: ResMut<Assets<Mesh>>,
16    mut materials: ResMut<Assets<StandardMaterial>>,
17) {
18    // Plane
19    commands.spawn((
20        Mesh3d(meshes.add(Plane3d::default().mesh().size(5.0, 5.0))),
21        MeshMaterial3d(materials.add(Color::srgb(0.3, 0.5, 0.3))),
22    ));
23
24    // Cube
25    commands.spawn((
26        Mesh3d(meshes.add(Cuboid::default())),
27        MeshMaterial3d(materials.add(Color::srgb(0.8, 0.7, 0.6))),
28        Transform::from_xyz(0.0, 0.5, 0.0),
29    ));
30
31    // Light
32    commands.spawn((
33        PointLight {
34            shadows_enabled: true,
35            ..default()
36        },
37        Transform::from_xyz(4.0, 8.0, 4.0),
38    ));
39
40    // Camera
41    commands.spawn((
42        Camera3d::default(),
43        Transform::from_xyz(-2.0, 2.5, 5.0).looking_at(Vec3::ZERO, Vec3::Y),
44    ));
45
46    // camera
47    commands.spawn((
48        Camera3d::default(),
49        Camera {
50            // renders after / on top of the main camera
51            order: 1,
52            clear_color: ClearColorConfig::None,
53            ..default()
54        },
55        Transform::from_xyz(10.0, 10., -5.0).looking_at(Vec3::ZERO, Vec3::Y),
56    ));
57}