diff --git a/resources/shaders/gl_solid_color.frag b/resources/shaders/gl_solid_color.frag new file mode 100644 index 0000000..c3da69f --- /dev/null +++ b/resources/shaders/gl_solid_color.frag @@ -0,0 +1,11 @@ +#version 330 core +in vec3 v_normal; +out vec4 color; +uniform vec3 light_dir; + +void main() { + float brightness = dot(normalize(v_normal), normalize(light_dir)); + vec3 dark_color = vec3(0.6, 0.0, 0.0); + vec3 regular_color = vec3(1.0, 0.0, 0.0); + color = vec4(mix(dark_color, regular_color, brightness), 1.0); +} diff --git a/resources/shaders/gl_solid_color.vert b/resources/shaders/gl_solid_color.vert new file mode 100644 index 0000000..cc65b9f --- /dev/null +++ b/resources/shaders/gl_solid_color.vert @@ -0,0 +1,12 @@ +#version 330 core +in vec3 position; +in vec3 normal; +uniform mat4 model; +uniform mat4 view; +uniform mat4 projection; +out vec3 v_normal; +void main() { + mat4 modelview = view * model; + v_normal = transpose(inverse(mat3(modelview))) * normal; + gl_Position = projection * modelview * vec4(position, 1.0); +} diff --git a/src/render.rs b/src/render.rs index a4097db..58557af 100644 --- a/src/render.rs +++ b/src/render.rs @@ -23,34 +23,8 @@ pub struct GliumRenderer { impl GliumRenderer { /// Create a new OpenGL renderer consuming the provided `display`. pub fn new(display: glium::Display) -> anyhow::Result { - const VERT: &str = r#" - #version 330 core - in vec3 position; - in vec3 normal; - uniform mat4 model; - uniform mat4 view; - uniform mat4 projection; - out vec3 v_normal; - void main() { - mat4 modelview = view * model; - v_normal = transpose(inverse(mat3(modelview))) * normal; - gl_Position = projection * modelview * vec4(position, 1.0); - }"#; - - const FRAG: &str = r#" - #version 330 core - in vec3 v_normal; - out vec4 color; - uniform vec3 light_dir; - - void main() { - float brightness = dot(normalize(v_normal), normalize(light_dir)); - vec3 dark_color = vec3(0.6, 0.0, 0.0); - vec3 regular_color = vec3(1.0, 0.0, 0.0); - color = vec4(mix(dark_color, regular_color, brightness), 1.0); - }"#; - - + const VERT: &str = include_str!("../resources/shaders/gl_solid_color.vert"); + const FRAG: &str = include_str!("../resources/shaders/gl_solid_color.frag"); let program = Program::from_source(&display, VERT, FRAG, None)?;