mirror of
https://github.com/bevyengine/bevy
synced 2024-11-25 22:20:20 +00:00
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 <8672791+mockersf@users.noreply.github.com>
This commit is contained in:
parent
ffecb05a0a
commit
c825fda74a
3 changed files with 32 additions and 3 deletions
|
@ -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::{
|
||||
|
@ -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>,
|
||||
|
@ -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],
|
||||
|
|
|
@ -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},
|
||||
|
@ -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(
|
||||
|
|
|
@ -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;
|
||||
|
@ -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>.
|
||||
|
|
Loading…
Reference in a new issue