-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLights.h
131 lines (124 loc) · 4.18 KB
/
Lights.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
#ifndef LIGHTS_H_
#define LIGHTS_H_
#include "Transform.h"
#define Z_FAR 1000000
using glm::vec3;
/**
* Abstract Base Class for all lights in the Scene
*
*/
class LightSource {
public:
LightSource(vec3 attenuationCoeff) :
attenuation(attenuationCoeff) {}
virtual vec3 computeLight(vec3 hitPoint, vec3 directionToEye,
vec3 diffuse, vec3 specular, float shininess,
vec3 objectNormal) = 0;
virtual void printInfo() = 0;
virtual vec3 getLightPosition() = 0;
virtual float getDistanceToLight(vec3 p) = 0;
protected:
vec3 attenuation;
};
/**
* Point light source
*
*/
class PointLight : public LightSource {
public:
/**
* Initialize PointLight
* @param input - float array containing light info
* @param attenuation - Coefficients for light attenuation
*
*/
PointLight(float* input, vec3 attenuation) :
xyz(vec3(input[0], input[1], input[2])),
rgb(vec3(input[3], input[4], input[5])),
LightSource(attenuation) {}
/**
* Compute the light of this source at a given point
*
* @param hitPoint - Point at which light is to be computed
* @param directionToEye - Direction to the eye, used for specular light
* @param diffuse - Diffuse properties of parent object of point
* @param specular - Specular properties of parent object of point
* @param shininess - Shininess of parent object of point
* @param objectNormal - Surface Normal of object
* @return The colour after computing the light
*/
vec3 computeLight(vec3 hitPoint, vec3 directionToEye,
vec3 diffuse, vec3 specular, float shininess,
vec3 objectNormal);
/**
* Print info about object
*
*/
void printInfo();
/**
* Get the position of the light
* @return Position of light
*/
vec3 getLightPosition() {return xyz;}
/**
* Get distance to light from a given point.
* @param p - Point to compute distance from
* @return Distance of light
*/
float getDistanceToLight(vec3 p) {return length(xyz-p);}
private:
// Light location, colour/intensity
vec3 xyz, rgb;
};
/**
* Directional light source
*
*/
class DirectionalLight : public LightSource {
public:
/**
* Initialize DirectionalLight
* @param input - float array containing light info
* @param attenuation - Coefficients for light attenuation
*
*/
DirectionalLight(float* input, vec3 attenuation) :
xyz(vec3(input[0], input[1], input[2])),
rgb(vec3(input[3], input[4], input[5])),
LightSource(attenuation) {}
/**
* Compute the light of this source at a given point
*
* @param hitPoint - Point at which light is to be computed
* @param directionToEye - Direction to the eye, used for specular light
* @param diffuse - Diffuse properties of parent object of point
* @param specular - Specular properties of parent object of point
* @param shininess - Shininess of parent object of point
* @param objectNormal - Surface Normal of object
* @return The colour after computing the light
*/
vec3 computeLight(vec3 hitPoint, vec3 directionToEye,
vec3 diffuse, vec3 specular, float shininess,
vec3 objectNormal);
/**
* Print info about object
*
*/
void printInfo();
/**
* Get the position of the light
* @return Position of light
*/
vec3 getLightPosition() {return xyz;}
/**
* Get distance to light from a given point.
* As directional light is infinitely far away, return Z_FAR
* @param p - Point to compute distance from
* @return Distance of light
*/
float getDistanceToLight(vec3 p) {return Z_FAR;}
private:
// Light location, colour/intensity
vec3 xyz, rgb;
};
#endif // LIGHTS_H_