diff --git a/assets/shaders/color.frag b/assets/shaders/color.frag index ad218bd..13bc6f6 100644 --- a/assets/shaders/color.frag +++ b/assets/shaders/color.frag @@ -4,12 +4,16 @@ uniform sampler2D tex; uniform vec3 diffuse; in vec3 v_color; +in vec2 v_tex_coords; out vec4 color; 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; + } } diff --git a/assets/shaders/color.vert b/assets/shaders/color.vert index e8ebcc2..4abafe8 100644 --- a/assets/shaders/color.vert +++ b/assets/shaders/color.vert @@ -10,8 +10,10 @@ in vec3 normal; in vec3 face_color; out vec3 v_color; +out vec2 v_tex_coords; void main() { 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); } diff --git a/src/exporter/mod.rs b/src/exporter/mod.rs index c8c7b06..995e2ba 100644 --- a/src/exporter/mod.rs +++ b/src/exporter/mod.rs @@ -33,6 +33,10 @@ impl From for ExportError { /// Exports a 3D model to a certain format. 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 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; /// 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; } /// Serialize a 3D element. diff --git a/src/renderer.rs b/src/renderer.rs index de51b24..19ace14 100644 --- a/src/renderer.rs +++ b/src/renderer.rs @@ -11,6 +11,7 @@ use glium::{Frame, Display, Surface, Program, DrawParameters, Depth, VertexBuffe use glium::draw_parameters::{DepthTest, Blend}; use glium::index::{NoIndices, PrimitiveType}; use glium::glutin::GlWindow; +use glium::program::ProgramCreationInput; use scene::Scene; use camera::{RenderCamera, mat_to_f32}; @@ -59,22 +60,30 @@ impl Renderer { /// Creates the program with the default shader. pub fn default_shader(display: &Display) -> Program { - Program::from_source( - display, - include_str!("../assets/shaders/default.vert"), - include_str!("../assets/shaders/default.frag"), - None - ).unwrap() + Program::new(display, ProgramCreationInput::SourceCode { + vertex_shader: include_str!("../assets/shaders/default.vert"), + fragment_shader: include_str!("../assets/shaders/default.frag"), + geometry_shader: None, + tessellation_control_shader: None, + tessellation_evaluation_shader: None, + transform_feedback_varyings: None, + outputs_srgb: false, + uses_point_size: false, + }).unwrap() } /// Creates the shader with one color per face. pub fn color_shader(display: &Display) -> Program { - Program::from_source( - display, - include_str!("../assets/shaders/color.vert"), - include_str!("../assets/shaders/color.frag"), - None - ).unwrap() + Program::new(display, ProgramCreationInput::SourceCode { + vertex_shader: include_str!("../assets/shaders/color.vert"), + fragment_shader: include_str!("../assets/shaders/color.frag"), + geometry_shader: None, + tessellation_control_shader: None, + tessellation_evaluation_shader: None, + transform_feedback_varyings: None, + outputs_srgb: true, + uses_point_size: false, + }).unwrap() } /// Creates a new renderer from a display.