diff --git a/examples/simple_new_graph.rs b/examples/simple_new_graph.rs index 2ccdfa404d..2313a34004 100644 --- a/examples/simple_new_graph.rs +++ b/examples/simple_new_graph.rs @@ -1,4 +1,5 @@ use bevy::prelude::*; +use bevy::render::render_graph_2::{StandardMaterial, ShaderUniforms}; fn main() { AppBuilder::new().add_defaults().setup_world(setup).run(); @@ -15,36 +16,43 @@ fn setup(world: &mut World) { world.build() // plane - .build_archetype(MeshEntity { - mesh: plane_handle.clone(), - material: Material::new(Albedo::Color(math::vec4(0.1, 0.2, 0.1, 1.0))), - local_to_world: LocalToWorld::identity(), - translation: Translation::new(0.0, 0.0, 0.0), - }) + // .build_archetype(MeshEntity { + // mesh: plane_handle.clone(), + // material: Material::new(Albedo::Color(math::vec4(0.1, 0.2, 0.1, 1.0))), + // local_to_world: LocalToWorld::identity(), + // translation: Translation::new(0.0, 0.0, 0.0), + // }) // cube - .build_archetype(MeshEntity { + .build_archetype(NewMeshEntity { mesh: cube_handle, - material: Material::new(Albedo::Color(math::vec4(0.5, 0.3, 0.3, 1.0))), + material: StandardMaterial { + albedo: math::vec4(1.0, 0.0, 0.0, 1.0), + }, + shader_uniforms: ShaderUniforms { + uniform_selectors: Vec::new( + + ) + }, local_to_world: LocalToWorld::identity(), translation: Translation::new(0.0, 0.0, 1.0), }) // light - .build_archetype(LightEntity { - light: Light { - color: wgpu::Color { - r: 0.8, - g: 0.8, - b: 0.5, - a: 1.0, - }, - fov: f32::to_radians(60.0), - depth: 0.1..50.0, - target_view: None, - }, - local_to_world: LocalToWorld::identity(), - translation: Translation::new(4.0, -4.0, 5.0), - rotation: Rotation::from_euler_angles(0.0, 0.0, 0.0), - }) + // .build_archetype(LightEntity { + // light: Light { + // color: wgpu::Color { + // r: 0.8, + // g: 0.8, + // b: 0.5, + // a: 1.0, + // }, + // fov: f32::to_radians(60.0), + // depth: 0.1..50.0, + // target_view: None, + // }, + // local_to_world: LocalToWorld::identity(), + // translation: Translation::new(4.0, -4.0, 5.0), + // rotation: Rotation::from_euler_angles(0.0, 0.0, 0.0), + // }) // camera .build_archetype(CameraEntity { camera: Camera::new(CameraType::Projection { diff --git a/src/ecs/default_archetypes.rs b/src/ecs/default_archetypes.rs index 0d46397c0c..d68535a9f7 100644 --- a/src/ecs/default_archetypes.rs +++ b/src/ecs/default_archetypes.rs @@ -1,4 +1,5 @@ use crate::prelude::*; +use crate::render::render_graph_2::{StandardMaterial, ShaderUniforms}; use bevy_derive::EntityArchetype; #[derive(EntityArchetype)] @@ -9,6 +10,15 @@ pub struct MeshEntity { pub translation: Translation, } +#[derive(EntityArchetype)] +pub struct NewMeshEntity { + pub mesh: Handle, + pub material: StandardMaterial, + pub shader_uniforms: ShaderUniforms, + pub local_to_world: LocalToWorld, + pub translation: Translation, +} + #[derive(EntityArchetype)] pub struct LightEntity { pub light: Light, diff --git a/src/render/render_graph_2/shader.rs b/src/render/render_graph_2/shader.rs index bc4653f14b..3e501373ff 100644 --- a/src/render/render_graph_2/shader.rs +++ b/src/render/render_graph_2/shader.rs @@ -7,6 +7,7 @@ use crate::{ math::Vec4, }; use zerocopy::AsBytes; +use legion::storage::Component; pub type ShaderUniformSelector = fn(Entity, &World) -> Option>; pub struct ShaderUniforms { @@ -90,6 +91,15 @@ pub struct UniformInfo<'a> { pub bind_type: BindType, } +pub fn standard_material_selector(entity: Entity, world: &World) -> Option> where T: AsUniforms + Component { + world.get_component::(entity).map( + |c| { + c.map_into(|s| { + s as &dyn AsUniforms + }) + }) +} + // const ST impl AsUniforms for StandardMaterial { fn get_uniform_info(&self) -> &[UniformInfo] {