From f2d38f716537ed8bb7d24f9db3ed0ec83adbc7dc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C3=ABl=20Lemaire?= Date: Thu, 17 Dec 2015 19:51:40 +0100 Subject: [PATCH] Fixed atmosphere model producing artifacts below ground surface --- src/interface/commandline/tests.cpp | 2 +- src/render/opengl/shaders/atmosphere.frag | 5 +++-- src/render/software/AtmosphereModelBruneton.cpp | 4 +++- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/interface/commandline/tests.cpp b/src/interface/commandline/tests.cpp index 0703d4c..e328642 100644 --- a/src/interface/commandline/tests.cpp +++ b/src/interface/commandline/tests.cpp @@ -255,7 +255,7 @@ static void testAtmosphereBruneton() { return result.final; } else { auto result = renderer->getAtmosphereRenderer()->applyAerialPerspective( - Vector3(-relx * 400.0, (rely + 1.0) * 20.0 - 10.0, 0.0), COLOR_BLACK); + Vector3(-relx * 400.0, (rely + 1.0) * 20.0, 0.0), COLOR_BLACK); return result.final; } } diff --git a/src/render/opengl/shaders/atmosphere.frag b/src/render/opengl/shaders/atmosphere.frag index be927dc..18ab5d8 100644 --- a/src/render/opengl/shaders/atmosphere.frag +++ b/src/render/opengl/shaders/atmosphere.frag @@ -246,7 +246,8 @@ vec3 applyWeatherEffects(float distance, vec3 base, vec3 _attenuation, vec3 _ins vec4 applyAerialPerspective(vec4 base) { - vec3 x = vec3(0.0, Rg + WORKAROUND_OFFSET + cameraLocation.y * WORLD_SCALING, 0.0); + vec3 location = vec3(unprojected.x, max(unprojected.y, 0.0), unprojected.z); + vec3 x = vec3(0.0, Rg + WORKAROUND_OFFSET + max(cameraLocation.y, 0.0) * WORLD_SCALING, 0.0); vec3 v = normalize(unprojected - cameraLocation); vec3 s = normalize(sunDirection * SUN_DISTANCE_SCALED - x); @@ -285,7 +286,7 @@ vec4 getSkyColor(vec3 location, vec3 direction) vec4 applyLighting(vec3 location, vec3 normal, vec4 color, float reflection, float shininess, float hardness) { - float r0 = Rg + WORKAROUND_OFFSET + location.y * WORLD_SCALING; + float r0 = Rg + WORKAROUND_OFFSET + max(location.y, 0.0) * WORLD_SCALING; vec3 sun_position = sunDirection * SUN_DISTANCE; float muS = dot(vec3(0.0, 1.0, 0.0), normalize(sun_position - vec3(0.0, r0, 0.0))); diff --git a/src/render/software/AtmosphereModelBruneton.cpp b/src/render/software/AtmosphereModelBruneton.cpp index 5d65737..1845e5d 100644 --- a/src/render/software/AtmosphereModelBruneton.cpp +++ b/src/render/software/AtmosphereModelBruneton.cpp @@ -1095,6 +1095,8 @@ AtmosphereResult AtmosphereModelBruneton::getSkyColor(Vector3 eye, const Vector3 AtmosphereResult AtmosphereModelBruneton::applyAerialPerspective(Vector3 location, const Color &base) { Vector3 eye = parent->getCameraLocation(location); + eye.y = max(eye.y, 0.0); + location.y = max(location.y, 0.0); Vector3 sun_position = parent->getAtmosphereRenderer()->getSunDirection().scale(SUN_DISTANCE); Vector3 direction = location.sub(eye).scale(WORLD_SCALING); @@ -1134,7 +1136,7 @@ bool AtmosphereModelBruneton::getLightsAt(vector &result, const LightComponent sun, irradiance; double muS; - double altitude = location.y * WORLD_SCALING; + double altitude = max(location.y * WORLD_SCALING, 0.0); double r0 = Rg + WORKAROUND_OFFSET + altitude; Vector3 up = {0.0, 1.0, 0.0};