mirror of
https://github.com/bevyengine/bevy
synced 2025-02-16 14:08:32 +00:00
add macro example to custom_shader
This commit is contained in:
parent
e0e0e41c33
commit
f820e4207c
2 changed files with 23 additions and 2 deletions
|
@ -13,6 +13,8 @@ use bevy_derive::Uniforms;
|
||||||
#[derive(Uniforms, Default)]
|
#[derive(Uniforms, Default)]
|
||||||
struct MyMaterial {
|
struct MyMaterial {
|
||||||
pub color: Vec4,
|
pub color: Vec4,
|
||||||
|
#[uniform(ignore, shader_def)]
|
||||||
|
pub always_red: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
|
@ -57,6 +59,10 @@ fn main() {
|
||||||
};
|
};
|
||||||
void main() {
|
void main() {
|
||||||
o_Target = color;
|
o_Target = color;
|
||||||
|
|
||||||
|
# ifdef always_red
|
||||||
|
o_Target = vec4(0.8, 0.0, 0.0, 1.0);
|
||||||
|
# endif
|
||||||
}
|
}
|
||||||
"#,
|
"#,
|
||||||
))
|
))
|
||||||
|
@ -76,6 +82,19 @@ fn setup(world: &mut World) {
|
||||||
world
|
world
|
||||||
.build()
|
.build()
|
||||||
// cube
|
// cube
|
||||||
|
.add_archetype(MeshMaterialEntity::<MyMaterial> {
|
||||||
|
mesh: cube_handle.clone(),
|
||||||
|
renderable: Renderable {
|
||||||
|
pipelines: vec![Handle::new(2)], // TODO: make this pipeline assignment cleaner
|
||||||
|
..Default::default()
|
||||||
|
},
|
||||||
|
material: MyMaterial {
|
||||||
|
color: Vec4::new(0.0, 0.8, 0.0, 1.0),
|
||||||
|
always_red: false,
|
||||||
|
},
|
||||||
|
..Default::default()
|
||||||
|
})
|
||||||
|
// cube
|
||||||
.add_archetype(MeshMaterialEntity::<MyMaterial> {
|
.add_archetype(MeshMaterialEntity::<MyMaterial> {
|
||||||
mesh: cube_handle,
|
mesh: cube_handle,
|
||||||
renderable: Renderable {
|
renderable: Renderable {
|
||||||
|
@ -83,8 +102,10 @@ fn setup(world: &mut World) {
|
||||||
..Default::default()
|
..Default::default()
|
||||||
},
|
},
|
||||||
material: MyMaterial {
|
material: MyMaterial {
|
||||||
color: Vec4::new(1.0, 0.0, 0.0, 1.0),
|
color: Vec4::new(0.0, 0.0, 0.0, 1.0),
|
||||||
|
always_red: true,
|
||||||
},
|
},
|
||||||
|
translation: Translation::new(3.0, 0.0, 0.0),
|
||||||
..Default::default()
|
..Default::default()
|
||||||
})
|
})
|
||||||
// camera
|
// camera
|
||||||
|
|
|
@ -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, Renderable},
|
render_graph::{StandardMaterial, Renderable, ShaderDefSuffixProvider},
|
||||||
},
|
},
|
||||||
ui::{Anchors, Margins, Node},
|
ui::{Anchors, Margins, Node},
|
||||||
};
|
};
|
||||||
|
|
Loading…
Add table
Reference in a new issue