Skip to content

Commit

Permalink
cooler sample scene
Browse files Browse the repository at this point in the history
  • Loading branch information
Jeremy5909 committed May 2, 2024
1 parent e182905 commit 5b51cc5
Showing 1 changed file with 41 additions and 22 deletions.
63 changes: 41 additions & 22 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use std::rc::Rc;
use camera::Camera;
use color::Color;
use material::{Dielectric, Lambertian, Metal};
use rand::{random, thread_rng, Rng};
use vec3::Vec3;

use crate::{hittable_list::HittableList, sphere::Sphere, vec3::Point3};
Expand All @@ -18,35 +19,53 @@ pub mod camera;
pub mod material;

fn main() {
let ground_mat = Lambertian {albedo: Color::new(0.8,0.8,0.0)};
let center_mat = Lambertian {albedo: Color::new(0.1, 0.2, 0.5)};
let left_mat = Dielectric { refraction_index: 1.5};
let bubble_mat = Dielectric { refraction_index: 1.0 / 1.5};
let right_mat = Metal {albedo: Color::new(0.8, 0.6, 0.2), fuzz: 1.0};

let mut world = HittableList::default();

let ground = Sphere::new(Point3::new(0.0, -100.5, -1.0), 100.0, Rc::new(ground_mat));
let center = Sphere::new(Point3::new(0.0, 0.0, -1.2), 0.5, Rc::new(center_mat));
let left = Sphere::new(Point3::new(-1.0, 0.0, -1.0), 0.5, Rc::new(left_mat));
let bubble = Sphere::new(Point3::new(-1.0, 0.0, -1.0), 0.4, Rc::new(bubble_mat));
let right = Sphere::new(Point3::new(1.0, 0.0, -1.0), 0.5, Rc::new(right_mat));
let ground_mat = Lambertian {albedo: Color::new(0.5,0.5,0.5)};
world.add(Rc::new(Sphere::new(Point3::new(0.0, -1000.0, 0.0), 1000.0, Rc::new(ground_mat))));

for a in -11..11 {
for b in -11..11 {
let choose_mat: f64 = random();
let center = Point3::new(a as f64 + 0.9*random::<f64>(), 0.2, b as f64+ 0.9*random::<f64>());

//?
if (center - Point3::new(4.0, 0.2, 0.0)).length() > 0.9 {
if choose_mat < 0.8 {
let albedo = Color::random() * Color::random();
let sphere_material = Lambertian{ albedo };
world.add(Rc::new(Sphere::new(center, 0.2, Rc::new(sphere_material))));
} else if choose_mat < 0.95 {
let albedo = Color::random() * Color::random();
let fuzz = thread_rng().gen_range(0.0..0.5);
let sphere_material = Metal { albedo, fuzz };
world.add(Rc::new(Sphere::new(center, 0.2, Rc::new(sphere_material))));
} else {
let sphere_material = Dielectric { refraction_index: 1.5};
world.add(Rc::new(Sphere::new(center, 0.2, Rc::new(sphere_material))));
}
}
}
}

world.add(Rc::new(ground));
world.add(Rc::new(center));
world.add(Rc::new(left));
world.add(Rc::new(bubble));
world.add(Rc::new(right));
let material_one = Dielectric { refraction_index: 1.5};
world.add(Rc::new(Sphere::new(Point3::new(0.0, 1.0, 0.0), 1.0, Rc::new(material_one))));
let material_two = Lambertian { albedo: Color::new(0.4, 0.2, 0.1) };
world.add(Rc::new(Sphere::new(Point3::new(-4.0, 1.0, 0.0), 1.0, Rc::new(material_two))));
let material_three = Metal { albedo: Color::new(0.7, 0.6, 0.5), fuzz: 0.0};
world.add(Rc::new(Sphere::new(Point3::new(4.0, 1.0, 0.0), 1.0, Rc::new(material_three))));

let mut cam = Camera::new(16.0/9.0, 400);
cam.samples_per_pixel = 100;


let mut cam = Camera::new(16.0/9.0, 1200);
cam.samples_per_pixel = 500;
cam.max_depth = 50;
cam.look_from = Point3::new(-2.0, 2.0, 1.0);
cam.look_at = Point3::new(0.0, 0.0, -1.0);
cam.look_from = Point3::new(13.0, 2.0, 3.0);
cam.look_at = Point3::new(0.0, 0.0, 0.0);
cam.vup = Vec3::new(0.0, 1.0, 0.0);
cam.fov = 20.0;
cam.defocus_angle = 10.0;
cam.focus_dist = 3.4;
cam.defocus_angle = 0.6;
cam.focus_dist = 10.0;

cam.render(&world);
}

0 comments on commit 5b51cc5

Please sign in to comment.