move repeat material into materials module
parent
76f93c22ea
commit
faee438747
@ -1,3 +1,6 @@
|
||||
mod solid;
|
||||
mod repeat;
|
||||
|
||||
pub use solid::SolidMaterial;
|
||||
pub use repeat::RepeatMaterial;
|
||||
|
||||
|
@ -0,0 +1,55 @@
|
||||
use bevy::{
|
||||
asset::Handle,
|
||||
pbr::{AlphaMode, Material, MaterialPipeline, MaterialPipelineKey},
|
||||
reflect::TypeUuid,
|
||||
render::{
|
||||
color::Color,
|
||||
mesh::MeshVertexBufferLayout,
|
||||
render_resource::{
|
||||
AsBindGroup, RenderPipelineDescriptor, ShaderRef, SpecializedMeshPipelineError,
|
||||
},
|
||||
texture::Image,
|
||||
},
|
||||
};
|
||||
|
||||
#[derive(AsBindGroup, Clone, TypeUuid)]
|
||||
#[uuid = "d57ae039-8c67-4004-9370-5c522e256515"]
|
||||
pub struct RepeatMaterial {
|
||||
#[uniform(0)]
|
||||
pub color: Color,
|
||||
|
||||
#[texture(1)]
|
||||
#[sampler(2)]
|
||||
pub color_texture: Option<Handle<Image>>,
|
||||
|
||||
pub alpha_mode: AlphaMode,
|
||||
}
|
||||
|
||||
impl Material for RepeatMaterial {
|
||||
fn vertex_shader() -> ShaderRef {
|
||||
"shaders/repeat.vert".into()
|
||||
}
|
||||
|
||||
fn fragment_shader() -> ShaderRef {
|
||||
"shaders/repeat.frag".into()
|
||||
}
|
||||
|
||||
fn alpha_mode(&self) -> AlphaMode {
|
||||
self.alpha_mode
|
||||
}
|
||||
|
||||
fn specialize(
|
||||
_: &MaterialPipeline<Self>,
|
||||
descriptor: &mut RenderPipelineDescriptor,
|
||||
_: &MeshVertexBufferLayout,
|
||||
_: MaterialPipelineKey<Self>,
|
||||
) -> Result<(), SpecializedMeshPipelineError> {
|
||||
descriptor.vertex.entry_point = "main".into();
|
||||
let mut frag = descriptor
|
||||
.fragment
|
||||
.as_mut()
|
||||
.expect("should have a fragment entry point here");
|
||||
frag.entry_point = "main".into();
|
||||
Ok(())
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue