fix custom_shader example
This commit is contained in:
parent
6cf981c610
commit
ad7acb111a
@ -17,11 +17,14 @@ pub fn derive_entity_archetype(input: TokenStream) -> TokenStream {
|
|||||||
_ => panic!("expected a struct with named fields"),
|
_ => panic!("expected a struct with named fields"),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
let generics = ast.generics;
|
||||||
|
let (impl_generics, ty_generics, _where_clause) = generics.split_for_impl();
|
||||||
|
|
||||||
let struct_name = &ast.ident;
|
let struct_name = &ast.ident;
|
||||||
let field_name = fields.iter().map(|field| &field.ident);
|
let field_name = fields.iter().map(|field| &field.ident);
|
||||||
|
|
||||||
TokenStream::from(quote! {
|
TokenStream::from(quote! {
|
||||||
impl bevy::prelude::EntityArchetype for #struct_name {
|
impl #impl_generics bevy::prelude::EntityArchetype for #struct_name#ty_generics {
|
||||||
fn insert(self, world: &mut bevy::prelude::World) -> Entity {
|
fn insert(self, world: &mut bevy::prelude::World) -> Entity {
|
||||||
*world.insert((), vec![(
|
*world.insert((), vec![(
|
||||||
#(self.#field_name,)*
|
#(self.#field_name,)*
|
||||||
|
|||||||
@ -1,16 +1,18 @@
|
|||||||
use bevy::{
|
use bevy::{
|
||||||
prelude::*,
|
prelude::*,
|
||||||
render::{
|
render::{
|
||||||
render_graph::{PipelineDescriptor, resource_name, resource_providers::UniformResourceProvider},
|
render_graph::{
|
||||||
|
resource_name, resource_providers::UniformResourceProvider, PipelineDescriptor,
|
||||||
|
},
|
||||||
Shader, ShaderStage, Vertex,
|
Shader, ShaderStage, Vertex,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
use bevy_derive::Uniforms;
|
use bevy_derive::Uniforms;
|
||||||
|
|
||||||
#[derive(Uniforms)]
|
#[derive(Uniforms, Default)]
|
||||||
struct MyMaterial {
|
struct MyMaterial {
|
||||||
pub color: Vec4
|
pub color: Vec4,
|
||||||
}
|
}
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
@ -24,8 +26,10 @@ fn main() {
|
|||||||
resource_name::pass::MAIN,
|
resource_name::pass::MAIN,
|
||||||
pipeline_storage,
|
pipeline_storage,
|
||||||
PipelineDescriptor::build(
|
PipelineDescriptor::build(
|
||||||
shader_storage, Shader::from_glsl(
|
shader_storage,
|
||||||
ShaderStage::Vertex,r#"
|
Shader::from_glsl(
|
||||||
|
ShaderStage::Vertex,
|
||||||
|
r#"
|
||||||
#version 450
|
#version 450
|
||||||
layout(location = 0) in vec4 a_Pos;
|
layout(location = 0) in vec4 a_Pos;
|
||||||
layout(location = 0) out vec4 v_Position;
|
layout(location = 0) out vec4 v_Position;
|
||||||
@ -39,11 +43,12 @@ fn main() {
|
|||||||
v_Position = Model * vec4(a_Pos);
|
v_Position = Model * vec4(a_Pos);
|
||||||
gl_Position = ViewProj * v_Position;
|
gl_Position = ViewProj * v_Position;
|
||||||
}
|
}
|
||||||
"#),
|
"#,
|
||||||
|
),
|
||||||
)
|
)
|
||||||
.with_fragment_shader(
|
.with_fragment_shader(Shader::from_glsl(
|
||||||
Shader::from_glsl(
|
ShaderStage::Fragment,
|
||||||
ShaderStage::Fragment, r#"
|
r#"
|
||||||
#version 450
|
#version 450
|
||||||
layout(location = 0) in vec4 v_Position;
|
layout(location = 0) in vec4 v_Position;
|
||||||
layout(location = 0) out vec4 o_Target;
|
layout(location = 0) out vec4 o_Target;
|
||||||
@ -53,8 +58,8 @@ fn main() {
|
|||||||
void main() {
|
void main() {
|
||||||
o_Target = color;
|
o_Target = color;
|
||||||
}
|
}
|
||||||
"#)
|
"#,
|
||||||
)
|
))
|
||||||
.with_depth_stencil_state(wgpu::DepthStencilStateDescriptor {
|
.with_depth_stencil_state(wgpu::DepthStencilStateDescriptor {
|
||||||
format: wgpu::TextureFormat::Depth32Float,
|
format: wgpu::TextureFormat::Depth32Float,
|
||||||
depth_write_enabled: true,
|
depth_write_enabled: true,
|
||||||
@ -86,9 +91,16 @@ fn setup(world: &mut World) {
|
|||||||
|
|
||||||
world
|
world
|
||||||
.build()
|
.build()
|
||||||
// red cube
|
// cube
|
||||||
.add_archetype(MeshEntity {
|
.add_archetype(MeshMaterialEntity::<MyMaterial> {
|
||||||
mesh: cube_handle,
|
mesh: cube_handle,
|
||||||
|
renderable: Renderable {
|
||||||
|
pipelines: vec![Handle::new(2)],
|
||||||
|
..Default::default()
|
||||||
|
},
|
||||||
|
material: MyMaterial {
|
||||||
|
color: Vec4::new(1.0, 0.0, 0.0, 1.0),
|
||||||
|
},
|
||||||
..Default::default()
|
..Default::default()
|
||||||
})
|
})
|
||||||
// camera
|
// camera
|
||||||
|
|||||||
@ -15,6 +15,15 @@ pub struct MeshEntity {
|
|||||||
pub translation: Translation,
|
pub translation: Translation,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(EntityArchetype, Default)]
|
||||||
|
pub struct MeshMaterialEntity<T: Default + Send + Sync + 'static> {
|
||||||
|
pub mesh: Handle<Mesh>,
|
||||||
|
pub material: T,
|
||||||
|
pub renderable: Renderable,
|
||||||
|
pub local_to_world: LocalToWorld,
|
||||||
|
pub translation: Translation,
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(EntityArchetype, Default)]
|
#[derive(EntityArchetype, Default)]
|
||||||
pub struct LightEntity {
|
pub struct LightEntity {
|
||||||
pub light: Light,
|
pub light: Light,
|
||||||
|
|||||||
@ -6,7 +6,7 @@ pub use crate::{
|
|||||||
ecs::{default_archetypes::*, EntityArchetype, WorldBuilder, WorldBuilderSource},
|
ecs::{default_archetypes::*, EntityArchetype, WorldBuilder, WorldBuilderSource},
|
||||||
render::{
|
render::{
|
||||||
ActiveCamera, ActiveCamera2d, Camera, CameraType, Instanced, Light,
|
ActiveCamera, ActiveCamera2d, Camera, CameraType, Instanced, Light,
|
||||||
render_graph::StandardMaterial,
|
render_graph::{StandardMaterial, Renderable},
|
||||||
},
|
},
|
||||||
ui::{Anchors, Margins, Node},
|
ui::{Anchors, Margins, Node},
|
||||||
};
|
};
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user