mirror of
https://github.com/bevyengine/bevy
synced 2024-11-21 20:23:28 +00:00
fix custom_shader example
This commit is contained in:
parent
6cf981c610
commit
ad7acb111a
4 changed files with 39 additions and 15 deletions
|
@ -17,11 +17,14 @@ pub fn derive_entity_archetype(input: TokenStream) -> TokenStream {
|
|||
_ => 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 field_name = fields.iter().map(|field| &field.ident);
|
||||
|
||||
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 {
|
||||
*world.insert((), vec![(
|
||||
#(self.#field_name,)*
|
||||
|
|
|
@ -1,16 +1,18 @@
|
|||
use bevy::{
|
||||
prelude::*,
|
||||
render::{
|
||||
render_graph::{PipelineDescriptor, resource_name, resource_providers::UniformResourceProvider},
|
||||
render_graph::{
|
||||
resource_name, resource_providers::UniformResourceProvider, PipelineDescriptor,
|
||||
},
|
||||
Shader, ShaderStage, Vertex,
|
||||
},
|
||||
};
|
||||
|
||||
use bevy_derive::Uniforms;
|
||||
|
||||
#[derive(Uniforms)]
|
||||
#[derive(Uniforms, Default)]
|
||||
struct MyMaterial {
|
||||
pub color: Vec4
|
||||
pub color: Vec4,
|
||||
}
|
||||
|
||||
fn main() {
|
||||
|
@ -24,8 +26,10 @@ fn main() {
|
|||
resource_name::pass::MAIN,
|
||||
pipeline_storage,
|
||||
PipelineDescriptor::build(
|
||||
shader_storage, Shader::from_glsl(
|
||||
ShaderStage::Vertex,r#"
|
||||
shader_storage,
|
||||
Shader::from_glsl(
|
||||
ShaderStage::Vertex,
|
||||
r#"
|
||||
#version 450
|
||||
layout(location = 0) in vec4 a_Pos;
|
||||
layout(location = 0) out vec4 v_Position;
|
||||
|
@ -39,11 +43,12 @@ fn main() {
|
|||
v_Position = Model * vec4(a_Pos);
|
||||
gl_Position = ViewProj * v_Position;
|
||||
}
|
||||
"#),
|
||||
"#,
|
||||
),
|
||||
)
|
||||
.with_fragment_shader(
|
||||
Shader::from_glsl(
|
||||
ShaderStage::Fragment, r#"
|
||||
.with_fragment_shader(Shader::from_glsl(
|
||||
ShaderStage::Fragment,
|
||||
r#"
|
||||
#version 450
|
||||
layout(location = 0) in vec4 v_Position;
|
||||
layout(location = 0) out vec4 o_Target;
|
||||
|
@ -53,8 +58,8 @@ fn main() {
|
|||
void main() {
|
||||
o_Target = color;
|
||||
}
|
||||
"#)
|
||||
)
|
||||
"#,
|
||||
))
|
||||
.with_depth_stencil_state(wgpu::DepthStencilStateDescriptor {
|
||||
format: wgpu::TextureFormat::Depth32Float,
|
||||
depth_write_enabled: true,
|
||||
|
@ -86,9 +91,16 @@ fn setup(world: &mut World) {
|
|||
|
||||
world
|
||||
.build()
|
||||
// red cube
|
||||
.add_archetype(MeshEntity {
|
||||
// cube
|
||||
.add_archetype(MeshMaterialEntity::<MyMaterial> {
|
||||
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()
|
||||
})
|
||||
// camera
|
||||
|
|
|
@ -15,6 +15,15 @@ pub struct MeshEntity {
|
|||
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)]
|
||||
pub struct LightEntity {
|
||||
pub light: Light,
|
||||
|
|
|
@ -6,7 +6,7 @@ pub use crate::{
|
|||
ecs::{default_archetypes::*, EntityArchetype, WorldBuilder, WorldBuilderSource},
|
||||
render::{
|
||||
ActiveCamera, ActiveCamera2d, Camera, CameraType, Instanced, Light,
|
||||
render_graph::StandardMaterial,
|
||||
render_graph::{StandardMaterial, Renderable},
|
||||
},
|
||||
ui::{Anchors, Margins, Node},
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue