add new materials to example
This commit is contained in:
parent
a2d0d937e0
commit
5ca84dbde0
@ -1,4 +1,5 @@
|
|||||||
use bevy::prelude::*;
|
use bevy::prelude::*;
|
||||||
|
use bevy::render::render_graph_2::{StandardMaterial, ShaderUniforms};
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
AppBuilder::new().add_defaults().setup_world(setup).run();
|
AppBuilder::new().add_defaults().setup_world(setup).run();
|
||||||
@ -15,36 +16,43 @@ fn setup(world: &mut World) {
|
|||||||
|
|
||||||
world.build()
|
world.build()
|
||||||
// plane
|
// plane
|
||||||
.build_archetype(MeshEntity {
|
// .build_archetype(MeshEntity {
|
||||||
mesh: plane_handle.clone(),
|
// mesh: plane_handle.clone(),
|
||||||
material: Material::new(Albedo::Color(math::vec4(0.1, 0.2, 0.1, 1.0))),
|
// material: Material::new(Albedo::Color(math::vec4(0.1, 0.2, 0.1, 1.0))),
|
||||||
local_to_world: LocalToWorld::identity(),
|
// local_to_world: LocalToWorld::identity(),
|
||||||
translation: Translation::new(0.0, 0.0, 0.0),
|
// translation: Translation::new(0.0, 0.0, 0.0),
|
||||||
})
|
// })
|
||||||
// cube
|
// cube
|
||||||
.build_archetype(MeshEntity {
|
.build_archetype(NewMeshEntity {
|
||||||
mesh: cube_handle,
|
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(),
|
local_to_world: LocalToWorld::identity(),
|
||||||
translation: Translation::new(0.0, 0.0, 1.0),
|
translation: Translation::new(0.0, 0.0, 1.0),
|
||||||
})
|
})
|
||||||
// light
|
// light
|
||||||
.build_archetype(LightEntity {
|
// .build_archetype(LightEntity {
|
||||||
light: Light {
|
// light: Light {
|
||||||
color: wgpu::Color {
|
// color: wgpu::Color {
|
||||||
r: 0.8,
|
// r: 0.8,
|
||||||
g: 0.8,
|
// g: 0.8,
|
||||||
b: 0.5,
|
// b: 0.5,
|
||||||
a: 1.0,
|
// a: 1.0,
|
||||||
},
|
// },
|
||||||
fov: f32::to_radians(60.0),
|
// fov: f32::to_radians(60.0),
|
||||||
depth: 0.1..50.0,
|
// depth: 0.1..50.0,
|
||||||
target_view: None,
|
// target_view: None,
|
||||||
},
|
// },
|
||||||
local_to_world: LocalToWorld::identity(),
|
// local_to_world: LocalToWorld::identity(),
|
||||||
translation: Translation::new(4.0, -4.0, 5.0),
|
// translation: Translation::new(4.0, -4.0, 5.0),
|
||||||
rotation: Rotation::from_euler_angles(0.0, 0.0, 0.0),
|
// rotation: Rotation::from_euler_angles(0.0, 0.0, 0.0),
|
||||||
})
|
// })
|
||||||
// camera
|
// camera
|
||||||
.build_archetype(CameraEntity {
|
.build_archetype(CameraEntity {
|
||||||
camera: Camera::new(CameraType::Projection {
|
camera: Camera::new(CameraType::Projection {
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
use crate::prelude::*;
|
use crate::prelude::*;
|
||||||
|
use crate::render::render_graph_2::{StandardMaterial, ShaderUniforms};
|
||||||
use bevy_derive::EntityArchetype;
|
use bevy_derive::EntityArchetype;
|
||||||
|
|
||||||
#[derive(EntityArchetype)]
|
#[derive(EntityArchetype)]
|
||||||
@ -9,6 +10,15 @@ pub struct MeshEntity {
|
|||||||
pub translation: Translation,
|
pub translation: Translation,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(EntityArchetype)]
|
||||||
|
pub struct NewMeshEntity {
|
||||||
|
pub mesh: Handle<Mesh>,
|
||||||
|
pub material: StandardMaterial,
|
||||||
|
pub shader_uniforms: ShaderUniforms,
|
||||||
|
pub local_to_world: LocalToWorld,
|
||||||
|
pub translation: Translation,
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(EntityArchetype)]
|
#[derive(EntityArchetype)]
|
||||||
pub struct LightEntity {
|
pub struct LightEntity {
|
||||||
pub light: Light,
|
pub light: Light,
|
||||||
|
@ -7,6 +7,7 @@ use crate::{
|
|||||||
math::Vec4,
|
math::Vec4,
|
||||||
};
|
};
|
||||||
use zerocopy::AsBytes;
|
use zerocopy::AsBytes;
|
||||||
|
use legion::storage::Component;
|
||||||
|
|
||||||
pub type ShaderUniformSelector = fn(Entity, &World) -> Option<RefMap<&dyn AsUniforms>>;
|
pub type ShaderUniformSelector = fn(Entity, &World) -> Option<RefMap<&dyn AsUniforms>>;
|
||||||
pub struct ShaderUniforms {
|
pub struct ShaderUniforms {
|
||||||
@ -90,6 +91,15 @@ pub struct UniformInfo<'a> {
|
|||||||
pub bind_type: BindType,
|
pub bind_type: BindType,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn standard_material_selector<T>(entity: Entity, world: &World) -> Option<RefMap<&dyn AsUniforms>> where T: AsUniforms + Component {
|
||||||
|
world.get_component::<T>(entity).map(
|
||||||
|
|c| {
|
||||||
|
c.map_into(|s| {
|
||||||
|
s as &dyn AsUniforms
|
||||||
|
})
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
// const ST
|
// const ST
|
||||||
impl AsUniforms for StandardMaterial {
|
impl AsUniforms for StandardMaterial {
|
||||||
fn get_uniform_info(&self) -> &[UniformInfo] {
|
fn get_uniform_info(&self) -> &[UniformInfo] {
|
||||||
|
Loading…
Reference in New Issue
Block a user