-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpointLight.h
121 lines (113 loc) · 3.86 KB
/
pointLight.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
//
// pointLight.h
// test
//
// Created by Nazirul Hasan on 22/9/23.
//
#ifndef pointLight_h
#define pointLight_h
#include <glad/glad.h>
#include <glm/glm.hpp>
#include "shader.h"
class PointLight {
public:
glm::vec3 position;
glm::vec3 ambient;
glm::vec3 diffuse;
glm::vec3 specular;
float k_c;
float k_l;
float k_q;
int lightNumber;
PointLight(float posX, float posY, float posZ, float ambR, float ambG, float ambB, float diffR, float diffG, float diffB, float specR, float specG, float specB, float constant, float linear, float quadratic, int num) {
position = glm::vec3(posX, posY, posZ);
ambient = glm::vec3(ambR, ambG, ambB);
diffuse = glm::vec3(diffR, diffG, diffB);
specular = glm::vec3(specR, specG, specB);
k_c = constant;
k_l = linear;
k_q = quadratic;
lightNumber = num;
}
void setUpPointLight(Shader& lightingShader)
{
lightingShader.use();
if (lightNumber == 1) {
lightingShader.setVec3("pointLights[0].position", position);
lightingShader.setVec3("pointLights[0].ambient", ambient * ambientOn * isOn);
lightingShader.setVec3("pointLights[0].diffuse", diffuse * diffuseOn * isOn);
lightingShader.setVec3("pointLights[0].specular", specular * specularOn * isOn);
lightingShader.setFloat("pointLights[0].k_c", k_c);
lightingShader.setFloat("pointLights[0].k_l", k_l);
lightingShader.setFloat("pointLights[0].k_q", k_q);
}
else if (lightNumber == 2)
{
lightingShader.setVec3("pointLights[1].position", position);
lightingShader.setVec3("pointLights[1].ambient", ambient * ambientOn * isOn);
lightingShader.setVec3("pointLights[1].diffuse", diffuse * diffuseOn * isOn);
lightingShader.setVec3("pointLights[1].specular", specular * specularOn * isOn);
lightingShader.setFloat("pointLights[1].k_c", k_c);
lightingShader.setFloat("pointLights[1].k_l", k_l);
lightingShader.setFloat("pointLights[1].k_q", k_q);
}
else if (lightNumber == 3)
{
lightingShader.setVec3("pointLights[2].position", position);
lightingShader.setVec3("pointLights[2].ambient", ambient * ambientOn * isOn);
lightingShader.setVec3("pointLights[2].diffuse", diffuse * diffuseOn * isOn);
lightingShader.setVec3("pointLights[2].specular", specular * specularOn * isOn);
lightingShader.setFloat("pointLights[2].k_c", k_c);
lightingShader.setFloat("pointLights[2].k_l", k_l);
lightingShader.setFloat("pointLights[2].k_q", k_q);
}
else
{
lightingShader.setVec3("pointLights[3].position", position);
lightingShader.setVec3("pointLights[3].ambient", ambient * ambientOn * isOn);
lightingShader.setVec3("pointLights[3].diffuse", diffuse * diffuseOn * isOn);
lightingShader.setVec3("pointLights[3].specular", specular * specularOn * isOn);
lightingShader.setFloat("pointLights[3].k_c", k_c);
lightingShader.setFloat("pointLights[3].k_l", k_l);
lightingShader.setFloat("pointLights[3].k_q", k_q);
}
}
void turnOff()
{
isOn = 0.0;
}
void turnOn()
{
isOn = 1.0;
}
void turnAmbientOn()
{
ambientOn = 1.0;
}
void turnAmbientOff()
{
ambientOn = 0.0;
}
void turnDiffuseOn()
{
diffuseOn = 1.0;
}
void turnDiffuseOff()
{
diffuseOn = 0.0;
}
void turnSpecularOn()
{
specularOn = 1.0;
}
void turnSpecularOff()
{
specularOn = 0.0;
}
private:
float ambientOn = 1.0;
float diffuseOn = 1.0;
float specularOn = 1.0;
float isOn = 1.0;
};
#endif /* pointLight_h */