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
//! This example shows that bevy_smud works with tonampping
//!
//! There are two shapes rendered:
//!
//! - A circle, rendered by bevy_smud
//! - A squaree rendered by bevy_sprite
//!
//! If tonemapping is working correctly, they should have the same color
use bevy::color::palettes::css;
use bevy::core_pipeline::tonemapping::Tonemapping;
use bevy::prelude::*;
use bevy_smud::prelude::*;
fn main() {
App::new()
.insert_resource(ClearColor(Color::BLACK))
.add_plugins((DefaultPlugins, SmudPlugin))
.add_systems(Startup, setup)
.run();
}
fn setup(mut commands: Commands, mut shaders: ResMut<Assets<Shader>>) {
let circle = shaders.add_sdf_expr("smud::sd_circle(input.pos, 70.)");
commands.spawn((
Transform::from_xyz(100., 0., 0.),
SmudShape {
color: css::TOMATO.into(),
sdf: circle,
bounds: Rectangle::from_length(160.),
fill: SIMPLE_FILL_HANDLE,
..default()
},
));
// bevy square for comparison
commands.spawn((
Transform::from_xyz(-100., 0., 0.),
Sprite {
color: css::TOMATO.into(),
custom_size: Some(Vec2::splat(160.)),
..default()
},
));
commands.spawn((
Camera2d,
// bevy_smud comes with anti-aliasing built into the standard fills
// which is more efficient than MSAA, and also works on Linux, wayland
Msaa::Off,
// Reinhard tonemapping looks pretty different from no tonemapping,
// so we can clearly see the difference between tonemapping and no tonemapping
Tonemapping::Reinhard,
));
}