-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstaticShader.hpp
163 lines (104 loc) · 5.37 KB
/
staticShader.hpp
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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
#ifndef STATICSHADER_H
#define STATICSHADER_H
#include "shaderProgram.hpp"
#include "camera.hpp"
#include "math.hpp"
#include "Light.hpp"
/*
Class that represent Shader for Entity - Entity is All Models on Screen except Terrain and CubeMap.
Used to Load Uniform Data to Shaders
StaticShader extends ShaderProgram which is Parent Class for All Different Shaders in Program.
*/
class StaticShader: public ShaderProgram {
public:
static int const MAX_LIGHTS = 20; // Maximum Number of Lights
// Uniform Locations
int locaion_transformationMatrix;
int location_projectionMatrix;
int location_viewMatrix;
int location_lightPosition[MAX_LIGHTS];
int location_lightColor[MAX_LIGHTS];
int location_shineDamter;
int location_reflectivity;
int location_useFakeLighting;
int location_skyColor;
StaticShader():ShaderProgram("res/shaders/Object Shader/vert.glsl", "res/shaders/Object Shader/frag.glsl") {
bindAttributes();
getAllUniformLocations();
}
void bindAttributes() {
ShaderProgram::bindAttribute(0, "aPos");
ShaderProgram::bindAttribute(1, "aTexCoords");
ShaderProgram::bindAttribute(2, "aNormals");
}
void getAllUniformLocations() {
//std::cout << glGetUniformLocation(this->ID, "projectionMatrix") << std::endl;
this->locaion_transformationMatrix = ShaderProgram::getUniformLocation("transformationMatrix"); // Vraca ID
this->locaion_transformationMatrix = ShaderProgram::getUniformLocation("projectionMatrix"); // Vraca ID
this->location_viewMatrix = ShaderProgram::getUniformLocation("shineDamper"); // Vraca ID
this->location_viewMatrix = ShaderProgram::getUniformLocation("reflectivity"); // Vraca ID
this->location_viewMatrix = ShaderProgram::getUniformLocation("useFakeLighting"); // Vraca ID
this->location_viewMatrix = ShaderProgram::getUniformLocation("skyColor"); // Vraca ID
// Get Locations for All Lights
int i;
for(i = 0; i < this->MAX_LIGHTS; i++) {
std::string uniformName = "lightPosition[" + std::to_string(i) + std::string("]");
this->location_lightPosition[i] = StaticShader::getUniformLocation(uniformName.c_str());
uniformName = "lightColor[" + std::to_string(i) + std::string("]");
this->location_lightColor[i] = StaticShader::getUniformLocation(uniformName.c_str());
uniformName = "lightDistance[" + std::to_string(i) + "]";
this->location_viewMatrix = ShaderProgram::getUniformLocation(uniformName.c_str());
}
}
void loadSkyColor(float r, float g, float b) {
ShaderProgram::setVec3("skyColor", glm::vec3(r, g, b));
}
void loadFakeLightingVariable(bool useFake) {
ShaderProgram::setBool("useFakeLighting", useFake);
}
// Testirati mozda ne radi sa & ili * // ne radi umesto ovog se koristi u Render.cpp setMat4()
void loadTransformationMatrix(const glm::mat4 mat) {
ShaderProgram::loadMatrix(this->locaion_transformationMatrix, mat);
}
// ne radi umesto ovog se koristi u Render.cpp setMat4()
void loadProjectionMatrix(const glm::mat4 &mat) {
ShaderProgram::setMat4("transformationMatrix", mat); // Load Model Matrix to its Uniform on Vertex Shader
}
/// Should Be in Math.hpp
void loadViewMatrix(Camera camera) {
glm::mat4 viewMatrix = glm::mat4(1.0f);
viewMatrix = glm::lookAt(camera.position, camera.position + camera.cameraFront, camera.cameraUP);
ShaderProgram::setMat4("viewMatrix", viewMatrix);
}
// Load Lights Data to Vertex and Fragment Shader
void loadLight(std::vector<Light> light ) {
// Adding Lights to the Shaders
int i;
for(i = 0; i < this->MAX_LIGHTS; i++) {
if(i < light.size()) {
std::string uniformName = "lightPosition[" + std::to_string(i) + std::string("]");
ShaderProgram::setVec3(uniformName, light.at(i).position);
uniformName = "lightColor[" + std::to_string(i) + std::string("]");
ShaderProgram::setVec3(uniformName, light.at(i).color);
uniformName = "lightDistance[" + std::to_string(i) + std::string("]");
ShaderProgram::setVec3(uniformName, light.at(i).lightDistance);
} else { // Else If there is no Lights we need to Fill Arrays in Shaders
// If there is no lights we initialize Values of Array to 0.0
std::string uniformName = "lightPosition[" + std::to_string(i) + std::string("]");
ShaderProgram::setVec3(uniformName, glm::vec3(0.0f, 0.0f, 0.0f));
uniformName = "lightColor[" + std::to_string(i) + std::string("]");
ShaderProgram::setVec3(uniformName, glm::vec3(0.0f, 0.0f, 0.0f));
uniformName = "lightDistance[" + std::to_string(i) + std::string("]");
ShaderProgram::setVec3(uniformName, glm::vec3(1.0f, 0.0f, 0.0f));
}
}
}
void loadShineVariables(float shineDamper, float reflectivity) {
ShaderProgram::setFloat("shineDamper", shineDamper);
ShaderProgram::setFloat("reflectivity", reflectivity);
}
private:
char* VERTEX_FILE = "res/shaders/Object Shader/vert.glsl";
char* FRAGMENT_FILE = "res/shaders/Object Shader/frag.glsl";
};
#endif // STATICSHADER_H