-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmaterial.pi
More file actions
54 lines (37 loc) · 1006 Bytes
/
material.pi
File metadata and controls
54 lines (37 loc) · 1006 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
use raytracepl::vec3::Vec3;
// use raytracepl::hittable::Material;
// use raytracepl::hittable::HitRecord;
use raytracepl::ray::Ray;
use raytracepl::utils::*;
pub type Mat = Lambertian | Metal | Dielectric;
pub struct Lambertian {
pub albedo: Vec3;
}
pub fn new_lam(a:Vec3) Lambertian {
return Lambertian { albedo: a };
}
pub struct Metal {
pub albedo: Vec3;
pub fuzz:f64;
}
pub fn new_metal(a:Vec3, f:f64) Metal {
if f < 1.0 {
return Metal { albedo: a, fuzz: f };
} else {
return Metal { albedo: a, fuzz: 1.0 };
}
}
pub struct Dielectric {
pub ir: f64;
}
pub fn new_dielectric(index_of_refraction: f64) Dielectric {
return Dielectric { ir: index_of_refraction };
}
impl Dielectric {
pub fn reflectance(cosine: f64, ref_idx: f64) f64 {
// Use Schlick's approximation for reflectance.
let r0 = (1.0 - ref_idx) / (1.0 + ref_idx);
r0 = r0 * r0;
return r0 + (1.0 - r0) * pow((1.0 - cosine), 5.0);
}
}