forked from yiming-cai/OursCraft
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFog.cpp
More file actions
61 lines (53 loc) · 1.38 KB
/
Copy pathFog.cpp
File metadata and controls
61 lines (53 loc) · 1.38 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
#include "Fog.h"
Fog::Fog(glm::vec3 color, Camera * camera, float start, float end, float rate)
{
this->color = color;
this->camera = camera;
this->start = start;
this->end = end;
this->tempend = end;
this->rate = rate;
this->shaderList = new std::vector<GLuint>();
}
void Fog::setCamera(Camera * camera)
{
this->camera = camera;
}
void Fog::setColor(glm::vec3 color)
{
this->color = color;
}
void Fog::addShader(GLuint shader)
{
int i;
for (i = 0; i < this->shaderList->size(); ++i) {
if ((*shaderList)[i] == shader) break;
}
if (i >= this->shaderList->size()) {
this->shaderList->push_back(shader);
}
}
void Fog::fogUpdate(int available)
{
GLuint pos;
if (tempend <= start + 0.2) rate = fabs(rate);
if (tempend >= end) rate = -fabs(rate);
tempend += rate;
for (int i = 0; i < shaderList->size(); ++i) {
glUseProgram((*shaderList)[i]);
pos = glGetUniformLocation((*shaderList)[i], "disableFog");
glUniform1i(pos, available);
pos = glGetUniformLocation((*shaderList)[i], "fog_color");
glUniform3fv(pos, 1, &color[0]);
pos = glGetUniformLocation((*shaderList)[i], "fog_pos");
glUniform3fv(pos, 1, &((camera->camera_pos)[0]));
pos = glGetUniformLocation((*shaderList)[i], "fog_end");
glUniform1f(pos, tempend);
pos = glGetUniformLocation((*shaderList)[i], "fog_start");
glUniform1f(pos, start);
}
}
void Fog::setRate(float rate)
{
this->rate = rate;
}