Moved shader to separate files

+ base.vert and base.frag
* adjusted pipeline.rs
This commit is contained in:
Steins7 2021-01-31 10:56:49 +01:00
parent 673ba2ba8c
commit 189708f026
3 changed files with 30 additions and 29 deletions

View File

@ -15,33 +15,8 @@ use super::{
mod attachement; mod attachement;
use self::attachement::Attachement; use self::attachement::Attachement;
const VERTEX_SOURCE: &str = static VERT_SRC: &'static str = include_str!("shaders/base.vert");
"#version 450 core static FRAG_SRC: &'static str = include_str!("shaders/base.frag");
layout (location = 0) in vec2 position;
layout (location = 1) in vec3 color;
layout (location = 0) out gl_PerVertex {
vec4 gl_Position;
};
layout (location = 1) out vec3 frag_color;
void main()
{
gl_Position = vec4(position, 0.0, 1.0);
frag_color = color;
}";
const FRAGMENT_SOURCE: &str =
"#version 450 core
layout (location = 0) out vec4 frag_color;
layout (location = 1) in vec3 color;
void main()
{
frag_color = vec4(color, 1);
}";
//--Pipeline implementation------------------------------------------------------------------------- //--Pipeline implementation-------------------------------------------------------------------------
#[derive(Debug)] #[derive(Debug)]
@ -93,13 +68,13 @@ where
debug!("Compiling shaders..."); debug!("Compiling shaders...");
let mut compiler = shaderc::Compiler::new().ok_or("shaderc not found")?; let mut compiler = shaderc::Compiler::new().ok_or("shaderc not found")?;
let vertex_compile_artifact = compiler let vertex_compile_artifact = compiler
.compile_into_spirv(VERTEX_SOURCE, shaderc::ShaderKind::Vertex, "vertex.vert", .compile_into_spirv(VERT_SRC, shaderc::ShaderKind::Vertex, "vertex.vert",
"main", "main",
None) None)
.map_err(|err| {error!("{}", err); .map_err(|err| {error!("{}", err);
"Could not compile vertex shader"})?; "Could not compile vertex shader"})?;
let fragment_compile_artifact = compiler let fragment_compile_artifact = compiler
.compile_into_spirv(FRAGMENT_SOURCE, shaderc::ShaderKind::Fragment, "fragement.frag", .compile_into_spirv(FRAG_SRC, shaderc::ShaderKind::Fragment, "fragement.frag",
"main", "main",
None) None)
.map_err(|err| {error!("{}", err); .map_err(|err| {error!("{}", err);

View File

@ -0,0 +1,10 @@
#version 450
layout (location = 0) out vec4 frag_color;
layout (location = 1) in vec3 color;
void main()
{
frag_color = vec4(color, 1);
}

View File

@ -0,0 +1,16 @@
#version 450
layout (location = 0) in vec2 position;
layout (location = 1) in vec3 color;
layout (location = 0) out gl_PerVertex {
vec4 gl_Position;
};
layout (location = 1) out vec3 frag_color;
void main()
{
gl_Position = vec4(position, 0.0, 1.0);
frag_color = color;
}