Skip to content

Commit

Permalink
add default standard material in PbrBundle (#3325)
Browse files Browse the repository at this point in the history
# 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]>
  • Loading branch information
mockersf and mockersf committed Dec 14, 2021
1 parent ffecb05 commit c825fda
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 3 deletions.
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
13 changes: 13 additions & 0 deletions crates/bevy_pbr/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ use bevy_core_pipeline::{AlphaMask3d, Opaque3d, Transparent3d};
use bevy_ecs::prelude::*;
use bevy_reflect::TypeUuid;
use bevy_render::{
prelude::Color,
render_component::ExtractComponentPlugin,
render_graph::RenderGraph,
render_phase::{sort_phase_system, AddRenderCommand, DrawFunctions},
Expand Down Expand Up @@ -122,6 +123,18 @@ impl Plugin for PbrPlugin {
.after(VisibilitySystems::CheckVisibility),
);

app.world
.get_resource_mut::<Assets<StandardMaterial>>()
.unwrap()
.set_untracked(
DEFAULT_STANDARD_MATERIAL_HANDLE,
StandardMaterial {
base_color: Color::rgb(1.0, 0.0, 0.5),
unlit: true,
..Default::default()
},
);

let render_app = app.sub_app(RenderApp);
render_app
.add_system_to_stage(
Expand Down
5 changes: 4 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

0 comments on commit c825fda

Please sign in to comment.