Some commit

This commit is contained in:
Thomas Forgione 2018-04-24 11:08:32 +02:00
parent 598365f913
commit 9349c45431
No known key found for this signature in database
GPG Key ID: 203DAEA747F48F41
4 changed files with 41 additions and 15 deletions

View File

@ -12,6 +12,7 @@ vec3 directionnalLight = normalize(vec3(10,5,7));
vec3 directionnalLightFactor = vec3(0.6,0.6,0.6);
void main() {
vec3 lambertComponent = dot(directionnalLight, v_normal) * directionnalLightFactor;
lambertComponent = max(vec3(0.0, 0.0, 0.0), lambertComponent);
@ -19,7 +20,7 @@ void main() {
color = factor * texture(tex, v_tex_coords);
if (color.a < 0.5) {
if (color.a < 0.05) {
discard;
} else {
color.a = 1.0;

View File

@ -71,6 +71,7 @@ pub fn perspective_matrix(aspect_ratio: f32, z_near: f32, z_far: f32) -> [[f32;
}
/// A simple camera with its position, target and up vector.
#[derive(Clone)]
pub struct Camera {
/// The position of the center of the camera.
pub position: Vector3<f32>,
@ -99,7 +100,7 @@ impl Camera {
position: position,
target: target,
up: up,
z_near: 0.01,
z_near: 0.0001,
z_far: 1000.0,
aspect_ratio: 16.0 / 9.0
}

View File

@ -374,6 +374,20 @@ impl Model {
}
}
/// Creates only non-existant vertex buffers, doesn't update the old ones.
pub fn build_new_vertex_buffers(&mut self, renderer: &Renderer) {
for part in &mut self.parts {
if part.vertex_buffer.is_none() {
Model::build_vertex_buffer_for_part(
&self.vertices,
&self.texture_coordinates,
&self.normals,
part,
renderer);
}
}
}
/// Creates a vertex buffer that can be rendered for a part of the model.
pub fn build_vertex_buffer_for_part(
vertices: &Vec<Vector3<f64>>,
@ -429,4 +443,9 @@ impl Model {
pub fn get_texture_by_name(&self, name: &str) -> Option<&SrgbTexture2d> {
self.textures[name].as_ref()
}
/// Returns a ref mut to the table of textures.
pub fn textures_mut(&mut self) -> &mut HashMap<String, Option<SrgbTexture2d>> {
&mut self.textures
}
}

View File

@ -4,7 +4,6 @@ use std::cell::Ref;
use std::borrow::Cow;
use image;
use glium::texture::{RawImage2d, SrgbTexture2d, Texture2dDataSink};
use glium::{Frame, Display, Surface, Program, DrawParameters, Depth, VertexBuffer};
use glium::{Rect, BlitTarget};
@ -88,11 +87,17 @@ impl Renderer {
}
/// Creates a 1x1 SrgbTexture with the color passed as parameter.
pub fn make_texture_from_color(&self, r: f32, g: f32, b: f32, a: f32) -> SrgbTexture2d {
pub fn make_texture_from_color_channels(&self, r: f32, g: f32, b: f32, a: f32) -> SrgbTexture2d {
let image = RawImage2d::from_raw_rgba(vec![r, g, b, a], (1, 1));
SrgbTexture2d::new(&self.display, image).ok().unwrap()
}
/// Creates a 1x1 SrgbTexture with the color passed as parameter.
pub fn make_texture_from_color(&self, c: (f32, f32, f32, f32)) -> SrgbTexture2d {
let image = RawImage2d::from_raw_rgba(vec![c.0, c.1, c.2, c.3], (1, 1));
SrgbTexture2d::new(&self.display, image).ok().unwrap()
}
/// Creates a frame from the display.
pub fn draw(&self) -> Frame {
self.display.draw()