mirror of
https://github.com/bevyengine/bevy
synced 2024-11-22 04:33:37 +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)]
|
||||
struct MyMaterial {
|
||||
pub color: Vec4,
|
||||
#[uniform(ignore, shader_def)]
|
||||
pub always_red: bool,
|
||||
}
|
||||
|
||||
fn main() {
|
||||
|
@ -57,6 +59,10 @@ fn main() {
|
|||
};
|
||||
void main() {
|
||||
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
|
||||
.build()
|
||||
// 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> {
|
||||
mesh: cube_handle,
|
||||
renderable: Renderable {
|
||||
|
@ -83,8 +102,10 @@ fn setup(world: &mut World) {
|
|||
..Default::default()
|
||||
},
|
||||
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()
|
||||
})
|
||||
// camera
|
||||
|
|
|
@ -6,7 +6,7 @@ pub use crate::{
|
|||
ecs::{default_archetypes::*, EntityArchetype, WorldBuilder, WorldBuilderSource},
|
||||
render::{
|
||||
ActiveCamera, ActiveCamera2d, Camera, CameraType, Instanced, Light,
|
||||
render_graph::{StandardMaterial, Renderable},
|
||||
render_graph::{StandardMaterial, Renderable, ShaderDefSuffixProvider},
|
||||
},
|
||||
ui::{Anchors, Margins, Node},
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue