Skip to content

[Merged by Bors] - add default standard material in PbrBundle #3325

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 15 additions & 2 deletions crates/bevy_pbr/src/bundle.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::{DirectionalLight, PointLight, StandardMaterial};
use crate::{DirectionalLight, PointLight, StandardMaterial, DEFAULT_STANDARD_MATERIAL_HANDLE};
use bevy_asset::Handle;
use bevy_ecs::{bundle::Bundle, component::Component};
use bevy_render::{
Expand All @@ -9,7 +9,7 @@ use bevy_render::{
use bevy_transform::components::{GlobalTransform, Transform};

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

impl Default for PbrBundle {
fn default() -> Self {
Self {
mesh: Default::default(),
material: DEFAULT_STANDARD_MATERIAL_HANDLE.typed(),
transform: Default::default(),
global_transform: Default::default(),
visibility: Default::default(),
computed_visibility: Default::default(),
}
}
}

#[derive(Component, Clone, Debug, Default)]
pub struct CubemapVisibleEntities {
data: [VisibleEntities; 6],
Expand Down
8 changes: 8 additions & 0 deletions crates/bevy_pbr/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,14 @@ impl Plugin for PbrPlugin {
.after(VisibilitySystems::CheckVisibility),
);

app.world
.get_resource_mut::<Assets<StandardMaterial>>()
.unwrap()
.set_untracked(
DEFAULT_STANDARD_MATERIAL_HANDLE,
StandardMaterial::high_vis(),
);

let render_app = app.sub_app(RenderApp);
render_app
.add_system_to_stage(
Expand Down
16 changes: 15 additions & 1 deletion crates/bevy_pbr/src/material.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::{AlphaMode, PbrPipeline, StandardMaterialFlags};
use bevy_app::{App, Plugin};
use bevy_asset::{AddAsset, Handle};
use bevy_asset::{AddAsset, Handle, HandleUntyped};
use bevy_ecs::system::{lifetimeless::SRes, SystemParamItem};
use bevy_math::Vec4;
use bevy_reflect::TypeUuid;
Expand All @@ -14,6 +14,9 @@ use bevy_render::{
use crevice::std140::{AsStd140, Std140};
use wgpu::{BindGroupDescriptor, BindGroupEntry, BindingResource};

pub const DEFAULT_STANDARD_MATERIAL_HANDLE: HandleUntyped =
HandleUntyped::weak_from_u64(StandardMaterial::TYPE_UUID, 13142262394054731189);

/// A material with "standard" properties used in PBR lighting
/// Standard property values with pictures here
/// <https://google.github.io/filament/Material%20Properties.pdf>.
Expand Down Expand Up @@ -81,6 +84,17 @@ impl Default for StandardMaterial {
}
}

impl StandardMaterial {
/// Create a high visibility material. It will be used by default when no material are specified in a `PbrBundle`
pub fn high_vis() -> Self {
StandardMaterial {
base_color: Color::rgb(1.0, 0.0, 0.5),
unlit: true,
..Default::default()
}
}
}

impl From<Color> for StandardMaterial {
fn from(color: Color) -> Self {
StandardMaterial {
Expand Down