[Book 1] Listing 60 Section 10.4 Unecessary unit vector
The listing in question:
...
class lambertian : public material {
...
};
class metal : public material {
public:
metal(const color& a) : albedo(a) {}
bool scatter(const ray& r_in, const hit_record& rec, color& attenuation, ray& scattered)
const override {
vec3 reflected = reflect(unit_vector(r_in.direction()), rec.normal);
scattered = ray(rec.p, reflected);
attenuation = albedo;
return true;
}
private:
color albedo;
};
Also slightly above that, the text says:
The reflected ray direction in red is just v+2b. In our design, n is a unit vector, but v may not be. The length of b should be v⋅n. Because v points in, we will need a minus sign, yielding:
v may not be a unit vector, and it doesn't need to be. From my understanding the reflection formula only requires the normal vector to be a unit vector. The proof for this can be seen in this stackoverflow post. Thus the unit_vector call in the line
vec3 reflected = reflect(unit_vector(r_in.direction()), rec.normal);
is redundant and confusing.
Also of note is that:
The length of b should be v⋅n.
This may not be obvious to some readers (including but possibly not limited to me), so some elaboration or a link to the proof would be greatly appreciated.