-
Notifications
You must be signed in to change notification settings - Fork 0
/
metal.h
39 lines (37 loc) · 1.25 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
#ifndef METAL_H
#define METAL_H
#include "material.h"
/*! Metal reflective type Material. */
class Metal : public Material {
public:
/** Create Metal Material for Object with specified Vector3D color and fuzz value.
*
* Example:
* Lambertian(Vector3D(1, 0, 0), 0.9);
*/
Metal(const Vector3D &a, double f) : m_vAlbedo(a) {
if (f < 1) { m_dFuzz = f; } // Shift ray scatter by dFuzz amount to blur reflection.
else { m_dFuzz = 1; } // If fuzz is disabled, do not alter reflection.
}
virtual bool Scatter(const Ray &r_in, const HitRecord &rec, Vector3D &attenuation, Ray &scattered) const {
Vector3D vReflected = Reflect(UnitVector(r_in.Direction()), rec.m_vNormal);
scattered = Ray(rec.m_vP, vReflected + m_dFuzz * RandomInUnitSphere());
attenuation = m_vAlbedo;
return (scattered.Direction().Dot(rec.m_vNormal) > 0);
}
virtual int MatType() const {
return 1;
}
virtual Vector3D MatColor() const {
return m_vAlbedo;
}
virtual double MatFuzz() const {
return m_dFuzz;
}
virtual double MatRef() const {
return 0;
}
Vector3D m_vAlbedo; //!< Vector3D attenuation of light absorbed or reflected from object.
double m_dFuzz; //!< 0.3 - 1.0 (double) value setting the randomness of reflections, thus blurring the metal surface.
};
#endif // METAL_H