-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathshader.h
137 lines (118 loc) · 4.21 KB
/
shader.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
#ifndef SHADER_HEADER
#define SHADER_HEADER
#include "util.h"
#include "lightSource.h"
#include "hittable.h"
#include <memory>
#include <vector>
class Shader
{
public:
virtual Util::Color computeColor(
const std::vector<std::unique_ptr<LightSource>> &lightSources,
Math::Ray viewRay,
std::shared_ptr<Renderable> surface,
std::shared_ptr<Util::HitRecord> hitRecord
) const = 0;
};
class StaticColorShader : public Shader
{
public:
StaticColorShader();
StaticColorShader(Util::Color surfaceColor);
Util::Color getSurfaceColor() const;
void setSurfaceColor(Util::Color color);
Util::Color computeColor(
const std::vector<std::unique_ptr<LightSource>> &lightSources,
Math::Ray viewRay,
std::shared_ptr<Renderable> surface,
std::shared_ptr<Util::HitRecord> hitRecord
) const;
protected:
Util::Color surfaceColor;
};
class LambertShader : public StaticColorShader
{
public:
LambertShader();
LambertShader(Util::Color surfaceColor);
Util::Color computeColor(
const std::vector<std::unique_ptr<LightSource>> &lightSources,
Math::Ray viewRay,
std::shared_ptr<Renderable> surface,
std::shared_ptr<Util::HitRecord> hitRecord
) const;
};
class BlinnPhongShader : public Shader
{
// TODO: add an option to make the reflective color the color of the light
public:
BlinnPhongShader();
BlinnPhongShader(float phongExponent);
BlinnPhongShader(Util::Color specularColor);
BlinnPhongShader(float phongExponent, Util::Color specularColor);
float getPhongExponent() const;
Util::Color getSpecularColor() const;
void setPhongExponent(float phongExponent);
void setSpecularColor(Util::Color specularColor);
Util::Color computeColor(
const std::vector<std::unique_ptr<LightSource>> &lightSources,
Math::Ray viewRay,
std::shared_ptr<Renderable> surface,
std::shared_ptr<Util::HitRecord> hitRecord
) const;
private:
Util::Color specularColor;
float phongExponent;
};
// combination of lambert, blinn-phong, and ambient shading
class StandardShader : public Shader
{
public:
StandardShader();
StandardShader(float ambientIntensity, Util::Color ambientColor);
StandardShader(float ambientIntensity, float phongExponent);
StandardShader(Util::Color surfaceColor, Util::Color specularColor, Util::Color ambientColor);
StandardShader(float ambientIntensity, Util::Color ambientColor, float phongExponent, Util::Color surfaceColor, Util::Color specularColor);
float getAmbientIntensity() const;
float getPhongExponent() const;
Util::Color getSurfaceColor() const;
Util::Color getSpecularColor() const;
Util::Color getAmbientColor() const;
void setAmbientIntensity(float ambientIntensity);
void setPhongExponent(float phongExponent);
void setSurfaceColor(Util::Color surfaceColor);
void setSpecularColor(Util::Color specularColor);
void setAmbientColor(Util::Color ambientColor);
Util::Color computeColor(
const std::vector<std::unique_ptr<LightSource>> &lightSources,
Math::Ray viewRay,
std::shared_ptr<Renderable> surface,
std::shared_ptr<Util::HitRecord> hitRecord
) const;
private:
Util::Color surfaceColor, specularColor, ambientColor;
float ambientIntensity, phongExponent;
};
class MirrorShader : public Shader
{
public:
MirrorShader();
MirrorShader(float specularWeight);
MirrorShader(Util::Color backgroundColor, Util::Color specularColor, float specularWeight);
void setBackgroundColor(Util::Color backgroundColor);
void setSpecularColor(Util::Color specularColor);
void setSpecularWeight(float specularWeight);
// TODO: figure out a way to add a specular component
Util::Color computeColor(
const std::vector<std::unique_ptr<LightSource>> &lightSources,
Math::Ray viewRay,
std::shared_ptr<Renderable> surface,
std::shared_ptr<Util::HitRecord> hitRecord
) const;
private:
Util::Color backgroundColor = { 255, 255, 255 };
Util::Color specularColor = { 0, 0, 0 };
float specularWeight = 0; // number in [0, 1] that defines how much of the total is specular color and how much is reflected color
};
#endif