From 2c7456028338301137f124986ce4848845f24451 Mon Sep 17 00:00:00 2001 From: Carter Anderson Date: Tue, 23 Jun 2020 19:27:00 -0700 Subject: [PATCH] render: draw in back-to-front mode to be safe (until we can do both at the same time). expand texture example --- .../src/render_graph/nodes/main_pass_node.rs | 2 +- examples/3d/texture.rs | 21 ++++++++++++++++--- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/crates/bevy_render/src/render_graph/nodes/main_pass_node.rs b/crates/bevy_render/src/render_graph/nodes/main_pass_node.rs index 9e23d8f475..6a438f6c24 100644 --- a/crates/bevy_render/src/render_graph/nodes/main_pass_node.rs +++ b/crates/bevy_render/src/render_graph/nodes/main_pass_node.rs @@ -103,7 +103,7 @@ impl Node for MainPassNode { }; let mut draw_state = DrawState::default(); - for visible_entity in visible_entities.iter() { + for visible_entity in visible_entities.iter().rev() { let draw = if let Some(draw) = world.get_component::(visible_entity.entity) { draw } else { diff --git a/examples/3d/texture.rs b/examples/3d/texture.rs index 19434f1931..5b5a167928 100644 --- a/examples/3d/texture.rs +++ b/examples/3d/texture.rs @@ -34,13 +34,20 @@ fn setup( ..Default::default() }); - // this material modulates the texture to make it red - let modulated_material_handle = materials.add(StandardMaterial { + // this material modulates the texture to make it red (and slightly transparent) + let red_material_handle = materials.add(StandardMaterial { albedo: Color::rgba(1.0, 0.0, 0.0, 0.5), albedo_texture: Some(texture_handle), ..Default::default() }); + // and lets make this one blue! (and also slightly transparent) + let blue_material_handle = materials.add(StandardMaterial { + albedo: Color::rgba(0.0, 0.0, 1.0, 0.5), + albedo_texture: Some(texture_handle), + ..Default::default() + }); + // add entities to the world command_buffer .build() @@ -48,6 +55,14 @@ fn setup( .add_entity(MeshEntity { mesh: quad_handle, material: material_handle, + translation: Translation::new(0.0, -1.5, 0.0), + rotation: Rotation::from_euler_angles(0.0, std::f32::consts::PI / 3.0, 0.0), + ..Default::default() + }) + // textured quad - modulated + .add_entity(MeshEntity { + mesh: quad_handle, + material: red_material_handle, translation: Translation::new(0.0, 0.0, 0.0), rotation: Rotation::from_euler_angles(0.0, std::f32::consts::PI / 3.0, 0.0), ..Default::default() @@ -55,7 +70,7 @@ fn setup( // textured quad - modulated .add_entity(MeshEntity { mesh: quad_handle, - material: modulated_material_handle, + material: blue_material_handle, translation: Translation::new(0.0, 1.5, 0.0), rotation: Rotation::from_euler_angles(0.0, std::f32::consts::PI / 3.0, 0.0), ..Default::default()