-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPointLight.cpp
More file actions
73 lines (60 loc) · 2.47 KB
/
PointLight.cpp
File metadata and controls
73 lines (60 loc) · 2.47 KB
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
#include "PointLight.h"
PointLight::PointLight() : Light()
{
position = glm::vec3(0.0f, 0.0f, 0.0f);
constant = 1.0f;
linear = 0.0f;
exponent = 0.0f;
farPlane = 0.0f;
}
PointLight::PointLight(GLuint shadowWidth, GLuint shadowHeight,
GLfloat near, GLfloat far,
GLfloat red, GLfloat green, GLfloat blue,
GLfloat aIntensity, GLfloat dIntensity,
GLfloat xPos, GLfloat yPos, GLfloat zPos,
GLfloat con, GLfloat lin, GLfloat exp) : Light(shadowWidth, shadowHeight, red, green, blue, aIntensity, dIntensity)
{
position = glm::vec3(xPos, yPos, zPos);
constant = con;
linear = lin;
exponent = exp;
farPlane = far;
float aspect = (float)shadowWidth / (float)shadowHeight;
lightProj = glm::perspective(glm::radians(90.0f), aspect, near, far);
shadowMap = new OmniShadowMap();
shadowMap->init(shadowWidth, shadowHeight);
}
void PointLight::useLight(GLuint ambientIntensityLocation, GLuint ambientColourLocation,
GLuint diffuseIntensityLocation, GLuint positionLocation,
GLuint constantLocation, GLuint linearLocation, GLuint exponentLocation)
{
glUniform3f(ambientColourLocation, colour.x, colour.y, colour.z);
glUniform1f(ambientIntensityLocation, ambientIntensity);
glUniform1f(diffuseIntensityLocation, diffuseIntensity);
glUniform3f(positionLocation, position.x, position.y, position.z);
glUniform1f(constantLocation, constant);
glUniform1f(linearLocation, linear);
glUniform1f(exponentLocation, exponent);
}
std::vector<glm::mat4> PointLight::calculateLightTransform() {
std::vector<glm::mat4> lightMatrices;
// +x and -x
lightMatrices.push_back(lightProj * glm::lookAt(position, position + glm::vec3(1.0, 0.0, 0.0), glm::vec3(0.0, -1.0, 0.0)));
lightMatrices.push_back(lightProj * glm::lookAt(position, position + glm::vec3(-1.0, 0.0, 0.0), glm::vec3(0.0, -1.0, 0.0)));
// +y and -y
lightMatrices.push_back(lightProj * glm::lookAt(position, position + glm::vec3(0.0, 1.0, 0.0), glm::vec3(0.0, 0.0, 1.0)));
lightMatrices.push_back(lightProj * glm::lookAt(position, position + glm::vec3(0.0, -1.0, 0.0), glm::vec3(0.0, 0.0, -1.0)));
// +z and -z
lightMatrices.push_back(lightProj * glm::lookAt(position, position + glm::vec3(0.0, 0.0, 1.0), glm::vec3(0.0, -1.0, 0.0)));
lightMatrices.push_back(lightProj * glm::lookAt(position, position + glm::vec3(0.0, 0.0, -1.0), glm::vec3(0.0, -1.0, 0.0)));
return lightMatrices;
}
glm::vec3 PointLight::getPosition() {
return position;
}
GLfloat PointLight::getFarPlane() {
return farPlane;
}
PointLight::~PointLight()
{
}