Fixed color renderer

This commit is contained in:
Thomas Forgione 2018-10-31 11:55:17 +01:00
parent 8bea93e865
commit 28189bbd33
No known key found for this signature in database
GPG Key ID: 203DAEA747F48F41
4 changed files with 33 additions and 14 deletions

View File

@ -4,12 +4,16 @@ uniform sampler2D tex;
uniform vec3 diffuse; uniform vec3 diffuse;
in vec3 v_color; in vec3 v_color;
in vec2 v_tex_coords;
out vec4 color; out vec4 color;
void main() { void main() {
color = vec4(v_color, 1.0); color = vec4(v_color.x, v_color.y, v_color.z, 1.0);
if (texture(tex, v_tex_coords).a < 0.05) {
discard;
}
} }

View File

@ -10,8 +10,10 @@ in vec3 normal;
in vec3 face_color; in vec3 face_color;
out vec3 v_color; out vec3 v_color;
out vec2 v_tex_coords;
void main() { void main() {
v_color = face_color; v_color = face_color;
v_tex_coords = vec2(tex_coords.x * texture_size.x, tex_coords.y * texture_size.y);
gl_Position = perspective * view * vec4(vertex, 1.0); gl_Position = perspective * view * vec4(vertex, 1.0);
} }

View File

@ -33,6 +33,10 @@ impl From<io::Error> for ExportError {
/// Exports a 3D model to a certain format. /// Exports a 3D model to a certain format.
pub trait Exporter { pub trait Exporter {
/// If an exporter wants to send some return value during the export.
type Output;
/// The type of errors the exporter will return in case of errors. /// The type of errors the exporter will return in case of errors.
/// ///
/// The errors can be of many things, we can't know everything in this create, so this type /// The errors can be of many things, we can't know everything in this create, so this type
@ -40,7 +44,7 @@ pub trait Exporter {
type Error; type Error;
/// Performs the export in the specified output directory. /// Performs the export in the specified output directory.
fn export(&self, model: &Model, output_dir: &str) -> Result<(), Self::Error>; fn export(&self, model: &Model, output_dir: &str) -> Result<Self::Output, Self::Error>;
} }
/// Serialize a 3D element. /// Serialize a 3D element.

View File

@ -11,6 +11,7 @@ use glium::{Frame, Display, Surface, Program, DrawParameters, Depth, VertexBuffe
use glium::draw_parameters::{DepthTest, Blend}; use glium::draw_parameters::{DepthTest, Blend};
use glium::index::{NoIndices, PrimitiveType}; use glium::index::{NoIndices, PrimitiveType};
use glium::glutin::GlWindow; use glium::glutin::GlWindow;
use glium::program::ProgramCreationInput;
use scene::Scene; use scene::Scene;
use camera::{RenderCamera, mat_to_f32}; use camera::{RenderCamera, mat_to_f32};
@ -59,22 +60,30 @@ impl Renderer {
/// Creates the program with the default shader. /// Creates the program with the default shader.
pub fn default_shader(display: &Display) -> Program { pub fn default_shader(display: &Display) -> Program {
Program::from_source( Program::new(display, ProgramCreationInput::SourceCode {
display, vertex_shader: include_str!("../assets/shaders/default.vert"),
include_str!("../assets/shaders/default.vert"), fragment_shader: include_str!("../assets/shaders/default.frag"),
include_str!("../assets/shaders/default.frag"), geometry_shader: None,
None tessellation_control_shader: None,
).unwrap() tessellation_evaluation_shader: None,
transform_feedback_varyings: None,
outputs_srgb: false,
uses_point_size: false,
}).unwrap()
} }
/// Creates the shader with one color per face. /// Creates the shader with one color per face.
pub fn color_shader(display: &Display) -> Program { pub fn color_shader(display: &Display) -> Program {
Program::from_source( Program::new(display, ProgramCreationInput::SourceCode {
display, vertex_shader: include_str!("../assets/shaders/color.vert"),
include_str!("../assets/shaders/color.vert"), fragment_shader: include_str!("../assets/shaders/color.frag"),
include_str!("../assets/shaders/color.frag"), geometry_shader: None,
None tessellation_control_shader: None,
).unwrap() tessellation_evaluation_shader: None,
transform_feedback_varyings: None,
outputs_srgb: true,
uses_point_size: false,
}).unwrap()
} }
/// Creates a new renderer from a display. /// Creates a new renderer from a display.