Some commit
This commit is contained in:
parent
598365f913
commit
9349c45431
|
@ -12,6 +12,7 @@ vec3 directionnalLight = normalize(vec3(10,5,7));
|
||||||
vec3 directionnalLightFactor = vec3(0.6,0.6,0.6);
|
vec3 directionnalLightFactor = vec3(0.6,0.6,0.6);
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
|
|
||||||
vec3 lambertComponent = dot(directionnalLight, v_normal) * directionnalLightFactor;
|
vec3 lambertComponent = dot(directionnalLight, v_normal) * directionnalLightFactor;
|
||||||
lambertComponent = max(vec3(0.0, 0.0, 0.0), lambertComponent);
|
lambertComponent = max(vec3(0.0, 0.0, 0.0), lambertComponent);
|
||||||
|
|
||||||
|
@ -19,7 +20,7 @@ void main() {
|
||||||
|
|
||||||
color = factor * texture(tex, v_tex_coords);
|
color = factor * texture(tex, v_tex_coords);
|
||||||
|
|
||||||
if (color.a < 0.5) {
|
if (color.a < 0.05) {
|
||||||
discard;
|
discard;
|
||||||
} else {
|
} else {
|
||||||
color.a = 1.0;
|
color.a = 1.0;
|
||||||
|
|
|
@ -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.
|
/// A simple camera with its position, target and up vector.
|
||||||
|
#[derive(Clone)]
|
||||||
pub struct Camera {
|
pub struct Camera {
|
||||||
/// The position of the center of the camera.
|
/// The position of the center of the camera.
|
||||||
pub position: Vector3<f32>,
|
pub position: Vector3<f32>,
|
||||||
|
@ -99,7 +100,7 @@ impl Camera {
|
||||||
position: position,
|
position: position,
|
||||||
target: target,
|
target: target,
|
||||||
up: up,
|
up: up,
|
||||||
z_near: 0.01,
|
z_near: 0.0001,
|
||||||
z_far: 1000.0,
|
z_far: 1000.0,
|
||||||
aspect_ratio: 16.0 / 9.0
|
aspect_ratio: 16.0 / 9.0
|
||||||
}
|
}
|
||||||
|
|
|
@ -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.
|
/// Creates a vertex buffer that can be rendered for a part of the model.
|
||||||
pub fn build_vertex_buffer_for_part(
|
pub fn build_vertex_buffer_for_part(
|
||||||
vertices: &Vec<Vector3<f64>>,
|
vertices: &Vec<Vector3<f64>>,
|
||||||
|
@ -429,4 +443,9 @@ impl Model {
|
||||||
pub fn get_texture_by_name(&self, name: &str) -> Option<&SrgbTexture2d> {
|
pub fn get_texture_by_name(&self, name: &str) -> Option<&SrgbTexture2d> {
|
||||||
self.textures[name].as_ref()
|
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
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,7 +4,6 @@ use std::cell::Ref;
|
||||||
use std::borrow::Cow;
|
use std::borrow::Cow;
|
||||||
|
|
||||||
use image;
|
use image;
|
||||||
|
|
||||||
use glium::texture::{RawImage2d, SrgbTexture2d, Texture2dDataSink};
|
use glium::texture::{RawImage2d, SrgbTexture2d, Texture2dDataSink};
|
||||||
use glium::{Frame, Display, Surface, Program, DrawParameters, Depth, VertexBuffer};
|
use glium::{Frame, Display, Surface, Program, DrawParameters, Depth, VertexBuffer};
|
||||||
use glium::{Rect, BlitTarget};
|
use glium::{Rect, BlitTarget};
|
||||||
|
@ -88,11 +87,17 @@ impl Renderer {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Creates a 1x1 SrgbTexture with the color passed as parameter.
|
/// 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));
|
let image = RawImage2d::from_raw_rgba(vec![r, g, b, a], (1, 1));
|
||||||
SrgbTexture2d::new(&self.display, image).ok().unwrap()
|
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.
|
/// Creates a frame from the display.
|
||||||
pub fn draw(&self) -> Frame {
|
pub fn draw(&self) -> Frame {
|
||||||
self.display.draw()
|
self.display.draw()
|
||||||
|
@ -126,17 +131,17 @@ impl Renderer {
|
||||||
let texture = self.get_texture_of_part(&model, part);
|
let texture = self.get_texture_of_part(&model, part);
|
||||||
|
|
||||||
if let Some(texture) = texture {
|
if let Some(texture) = texture {
|
||||||
target.draw(
|
target.draw(
|
||||||
buffer,
|
buffer,
|
||||||
NoIndices(PrimitiveType::TrianglesList),
|
NoIndices(PrimitiveType::TrianglesList),
|
||||||
&self.program,
|
&self.program,
|
||||||
&uniform!(
|
&uniform!(
|
||||||
tex: texture,
|
tex: texture,
|
||||||
perspective: perspective,
|
perspective: perspective,
|
||||||
view: view,
|
view: view,
|
||||||
),
|
),
|
||||||
¶ms,
|
¶ms,
|
||||||
).unwrap();
|
).unwrap();
|
||||||
} else {
|
} else {
|
||||||
target.draw(
|
target.draw(
|
||||||
buffer,
|
buffer,
|
||||||
|
|
Loading…
Reference in New Issue