-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmetal.h
39 lines (31 loc) · 1.21 KB
/
metal.h
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
#pragma once
#include "rt.h"
#include "material.h"
class metal : public material
{
public:
metal() : albe(color(1.0f)), fuzzy_factor(1.0f) {}
metal(const albedo& albe, double fuzzy) : albe(albe), fuzzy_factor(fuzzy) {}
metal(const color& albedo) : albe(albedo) {}
bool scatter(
const ray& r_in, hit_record& record,
color& attenuation, ray& scattered
) const override
{
vec3 reflected = reflect(r_in.direction(), record.normal);
reflected = normalize(reflected) + fuzzy_factor * random_unit_vector();
record.mat_type = mat_type;
// Update the ray time == r_in.time()
// scattered = ray(record.p, reflected);
// --------------------------
scattered = ray(record.p, reflected, r_in.get_time());
attenuation = albe;
// return true;
// Check after fuzzy, the reflected ray is in the same side as the origin reflected ray
return dot(normalize(record.normal), normalize(reflected)) > 0;
}
private:
albedo albe;
material_type mat_type = material_type::METAL;
double fuzzy_factor;
};