-
Notifications
You must be signed in to change notification settings - Fork 35
Expand file tree
/
Copy pathbloom.rs
More file actions
103 lines (93 loc) · 2.8 KB
/
Copy pathbloom.rs
File metadata and controls
103 lines (93 loc) · 2.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
use std::f32::consts::{PI, TAU};
use bevy::{
post_process::bloom::{Bloom, BloomCompositeMode},
prelude::*,
render::view::Hdr,
};
use bevy_mod_outline::*;
#[bevy_main]
fn main() {
App::new()
.insert_resource(ClearColor(Color::BLACK))
.add_plugins((DefaultPlugins, OutlinePlugin))
.add_systems(Startup, setup)
.add_systems(Update, (rotates, pulses))
.run();
}
#[derive(Component)]
struct Rotates;
#[derive(Component)]
struct Pulses(f32);
fn setup(
mut commands: Commands,
mut meshes: ResMut<Assets<Mesh>>,
mut materials: ResMut<Assets<StandardMaterial>>,
) {
// Add emissive sphere
commands.spawn((
Mesh3d(meshes.add(Sphere::new(0.75).mesh().uv(50, 50))),
MeshMaterial3d(materials.add(StandardMaterial {
base_color: Color::WHITE,
..default()
})),
Transform::from_translation(Vec3::new(0.0, 0.0, 0.0)),
OutlineVolume {
visible: true,
colour: Color::WHITE,
width: 5.0,
},
Pulses(0.0),
));
// Add satellite
commands
.spawn((Transform::default(), InheritedVisibility::default()))
.insert(Rotates)
.with_children(|parent| {
parent.spawn((
Mesh3d(meshes.add(Sphere::new(0.25).mesh().uv(25, 25))),
MeshMaterial3d(materials.add(StandardMaterial {
base_color: Color::srgb(1.0, 0.0, 0.0),
emissive: LinearRgba::rgb(100.0, 0.0, 0.0),
..default()
})),
Transform::from_translation(Vec3::new(0.0, 0.0, 1.25)),
OutlineVolume {
visible: true,
colour: Color::WHITE,
width: 5.0,
},
Pulses(PI),
));
});
// Add HDR camera
commands.spawn((
Camera3d::default(),
Transform::from_xyz(0.0, 3.0, 4.0).looking_at(Vec3::ZERO, Vec3::Y),
Hdr,
Msaa::Sample4,
Bloom {
intensity: 1.0,
low_frequency_boost: 0.5,
low_frequency_boost_curvature: 0.5,
high_pass_frequency: 0.5,
composite_mode: BloomCompositeMode::Additive,
..default()
},
));
}
fn rotates(mut query: Query<&mut Transform, With<Rotates>>, timer: Res<Time>) {
for mut transform in query.iter_mut() {
transform.rotate_axis(Dir3::Y, 0.75 * timer.delta_secs());
}
}
fn pulses(
mut query: Query<(&mut OutlineVolume, &Pulses)>,
timer: Res<Time>,
mut state: Local<f32>,
) {
*state = (*state + 0.3 * timer.delta_secs()) % TAU;
for (mut outline, phase) in query.iter_mut() {
let t = (*state + phase.0).sin().max(0.0);
outline.width = (15.0 * t).min(7.5);
}
}