transparency_3d
example tweaks (#4968)
Fixed a typo, removed unused component, normalized comments added a touch more detail.
This commit is contained in:
parent
7e6dd3f03e
commit
33a5f2b977
@ -13,21 +13,18 @@ fn main() {
|
|||||||
.run();
|
.run();
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Component)]
|
|
||||||
pub struct FadeTransparency;
|
|
||||||
|
|
||||||
fn setup(
|
fn setup(
|
||||||
mut commands: Commands,
|
mut commands: Commands,
|
||||||
mut meshes: ResMut<Assets<Mesh>>,
|
mut meshes: ResMut<Assets<Mesh>>,
|
||||||
mut materials: ResMut<Assets<StandardMaterial>>,
|
mut materials: ResMut<Assets<StandardMaterial>>,
|
||||||
) {
|
) {
|
||||||
// Opaque plane
|
// opaque plane, uses `alpha_mode: Opaque` by default
|
||||||
commands.spawn_bundle(PbrBundle {
|
commands.spawn_bundle(PbrBundle {
|
||||||
mesh: meshes.add(Mesh::from(shape::Plane { size: 6.0 })),
|
mesh: meshes.add(Mesh::from(shape::Plane { size: 6.0 })),
|
||||||
material: materials.add(Color::rgb(0.3, 0.5, 0.3).into()),
|
material: materials.add(Color::rgb(0.3, 0.5, 0.3).into()),
|
||||||
..default()
|
..default()
|
||||||
});
|
});
|
||||||
// transparent sphere, using alpha_mode: Mask
|
// transparent sphere, uses `alpha_mode: Mask(f32)`
|
||||||
commands.spawn_bundle(PbrBundle {
|
commands.spawn_bundle(PbrBundle {
|
||||||
mesh: meshes.add(Mesh::from(shape::Icosphere {
|
mesh: meshes.add(Mesh::from(shape::Icosphere {
|
||||||
radius: 0.5,
|
radius: 0.5,
|
||||||
@ -39,7 +36,7 @@ fn setup(
|
|||||||
// `fade_transparency` function.
|
// `fade_transparency` function.
|
||||||
// Note that the transparency has no effect on the objects shadow.
|
// Note that the transparency has no effect on the objects shadow.
|
||||||
base_color: Color::rgba(0.2, 0.7, 0.1, 0.0),
|
base_color: Color::rgba(0.2, 0.7, 0.1, 0.0),
|
||||||
// Maks sets a cutoff for transparency. Alpha values below are fully transparent,
|
// Mask sets a cutoff for transparency. Alpha values below are fully transparent,
|
||||||
// alpha values above are fully opaque.
|
// alpha values above are fully opaque.
|
||||||
alpha_mode: AlphaMode::Mask(0.5),
|
alpha_mode: AlphaMode::Mask(0.5),
|
||||||
..default()
|
..default()
|
||||||
@ -47,7 +44,7 @@ fn setup(
|
|||||||
transform: Transform::from_xyz(1.0, 0.5, -1.5),
|
transform: Transform::from_xyz(1.0, 0.5, -1.5),
|
||||||
..default()
|
..default()
|
||||||
});
|
});
|
||||||
// transparent cube, using alpha_mode: Blend
|
// transparent cube, uses `alpha_mode: Blend`
|
||||||
commands.spawn_bundle(PbrBundle {
|
commands.spawn_bundle(PbrBundle {
|
||||||
mesh: meshes.add(Mesh::from(shape::Cube { size: 1.0 })),
|
mesh: meshes.add(Mesh::from(shape::Cube { size: 1.0 })),
|
||||||
// Notice how there is no need to set the `alpha_mode` explicitly here.
|
// Notice how there is no need to set the `alpha_mode` explicitly here.
|
||||||
@ -57,7 +54,7 @@ fn setup(
|
|||||||
transform: Transform::from_xyz(0.0, 0.5, 0.0),
|
transform: Transform::from_xyz(0.0, 0.5, 0.0),
|
||||||
..default()
|
..default()
|
||||||
});
|
});
|
||||||
// sphere
|
// opaque sphere
|
||||||
commands.spawn_bundle(PbrBundle {
|
commands.spawn_bundle(PbrBundle {
|
||||||
mesh: meshes.add(Mesh::from(shape::Icosphere {
|
mesh: meshes.add(Mesh::from(shape::Icosphere {
|
||||||
radius: 0.5,
|
radius: 0.5,
|
||||||
|
Loading…
Reference in New Issue
Block a user