-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPointLight.cpp
88 lines (72 loc) · 2.79 KB
/
PointLight.cpp
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
#include "PointLight.h"
PointLight::PointLight() :
Light(),
LightPosition{ glm::vec3(1.0f,1.0f,1.0f) },
a{ 0.f },
b{ 0.f },
c{ 1.f },
NearPlane{ 0.1f },
FarPlane{ 100.f }
{
delete sMap;
sMap = new OmniShadowMap();
float AspectRatio = (float)(ShadowMapWidth / ShadowMapHeight);
LightProjection = glm::perspective(glm::radians(90.f), AspectRatio, NearPlane, FarPlane);
}
PointLight::PointLight
( glm::vec4 AmbientLightParams,
GLfloat DiffuseIntensity,
GLuint SMapWidth,
GLuint SMapHeight,
glm::vec3 LightPositionParams,
glm::vec3 EquationCoeffs,
GLfloat nPlane,
GLfloat fPlane)
:
Light(AmbientLightParams, DiffuseIntensity, SMapWidth,SMapHeight),
LightPosition{LightPositionParams},
a{EquationCoeffs.x},
b{ EquationCoeffs.y },
c{ EquationCoeffs.z },
NearPlane{nPlane},
FarPlane{fPlane}
{
delete sMap;
sMap = new OmniShadowMap();
float AspectRatio = (float)(ShadowMapWidth / ShadowMapHeight);
LightProjection = glm::perspective(glm::radians(90.f), AspectRatio, NearPlane, FarPlane);
}
void PointLight::UseLight(GLuint AmbientColorLocation, GLuint AmbientIntensityLocation, GLuint DiffuseIntensityUniformLocation, GLuint LightPositionUniformLocation, GLuint CoeffAUniformLocation, GLuint CoeffBUniformLocation, GLuint CoeffCUniformLocation)
{ //Passes light information into the shaders
Light::UseLight(AmbientColorLocation, AmbientIntensityLocation, DiffuseIntensityUniformLocation);
glUniform3f(LightPositionUniformLocation, LightPosition.x, LightPosition.y, LightPosition.z);
glUniform1f(CoeffAUniformLocation, a);
glUniform1f(CoeffBUniformLocation, b);
glUniform1f(CoeffCUniformLocation, c);
}
std::vector<glm::mat4> PointLight::CalculateLightMatrices()
{
std::vector<glm::mat4> lightMatrices;
glm::mat4 temp;
temp= LightProjection* glm::lookAt( LightPosition, LightPosition + glm::vec3(1.0, 0.0, 0.0) ,glm::vec3(0.f, -1.f, 0.f) );
lightMatrices.push_back(temp);
temp = LightProjection * glm::lookAt(LightPosition, LightPosition + glm::vec3(-1.0, 0.0, 0.0), glm::vec3(0.f, -1.f, 0.f) );
lightMatrices.push_back(temp);
temp = LightProjection * glm::lookAt(LightPosition, LightPosition + glm::vec3(0.0, 1.0, 0.0), glm::vec3(0.f, 0.f , 1.f));
lightMatrices.push_back(temp);
temp = LightProjection * glm::lookAt(LightPosition, LightPosition + glm::vec3(0.0,- 1.0, 0.0), glm::vec3(0.f, 0.f, -1.f));
lightMatrices.push_back(temp);
temp = LightProjection * glm::lookAt(LightPosition, LightPosition + glm::vec3(0.0, 0.0, 1.f), glm::vec3(0.0f, -1.f, 0.f));
lightMatrices.push_back(temp);
temp = LightProjection * glm::lookAt(LightPosition, LightPosition + glm::vec3(0.0, 0.0, -1.f), glm::vec3(0.f, -1.f, 0.f));
lightMatrices.push_back(temp);
return lightMatrices;
}
GLfloat PointLight::GetFarPlane()
{
return FarPlane;
}
glm::vec3 PointLight::GetLightPosition()
{
return LightPosition;
}