Implemented simple fog.
This commit is contained in:
parent
1c848f35e6
commit
9367026ef0
@ -20,6 +20,8 @@ uniform float directionalIntensity;
|
|||||||
uniform vec3 lightSources[128];
|
uniform vec3 lightSources[128];
|
||||||
uniform vec3 lightColors[128];
|
uniform vec3 lightColors[128];
|
||||||
uniform float lightIntensities[128];
|
uniform float lightIntensities[128];
|
||||||
|
uniform float fogStart;
|
||||||
|
uniform vec3 fogColor;
|
||||||
|
|
||||||
void main()
|
void main()
|
||||||
{
|
{
|
||||||
@ -48,7 +50,11 @@ void main()
|
|||||||
*specularFactor*intensity*lightColors[i];
|
*specularFactor*intensity*lightColors[i];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
vec3 finalColor = specularColor + diffuseColor + ambientColor;
|
vec3 finalColor = specularColor + diffuseColor + ambientColor;
|
||||||
|
float distanceCamera = distance(camera, vec3(fragPosition));
|
||||||
|
float fogFactor = clamp((1.0 - exp(-distanceCamera+fogStart)), 0.0, 1.0);
|
||||||
|
finalColor = mix(finalColor, fogColor, fogFactor);
|
||||||
|
|
||||||
vec4 texture = texture(uTexture, vTexCoord).rgba;
|
vec4 texture = texture(uTexture, vTexCoord).rgba;
|
||||||
oColor = vec4(finalColor, 1.0f)*texture;
|
oColor = vec4(finalColor, 1.0f)*texture;
|
||||||
|
@ -139,9 +139,13 @@ void Graphics::render(Level* level, ACGL::OpenGL::SharedShaderProgram shader)
|
|||||||
level->getDirectionalLight()->getIntensity());
|
level->getDirectionalLight()->getIntensity());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// set fog Parameters
|
||||||
|
shader->setUniform("fogStart", farPlane-50.0f);
|
||||||
|
shader->setUniform("fogColor", level->getFogColor());
|
||||||
|
|
||||||
// set Material Parameters
|
// set Material Parameters
|
||||||
shader->setUniform("ambientColor", level->getAmbientLight());
|
shader->setUniform("ambientColor", level->getAmbientLight());
|
||||||
shader->setUniform("camera", glm::vec3(0.0f, 0.0f, 0.0f));
|
shader->setUniform("camera", level->getCameraPosition());
|
||||||
|
|
||||||
// render the level(currently only a bunny):
|
// render the level(currently only a bunny):
|
||||||
level->render();
|
level->render();
|
||||||
|
5
level.cc
5
level.cc
@ -54,6 +54,7 @@ void Level::load(ACGL::OpenGL::SharedShaderProgram shader) {
|
|||||||
|
|
||||||
//set lighting parameters
|
//set lighting parameters
|
||||||
ambientLight = glm::vec3(1.0f, 1.0f, 1.0f);
|
ambientLight = glm::vec3(1.0f, 1.0f, 1.0f);
|
||||||
|
fogColor = glm::vec3(0.10f, 0.14f, 0.14f);
|
||||||
directionalLight = Light(glm::vec3(-0.5f, 0.0f, -0.5f), glm::vec3(1.0f, 1.0f, 0.0f), 0.4f);
|
directionalLight = Light(glm::vec3(-0.5f, 0.0f, -0.5f), glm::vec3(1.0f, 1.0f, 0.0f), 0.4f);
|
||||||
Light light = Light(glm::vec3(-3.0f, 7.0f, 0.0f), glm::vec3(1.0f, 1.0f, 1.0f), 5.0f);
|
Light light = Light(glm::vec3(-3.0f, 7.0f, 0.0f), glm::vec3(1.0f, 1.0f, 1.0f), 5.0f);
|
||||||
lights.push_back(light);
|
lights.push_back(light);
|
||||||
@ -134,6 +135,10 @@ Light* Level::getDirectionalLight() {
|
|||||||
return &directionalLight;
|
return &directionalLight;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
glm::vec3 Level::getFogColor() {
|
||||||
|
return fogColor;
|
||||||
|
}
|
||||||
|
|
||||||
glm::vec3 Level::getCameraPosition() {
|
glm::vec3 Level::getCameraPosition() {
|
||||||
return cameraCenter->getPosition() + camera.getVector();
|
return cameraCenter->getPosition() + camera.getVector();
|
||||||
}
|
}
|
||||||
|
2
level.hh
2
level.hh
@ -24,11 +24,13 @@ class Level {
|
|||||||
Object* getCameraCenter();
|
Object* getCameraCenter();
|
||||||
Camera* getCamera();
|
Camera* getCamera();
|
||||||
glm::vec3 getCameraPosition();
|
glm::vec3 getCameraPosition();
|
||||||
|
glm::vec3 getFogColor();
|
||||||
private:
|
private:
|
||||||
std::string filePath;
|
std::string filePath;
|
||||||
std::vector<Object> objects;
|
std::vector<Object> objects;
|
||||||
std::vector<Light> lights;
|
std::vector<Light> lights;
|
||||||
glm::vec3 ambientLight;
|
glm::vec3 ambientLight;
|
||||||
|
glm::vec3 fogColor;
|
||||||
Light directionalLight;
|
Light directionalLight;
|
||||||
Object* cameraCenter;
|
Object* cameraCenter;
|
||||||
Physics physics;
|
Physics physics;
|
||||||
|
Loading…
Reference in New Issue
Block a user