From 4039bad9f963f1e45757e8efaf8f67fdc2e66859 Mon Sep 17 00:00:00 2001 From: Faerbit Date: Fri, 21 Nov 2014 02:46:02 +0100 Subject: [PATCH] Improved fog a little bit. --- Shader/phong.fsh | 5 +++-- graphics.cc | 3 ++- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/Shader/phong.fsh b/Shader/phong.fsh index 4a5b9dc..e76524b 100644 --- a/Shader/phong.fsh +++ b/Shader/phong.fsh @@ -22,6 +22,7 @@ uniform vec3 lightColors[128]; uniform float lightIntensities[128]; uniform float fogStart; uniform vec4 fogColor; +uniform vec3 cameraCenter; void main() { @@ -52,8 +53,8 @@ void main() } vec3 finalColor = specularColor + diffuseColor + ambientColor; - float distanceCamera = distance(camera, vec3(fragPosition)); - float fogFactor = clamp((1.0 - exp(-distanceCamera+fogStart)), 0.0, 1.0); + float distanceCameraCenter = distance(cameraCenter, vec3(fragPosition)); + float fogFactor = clamp((1.0 - exp(-distanceCameraCenter+fogStart)), 0.0, 1.0); fogFactor = mix(fogFactor, 0.0, clamp((1.0 - exp(-fragPosition.y+20.0)), 0.0, 1.0)); vec4 texture = texture(uTexture, vTexCoord).rgba; diff --git a/graphics.cc b/graphics.cc index 4a919ba..e83bda1 100644 --- a/graphics.cc +++ b/graphics.cc @@ -140,8 +140,9 @@ void Graphics::render(Level* level, ACGL::OpenGL::SharedShaderProgram shader) } // set fog Parameters - shader->setUniform("fogStart", farPlane-50.0f); + shader->setUniform("fogStart", (float)((farPlane-40.0f)/sqrt(2))); shader->setUniform("fogColor", level->getFogColor()); + shader->setUniform("cameraCenter", level->getCameraCenter()->getPosition()); // set Material Parameters shader->setUniform("ambientColor", level->getAmbientLight());