wip
This commit is contained in:
parent
c592b8e971
commit
bc21beeb36
3 changed files with 39 additions and 13 deletions
14
assets/shaders/custom_material.frag
Normal file
14
assets/shaders/custom_material.frag
Normal file
|
|
@ -0,0 +1,14 @@
|
||||||
|
#version 450
|
||||||
|
|
||||||
|
layout(location = 0) in vec2 v_uv;
|
||||||
|
layout(location = 0) out vec4 o_color;
|
||||||
|
|
||||||
|
layout(set = 0, binding = 0) uniform MaterialUniform {
|
||||||
|
vec4 color;
|
||||||
|
} material;
|
||||||
|
|
||||||
|
void main() {
|
||||||
|
// simple uv-based gradient multiplied by uniform color
|
||||||
|
vec3 grad = vec3(v_uv, 0.5);
|
||||||
|
o_color = material.color * vec4(grad, 1.0);
|
||||||
|
}
|
||||||
12
assets/shaders/custom_material.vert
Normal file
12
assets/shaders/custom_material.vert
Normal file
|
|
@ -0,0 +1,12 @@
|
||||||
|
#version 450
|
||||||
|
|
||||||
|
// Minimal passthrough vertex shader for a fullscreen plane.
|
||||||
|
layout(location = 0) in vec3 Vertex_Position;
|
||||||
|
layout(location = 1) in vec2 Vertex_Uv;
|
||||||
|
|
||||||
|
layout(location = 0) out vec2 v_uv;
|
||||||
|
|
||||||
|
void main() {
|
||||||
|
v_uv = Vertex_Uv;
|
||||||
|
gl_Position = vec4(Vertex_Position, 1.0);
|
||||||
|
}
|
||||||
26
src/main.rs
26
src/main.rs
|
|
@ -1,7 +1,9 @@
|
||||||
//! A shader that uses the GLSL shading language.
|
//! A shader that uses the GLSL shading language.
|
||||||
|
|
||||||
use bevy::{
|
use bevy::{
|
||||||
prelude::*, reflect::TypePath, render::render_resource::AsBindGroup, render::render_resource::ShaderRef,
|
prelude::*,
|
||||||
|
reflect::TypePath,
|
||||||
|
render::render_resource::{AsBindGroup, ShaderRef},
|
||||||
};
|
};
|
||||||
|
|
||||||
/// This example uses shader source files from the assets subdirectory
|
/// This example uses shader source files from the assets subdirectory
|
||||||
|
|
@ -10,34 +12,32 @@ const FRAGMENT_SHADER_ASSET_PATH: &str = "shaders/custom_material.frag";
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
App::new()
|
App::new()
|
||||||
.add_plugins((DefaultPlugins, MaterialPlugin::<CustomMaterial>::default()))
|
.add_plugins(DefaultPlugins)
|
||||||
|
.add_plugins(MaterialPlugin::<CustomMaterial>::default())
|
||||||
.add_systems(Startup, setup)
|
.add_systems(Startup, setup)
|
||||||
.run();
|
.run();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// set up a simple 3D scene
|
/// set up a simple 2D-screen-like surface
|
||||||
fn setup(
|
fn setup(
|
||||||
mut commands: Commands,
|
mut commands: Commands,
|
||||||
mut meshes: ResMut<Assets<Mesh>>,
|
mut meshes: ResMut<Assets<Mesh>>,
|
||||||
mut materials: ResMut<Assets<CustomMaterial>>,
|
mut materials: ResMut<Assets<CustomMaterial>>,
|
||||||
asset_server: Res<AssetServer>,
|
|
||||||
) {
|
) {
|
||||||
// cube
|
// Fullscreen flat surface: use a very large, thin cuboid so it behaves like a plane
|
||||||
commands.spawn((
|
commands.spawn((
|
||||||
Mesh3d(meshes.add(Cuboid::default())),
|
Mesh3d(meshes.add(Cuboid::default())),
|
||||||
MeshMaterial3d(materials.add(CustomMaterial {
|
MeshMaterial3d(materials.add(CustomMaterial {
|
||||||
color: LinearRgba::BLUE,
|
color: LinearRgba::new(0.2, 0.6, 0.9, 1.0),
|
||||||
color_texture: None,
|
color_texture: None,
|
||||||
alpha_mode: AlphaMode::Blend,
|
alpha_mode: AlphaMode::Opaque,
|
||||||
})),
|
})),
|
||||||
Transform::from_xyz(0.0, 0.5, 0.0),
|
// Scale X/Y large to cover the camera view, keep Z very small to make it effectively a plane
|
||||||
|
Transform::from_scale(Vec3::new(2000.0, 2000.0, 0.01)),
|
||||||
));
|
));
|
||||||
|
|
||||||
// camera
|
// 2D camera so the scene renders as a flat screen
|
||||||
commands.spawn((
|
commands.spawn((Camera2d::default(), Transform::default()));
|
||||||
Camera3d::default(),
|
|
||||||
Transform::from_xyz(-2.0, 2.5, 5.0).looking_at(Vec3::ZERO, Vec3::Y),
|
|
||||||
));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// This is the struct that will be passed to your shader
|
// This is the struct that will be passed to your shader
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue