cannot get this shader to work yet

main
Jordan Orelli 1 year ago
parent c814bd3053
commit ded1b7f12f

@ -0,0 +1,18 @@
#version 450
layout(location = 0) in vec2 v_Uv;
layout(location = 0) out vec4 o_Target;
layout(set = 1, binding = 0) uniform RepeatMaterial {
vec4 Color;
};
layout(set = 1, binding = 1) uniform texture2D RepeatMaterial_texture;
layout(set = 1, binding = 2) uniform sampler RepeatMaterial_sampler;
void main() {
o_Target = Color * texture(sampler2D(RepeatMaterial_texture,RepeatMaterial_sampler), v_Uv);
}
// vim: set ft=glsl:

@ -0,0 +1,30 @@
#version 450
layout(location = 0) in vec3 Vertex_Position;
layout(location = 1) in vec3 Vertex_Normal;
layout(location = 2) in vec2 Vertex_Uv;
layout(location = 0) out vec2 v_Uv;
layout(set = 0, binding = 0) uniform CameraViewProj {
mat4 ViewProj;
mat4 View;
mat4 InverseView;
mat4 Projection;
vec3 WorldPosition;
float width;
float height;
};
layout(set = 2, binding = 0) uniform Mesh {
mat4 Model;
mat4 InverseTransposeModel;
uint flags;
};
void main() {
v_Uv = Vertex_Uv;
gl_Position = ViewProj * Model * vec4(Vertex_Position, 1.0);
}
// vim: set ft=glsl:

@ -1,17 +1,28 @@
use bevy::prelude::*; use bevy::{
pbr::{MaterialPipeline, MaterialPipelineKey},
prelude::*,
reflect::TypeUuid,
render::{
mesh::MeshVertexBufferLayout,
render_resource::{
AsBindGroup, RenderPipelineDescriptor, ShaderRef, SpecializedMeshPipelineError,
},
},
};
fn startup( fn startup(
mut commands: Commands, mut commands: Commands,
assets: Res<AssetServer>, assets: Res<AssetServer>,
mut meshes: ResMut<Assets<Mesh>>, mut meshes: ResMut<Assets<Mesh>>,
mut materials: ResMut<Assets<StandardMaterial>>, mut materials: ResMut<Assets<StandardMaterial>>,
mut tiled_materials: ResMut<Assets<RepeatMaterial>>,
) { ) {
// //
let texture = assets.load("grid-texture.png"); let texture = assets.load("grid-texture.png");
// // This is a solid texture
let material = materials.add(StandardMaterial { let material = materials.add(StandardMaterial {
base_color_texture: Some(texture), base_color_texture: Some(texture.clone()),
alpha_mode: AlphaMode::Opaque, alpha_mode: AlphaMode::Opaque,
unlit: true, unlit: true,
..default() ..default()
@ -21,7 +32,6 @@ fn startup(
commands.spawn(PbrBundle { commands.spawn(PbrBundle {
mesh: meshes.add(shape::Plane::from_size(5.0).into()), mesh: meshes.add(shape::Plane::from_size(5.0).into()),
material, material,
// material: materials.add(Color::rgb(0.3, 0.5, 0.3).into()),
..default() ..default()
}); });
@ -33,6 +43,17 @@ fn startup(
..default() ..default()
}); });
commands.spawn(MaterialMeshBundle {
mesh: meshes.add(Mesh::from(shape::Cube { size: 1.0 })),
material: tiled_materials.add(RepeatMaterial{
color: Color::BLUE,
color_texture: Some(texture.clone()),
alpha_mode: AlphaMode::Opaque,
}),
transform: Transform::from_xyz(2.0, 0.5, 0.0),
..default()
});
// single light source // single light source
commands.spawn(PointLightBundle { commands.spawn(PointLightBundle {
point_light: PointLight { point_light: PointLight {
@ -51,9 +72,49 @@ fn startup(
}); });
} }
#[derive(AsBindGroup, Clone, TypeUuid)]
#[uuid = "00000000-0000-0000-0000-000000000001"]
pub struct RepeatMaterial {
#[uniform(0)]
color: Color,
#[texture(1)]
#[sampler(2)]
color_texture: Option<Handle<Image>>,
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(())
}
}
fn main() { fn main() {
App::new() App::new()
.add_plugins(DefaultPlugins) .add_plugins(DefaultPlugins)
.add_plugin(MaterialPlugin::<RepeatMaterial>::default())
.add_startup_system(startup) .add_startup_system(startup)
.run(); .run();
} }

Loading…
Cancel
Save