Created
August 30, 2023 07:38
-
-
Save IceSentry/85987dfee4537b542421174e690ee377 to your computer and use it in GitHub Desktop.
Simple quad material
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//! A shader and a material that uses it. | |
use bevy::{ | |
prelude::*, | |
reflect::{TypePath, TypeUuid}, | |
render::render_resource::{AsBindGroup, ShaderRef}, | |
}; | |
use bevy_internal::window::WindowResized; | |
fn main() { | |
App::new() | |
.add_plugins((DefaultPlugins, MaterialPlugin::<CustomMaterial>::default())) | |
.add_systems(Startup, setup) | |
.run(); | |
} | |
fn setup( | |
mut commands: Commands, | |
mut meshes: ResMut<Assets<Mesh>>, | |
mut materials: ResMut<Assets<CustomMaterial>>, | |
asset_server: Res<AssetServer>, | |
) { | |
commands.spawn(MaterialMeshBundle { | |
mesh: meshes.add(Mesh::from(shape::Quad { | |
size: Vec2::new(16.0, 9.0) * 0.1, | |
flip: false, | |
})), | |
transform: Transform::from_xyz(0.0, 0.5, 0.0), | |
material: materials.add(CustomMaterial {}), | |
..default() | |
}); | |
commands.spawn(Camera3dBundle { | |
transform: Transform::from_xyz(0.0, 0.5, 1.0), | |
..default() | |
}); | |
} | |
#[derive(AsBindGroup, TypeUuid, TypePath, Debug, Clone)] | |
#[uuid = "f690fdae-d598-45ab-8225-97e2a3f056e0"] | |
pub struct CustomMaterial {} | |
impl Material for CustomMaterial { | |
fn fragment_shader() -> ShaderRef { | |
"simple_material.wgsl".into() | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#import bevy_pbr::mesh_vertex_output MeshVertexOutput | |
@fragment | |
fn fragment( | |
mesh: MeshVertexOutput, | |
) -> @location(0) vec4<f32> { | |
return vec4(mesh.uv.x, mesh.uv.y, 0.0, 1.0); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment