add different diffuse renderer
This commit is contained in:
parent
de16463c4e
commit
decae9d00d
2 changed files with 15 additions and 2 deletions
|
@ -27,7 +27,7 @@ fn ray_color(r: &Ray, world: &HittableList, depth: u32) -> Color {
|
|||
}
|
||||
|
||||
if world.hit(r, 0.0, f64::INFINITY, &mut rec) {
|
||||
let target = rec.p + rec.normal + Vec3::random_in_unit_sphere();
|
||||
let target = rec.p + rec.normal + Vec3::random_unit_vector(); // rec.p + rec.normal.random_in_hemisphere();
|
||||
return 0.5 * ray_color(&Ray::new(rec.p, target - rec.p), world, depth-1);
|
||||
}
|
||||
let unit_direction = r.direction();
|
||||
|
@ -43,7 +43,7 @@ fn main() {
|
|||
let aspect_ratio = 16.0 / 9.0;
|
||||
let image_width = 1000;
|
||||
let image_height = (image_width as f64 / aspect_ratio) as u32;
|
||||
let samples_per_pixel = 10_u32;
|
||||
let samples_per_pixel = 50_u32;
|
||||
let max_depth = 50;
|
||||
|
||||
// World
|
||||
|
|
13
src/vec3.rs
13
src/vec3.rs
|
@ -54,6 +54,19 @@ impl Vec3 {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn random_unit_vector() -> Self {
|
||||
Self::unit_vector(Self::random_in_unit_sphere())
|
||||
}
|
||||
|
||||
pub fn random_in_hemisphere(&self) -> Self {
|
||||
let in_unit_sphere = Self::random_in_unit_sphere();
|
||||
if Self::dot(in_unit_sphere, *self) > 0.0 {
|
||||
return in_unit_sphere;
|
||||
} else {
|
||||
return -1.0*in_unit_sphere;
|
||||
}
|
||||
}
|
||||
|
||||
pub fn x(&self) -> f64 {
|
||||
self.e[0]
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue