@@ -3,6 +3,7 @@ use std::rc::Rc;
3
3
use camera:: Camera ;
4
4
use color:: Color ;
5
5
use material:: { Dielectric , Lambertian , Metal } ;
6
+ use rand:: { random, thread_rng, Rng } ;
6
7
use vec3:: Vec3 ;
7
8
8
9
use crate :: { hittable_list:: HittableList , sphere:: Sphere , vec3:: Point3 } ;
@@ -18,35 +19,53 @@ pub mod camera;
18
19
pub mod material;
19
20
20
21
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
-
27
22
let mut world = HittableList :: default ( ) ;
28
23
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
+ }
34
50
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) ) ) ) ;
40
57
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 ;
43
62
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) ;
46
65
cam. vup = Vec3 :: new ( 0.0 , 1.0 , 0.0 ) ;
47
66
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 ;
50
69
51
70
cam. render ( & world) ;
52
71
}
0 commit comments