-
Notifications
You must be signed in to change notification settings - Fork 0
/
material.h
56 lines (42 loc) · 1.11 KB
/
material.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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#pragma once
#include "common.h"
#include "color.h"
class HitRecord;
class Material
{
public:
virtual ~Material() = default;
virtual bool scatter(const Ray& r_in, const HitRecord& rec, Color& attenuation, Ray& scattered) const = 0;
};
class Lambertian : public Material
{
public:
Lambertian(const Color& a);
bool scatter(const Ray& r_in, const HitRecord& rec, Color& attenuation, Ray& scattered) const override;
private:
Color albedo;
};
class Metal : public Material
{
public:
Metal(const Color& a, double f);
bool scatter(const Ray& r_in, const HitRecord& rec, Color& attenuation, Ray& scattered) const override;
private:
Color albedo;
double fuzz;
};
class Dielectric : public Material
{
public:
Dielectric(double index_of_refraction);
bool scatter(const Ray& r_in, const HitRecord& rec, Color& attenuation, Ray& scattered) const override;
private:
double ir; // Index of refraction
static double reflectance(double cosine, double ref_idx)
{
// Use Schlick's approximation for reflectance
double r0 = (1 - ref_idx) / (1 + ref_idx);
r0 = r0 * r0;
return r0 + (1 - r0) * pow((1 - cosine), 5);
}
};