Implemented simple fog.
This commit is contained in:
parent
faf548d3ee
commit
b12b917a44
@ -20,6 +20,8 @@ uniform float directionalIntensity;
|
||||
uniform vec3 lightSources[128];
|
||||
uniform vec3 lightColors[128];
|
||||
uniform float lightIntensities[128];
|
||||
uniform float fogStart;
|
||||
uniform vec3 fogColor;
|
||||
|
||||
void main()
|
||||
{
|
||||
@ -48,7 +50,11 @@ void main()
|
||||
*specularFactor*intensity*lightColors[i];
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
oColor = vec4(finalColor, 1.0f)*texture;
|
||||
|
@ -139,9 +139,13 @@ void Graphics::render(Level* level, ACGL::OpenGL::SharedShaderProgram shader)
|
||||
level->getDirectionalLight()->getIntensity());
|
||||
}
|
||||
|
||||
// set fog Parameters
|
||||
shader->setUniform("fogStart", farPlane-50.0f);
|
||||
shader->setUniform("fogColor", level->getFogColor());
|
||||
|
||||
// set Material Parameters
|
||||
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):
|
||||
level->render();
|
||||
|
5
level.cc
5
level.cc
@ -54,6 +54,7 @@ void Level::load(ACGL::OpenGL::SharedShaderProgram shader) {
|
||||
|
||||
//set lighting parameters
|
||||
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);
|
||||
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);
|
||||
@ -134,6 +135,10 @@ Light* Level::getDirectionalLight() {
|
||||
return &directionalLight;
|
||||
}
|
||||
|
||||
glm::vec3 Level::getFogColor() {
|
||||
return fogColor;
|
||||
}
|
||||
|
||||
glm::vec3 Level::getCameraPosition() {
|
||||
return cameraCenter->getPosition() + camera.getVector();
|
||||
}
|
||||
|
2
level.hh
2
level.hh
@ -24,11 +24,13 @@ class Level {
|
||||
Object* getCameraCenter();
|
||||
Camera* getCamera();
|
||||
glm::vec3 getCameraPosition();
|
||||
glm::vec3 getFogColor();
|
||||
private:
|
||||
std::string filePath;
|
||||
std::vector<Object> objects;
|
||||
std::vector<Light> lights;
|
||||
glm::vec3 ambientLight;
|
||||
glm::vec3 fogColor;
|
||||
Light directionalLight;
|
||||
Object* cameraCenter;
|
||||
Physics physics;
|
||||
|
Loading…
Reference in New Issue
Block a user