Created
August 29, 2014 12:31
-
-
Save anonymous/e619e7835508af73ad19 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use std::num::zero; | |
use std::rand::Rng; | |
use std::rand::distributions::range::SampleRange; | |
use vecmath::vector::Vec3; | |
use vecmath::ray::Ray; | |
use lightray::Lightray; | |
use objecthit::ObjectHit; | |
pub trait Material<T> { | |
fn reflect<R: Rng>(&self, lray: &Lightray<T>, ohit: &ObjectHit<T>, r: &mut R) -> Lightray<T>; | |
fn has_emission(&self) -> bool; | |
fn emission(&self, wavelength: f32) -> f32; | |
} | |
pub struct Clay; | |
impl<T: Num + FloatMath + PartialOrd + SampleRange> Material<T> for Clay { | |
fn reflect<R: Rng>(&self, lray: &Lightray<T>, ohit: &ObjectHit<T>, rng: &mut R) -> Lightray<T> { | |
let new_dir = Vec3::cos_hemisphere(rng).align( | |
&if lray.ray.dir.dotv(&ohit.hit.normal) < zero() { ohit.hit.normal } else { ohit.hit.normal.cflip() } | |
); | |
Lightray::new(Ray::new(ohit.hit.pos, new_dir), lray.wavelength, 1f32) | |
} | |
fn has_emission(&self) -> bool { false } | |
fn emission(&self, wavelength: f32) -> f32 { 0.0f32 } | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment