-
-
Notifications
You must be signed in to change notification settings - Fork 3.2k
/
color_banding.rs
61 lines (56 loc) · 1.63 KB
/
color_banding.rs
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
//! Useful for stress-testing rendering cases that exhibit extreme color banding.
use bevy::prelude::*;
fn main() {
App::new()
.add_plugins(DefaultPlugins)
.insert_resource(AmbientLight {
color: Color::BLACK,
brightness: 0.0,
})
.add_startup_system(setup)
.run();
}
/// set up a simple 3D scene
fn setup(
mut commands: Commands,
mut meshes: ResMut<Assets<Mesh>>,
mut materials: ResMut<Assets<StandardMaterial>>,
) {
let colors = [Color::WHITE, Color::RED, Color::GREEN, Color::BLUE];
let x = [-5.0, 5.0, -5.0, 5.0];
let z = [-5.0, -5.0, 5.0, 5.0];
let mesh = meshes.add(Mesh::from(shape::Plane { size: 10.0 }));
for i in 0..4 {
// plane
commands.spawn_bundle(PbrBundle {
mesh: mesh.clone(),
material: materials.add(custom_material(colors[i])),
transform: Transform::from_xyz(x[i], 0.0, z[i]),
..default()
});
}
// light
commands.spawn_bundle(PointLightBundle {
point_light: PointLight {
intensity: 50.0,
shadows_enabled: false,
..default()
},
transform: Transform::from_xyz(0.0, 5.0, 0.0),
..default()
});
// camera
commands.spawn_bundle(Camera3dBundle {
transform: Transform::from_xyz(0.0, 6.0, 0.0).looking_at(Vec3::default(), -Vec3::Z),
..default()
});
}
fn custom_material(color: Color) -> StandardMaterial {
StandardMaterial {
base_color: color,
perceptual_roughness: 1.0,
metallic: 0.0,
reflectance: 0.0,
..default()
}
}