Skip to content

Commit c825fda

Browse files
committed
add default standard material in PbrBundle (#3325)
# Objective - Fix #3323 ## Solution - Add a default standard material that is very visible. It is similar to the previous standard material that was used <img width="1392" alt="Screenshot 2021-12-14 at 15 39 01" src="https://user-images.githubusercontent.com/8672791/146019401-ed4b5fc1-7cce-4a8f-a511-a6f9665a51d7.png"> Co-authored-by: François <[email protected]>
1 parent ffecb05 commit c825fda

File tree

3 files changed

+32
-3
lines changed

3 files changed

+32
-3
lines changed

crates/bevy_pbr/src/bundle.rs

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use crate::{DirectionalLight, PointLight, StandardMaterial};
1+
use crate::{DirectionalLight, PointLight, StandardMaterial, DEFAULT_STANDARD_MATERIAL_HANDLE};
22
use bevy_asset::Handle;
33
use bevy_ecs::{bundle::Bundle, component::Component};
44
use bevy_render::{
@@ -9,7 +9,7 @@ use bevy_render::{
99
use bevy_transform::components::{GlobalTransform, Transform};
1010

1111
/// A component bundle for PBR entities with a [`Mesh`] and a [`StandardMaterial`].
12-
#[derive(Bundle, Clone, Default)]
12+
#[derive(Bundle, Clone)]
1313
pub struct PbrBundle {
1414
pub mesh: Handle<Mesh>,
1515
pub material: Handle<StandardMaterial>,
@@ -21,6 +21,19 @@ pub struct PbrBundle {
2121
pub computed_visibility: ComputedVisibility,
2222
}
2323

24+
impl Default for PbrBundle {
25+
fn default() -> Self {
26+
Self {
27+
mesh: Default::default(),
28+
material: DEFAULT_STANDARD_MATERIAL_HANDLE.typed(),
29+
transform: Default::default(),
30+
global_transform: Default::default(),
31+
visibility: Default::default(),
32+
computed_visibility: Default::default(),
33+
}
34+
}
35+
}
36+
2437
#[derive(Component, Clone, Debug, Default)]
2538
pub struct CubemapVisibleEntities {
2639
data: [VisibleEntities; 6],

crates/bevy_pbr/src/lib.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ use bevy_core_pipeline::{AlphaMask3d, Opaque3d, Transparent3d};
3535
use bevy_ecs::prelude::*;
3636
use bevy_reflect::TypeUuid;
3737
use bevy_render::{
38+
prelude::Color,
3839
render_component::ExtractComponentPlugin,
3940
render_graph::RenderGraph,
4041
render_phase::{sort_phase_system, AddRenderCommand, DrawFunctions},
@@ -122,6 +123,18 @@ impl Plugin for PbrPlugin {
122123
.after(VisibilitySystems::CheckVisibility),
123124
);
124125

126+
app.world
127+
.get_resource_mut::<Assets<StandardMaterial>>()
128+
.unwrap()
129+
.set_untracked(
130+
DEFAULT_STANDARD_MATERIAL_HANDLE,
131+
StandardMaterial {
132+
base_color: Color::rgb(1.0, 0.0, 0.5),
133+
unlit: true,
134+
..Default::default()
135+
},
136+
);
137+
125138
let render_app = app.sub_app(RenderApp);
126139
render_app
127140
.add_system_to_stage(

crates/bevy_pbr/src/material.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use crate::{AlphaMode, PbrPipeline, StandardMaterialFlags};
22
use bevy_app::{App, Plugin};
3-
use bevy_asset::{AddAsset, Handle};
3+
use bevy_asset::{AddAsset, Handle, HandleUntyped};
44
use bevy_ecs::system::{lifetimeless::SRes, SystemParamItem};
55
use bevy_math::Vec4;
66
use bevy_reflect::TypeUuid;
@@ -14,6 +14,9 @@ use bevy_render::{
1414
use crevice::std140::{AsStd140, Std140};
1515
use wgpu::{BindGroupDescriptor, BindGroupEntry, BindingResource};
1616

17+
pub const DEFAULT_STANDARD_MATERIAL_HANDLE: HandleUntyped =
18+
HandleUntyped::weak_from_u64(StandardMaterial::TYPE_UUID, 13142262394054731189);
19+
1720
/// A material with "standard" properties used in PBR lighting
1821
/// Standard property values with pictures here
1922
/// <https://google.github.io/filament/Material%20Properties.pdf>.

0 commit comments

Comments
 (0)