Skip to content

Commit 5b51cc5

Browse files
committed
cooler sample scene
1 parent e182905 commit 5b51cc5

File tree

1 file changed

+41
-22
lines changed

1 file changed

+41
-22
lines changed

src/main.rs

+41-22
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ use std::rc::Rc;
33
use camera::Camera;
44
use color::Color;
55
use material::{Dielectric, Lambertian, Metal};
6+
use rand::{random, thread_rng, Rng};
67
use vec3::Vec3;
78

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

2021
fn main() {
21-
let ground_mat = Lambertian {albedo: Color::new(0.8,0.8,0.0)};
22-
let center_mat = Lambertian {albedo: Color::new(0.1, 0.2, 0.5)};
23-
let left_mat = Dielectric { refraction_index: 1.5};
24-
let bubble_mat = Dielectric { refraction_index: 1.0 / 1.5};
25-
let right_mat = Metal {albedo: Color::new(0.8, 0.6, 0.2), fuzz: 1.0};
26-
2722
let mut world = HittableList::default();
2823

29-
let ground = Sphere::new(Point3::new(0.0, -100.5, -1.0), 100.0, Rc::new(ground_mat));
30-
let center = Sphere::new(Point3::new(0.0, 0.0, -1.2), 0.5, Rc::new(center_mat));
31-
let left = Sphere::new(Point3::new(-1.0, 0.0, -1.0), 0.5, Rc::new(left_mat));
32-
let bubble = Sphere::new(Point3::new(-1.0, 0.0, -1.0), 0.4, Rc::new(bubble_mat));
33-
let right = Sphere::new(Point3::new(1.0, 0.0, -1.0), 0.5, Rc::new(right_mat));
24+
let ground_mat = Lambertian {albedo: Color::new(0.5,0.5,0.5)};
25+
world.add(Rc::new(Sphere::new(Point3::new(0.0, -1000.0, 0.0), 1000.0, Rc::new(ground_mat))));
26+
27+
for a in -11..11 {
28+
for b in -11..11 {
29+
let choose_mat: f64 = random();
30+
let center = Point3::new(a as f64 + 0.9*random::<f64>(), 0.2, b as f64+ 0.9*random::<f64>());
31+
32+
//?
33+
if (center - Point3::new(4.0, 0.2, 0.0)).length() > 0.9 {
34+
if choose_mat < 0.8 {
35+
let albedo = Color::random() * Color::random();
36+
let sphere_material = Lambertian{ albedo };
37+
world.add(Rc::new(Sphere::new(center, 0.2, Rc::new(sphere_material))));
38+
} else if choose_mat < 0.95 {
39+
let albedo = Color::random() * Color::random();
40+
let fuzz = thread_rng().gen_range(0.0..0.5);
41+
let sphere_material = Metal { albedo, fuzz };
42+
world.add(Rc::new(Sphere::new(center, 0.2, Rc::new(sphere_material))));
43+
} else {
44+
let sphere_material = Dielectric { refraction_index: 1.5};
45+
world.add(Rc::new(Sphere::new(center, 0.2, Rc::new(sphere_material))));
46+
}
47+
}
48+
}
49+
}
3450

35-
world.add(Rc::new(ground));
36-
world.add(Rc::new(center));
37-
world.add(Rc::new(left));
38-
world.add(Rc::new(bubble));
39-
world.add(Rc::new(right));
51+
let material_one = Dielectric { refraction_index: 1.5};
52+
world.add(Rc::new(Sphere::new(Point3::new(0.0, 1.0, 0.0), 1.0, Rc::new(material_one))));
53+
let material_two = Lambertian { albedo: Color::new(0.4, 0.2, 0.1) };
54+
world.add(Rc::new(Sphere::new(Point3::new(-4.0, 1.0, 0.0), 1.0, Rc::new(material_two))));
55+
let material_three = Metal { albedo: Color::new(0.7, 0.6, 0.5), fuzz: 0.0};
56+
world.add(Rc::new(Sphere::new(Point3::new(4.0, 1.0, 0.0), 1.0, Rc::new(material_three))));
4057

41-
let mut cam = Camera::new(16.0/9.0, 400);
42-
cam.samples_per_pixel = 100;
58+
59+
60+
let mut cam = Camera::new(16.0/9.0, 1200);
61+
cam.samples_per_pixel = 500;
4362
cam.max_depth = 50;
44-
cam.look_from = Point3::new(-2.0, 2.0, 1.0);
45-
cam.look_at = Point3::new(0.0, 0.0, -1.0);
63+
cam.look_from = Point3::new(13.0, 2.0, 3.0);
64+
cam.look_at = Point3::new(0.0, 0.0, 0.0);
4665
cam.vup = Vec3::new(0.0, 1.0, 0.0);
4766
cam.fov = 20.0;
48-
cam.defocus_angle = 10.0;
49-
cam.focus_dist = 3.4;
67+
cam.defocus_angle = 0.6;
68+
cam.focus_dist = 10.0;
5069

5170
cam.render(&world);
5271
}

0 commit comments

Comments
 (0)