1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59
use color::{Rgb, ToRgb}; use glin; use graphics; pub struct AmbientLight{ diffuse: Rgb<f32>, specular: Rgb<f32>, strength: f32, } impl AmbientLight{ pub fn new() -> AmbientLight{ AmbientLight{ diffuse: rgb!(0.02, 0.02, 0.02), specular: rgb!(0.02, 0.02, 0.02), strength: 1., } } pub fn diffuse(&self) -> &Rgb<f32>{ &self.diffuse } pub fn specular(&self) -> &Rgb<f32>{ &self.specular } pub fn strength(&self) -> f32{ self.strength } pub fn set_diffuse<C: ToRgb>(&mut self, color: &C){ self.diffuse = color.to_rgb(); } pub fn set_specular<C: ToRgb>(&mut self, color: &C){ self.specular = color.to_rgb(); } pub fn set_strength(&mut self, strength: f32){ self.strength = strength; } } impl ::Light for AmbientLight{ fn ty(&self) -> &str{ "AMBIENT_LIGHT" } fn uniforms(&self, _: &graphics::Mvp, _texture_bind_offset: &mut u32) -> Vec<glin::program::Uniform>{ uniforms!{ enabled: 1f32, type: 3f32, ambient_diffuse: self.diffuse * self.strength, ambient_specular: self.specular * self.strength, } } }