-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMetal.java
More file actions
25 lines (22 loc) · 770 Bytes
/
Metal.java
File metadata and controls
25 lines (22 loc) · 770 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
public final class Metal implements Material {
private final Color albedo;
private final double fuzz;
public Metal(Color albedo) {
this(albedo, 0);
}
public Metal(Color albedo, double fuzz) {
this.albedo = albedo;
this.fuzz = fuzz < 1 ? fuzz : 1;
}
@Override
public boolean scatter(Ray rIn, HitRecord rec, ScatterRecord out) {
Vec3 reflected = Vec3.reflect(Vec3.unitVector(rIn.direction()), rec.normal);
reflected = Vec3.add(
Vec3.unitVector(reflected),
Vec3.multiply(fuzz, Vec3.randomUnitVector())
);
out.scattered = new Ray(rec.p, reflected);
out.attenuation = albedo;
return Vec3.dot(out.scattered.direction(), rec.normal) > 0;
}
}