From e1514fae78052db286738efea00c16a1ce39b355 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C3=ABl=20Lemaire?= Date: Wed, 30 Jan 2013 22:06:29 +0000 Subject: [PATCH] paysages : Fixed bruneton aerial perspective. git-svn-id: https://subversion.assembla.com/svn/thunderk/paysages@512 b1fd45b6-86a6-48da-8261-f70d1f35bdcc --- TODO | 2 +- lib_paysages/atmosphere/bruneton.c | 28 +++++++++++++++++++++++++--- lib_paysages/renderer.c | 2 +- 3 files changed, 27 insertions(+), 5 deletions(-) diff --git a/TODO b/TODO index 835ad29..9351d8f 100644 --- a/TODO +++ b/TODO @@ -6,7 +6,7 @@ Technology Preview 2 : => Allow camera move and zoom. - Get rid of noise dialogs, for simpler settings. - Finalize Bruneton's model - => Fix artifacts on aerial perspective + => Fix artifacts on aerial perspective (mostly when sun is near horizon) => Fix blue appearance at night - Finalize lighting refactoring => Restore water filtering diff --git a/lib_paysages/atmosphere/bruneton.c b/lib_paysages/atmosphere/bruneton.c index e20fb88..3f16488 100644 --- a/lib_paysages/atmosphere/bruneton.c +++ b/lib_paysages/atmosphere/bruneton.c @@ -1144,6 +1144,7 @@ Color brunetonGetSkyColor(AtmosphereDefinition* definition, Vector3 eye, Vector3 { UNUSED(definition); + /* TODO Water height ? */ Vector3 x = {0.0, Rg + (max(eye.y, 0.0) + GROUND_OFFSET) * WORLD_SCALING, 0.0}; Vector3 v = v3Normalize(direction); Vector3 s = v3Normalize(v3Sub(sun_position, x)); @@ -1166,10 +1167,22 @@ Color brunetonGetSkyColor(AtmosphereDefinition* definition, Vector3 eye, Vector3 Color brunetonApplyAerialPerspective(Renderer* renderer, Vector3 location, Color base) { Vector3 eye = renderer->camera_location; - Vector3 direction = v3Scale(v3Sub(location, eye), WORLD_SCALING); Vector3 sun_position = v3Scale(renderer->atmosphere->getSunDirection(renderer), SUN_DISTANCE); - Vector3 x = {0.0, Rg + (max(eye.y, 0.0) + GROUND_OFFSET) * WORLD_SCALING, 0.0}; + double yoffset = GROUND_OFFSET - renderer->getWaterHeightInfo(renderer).base_height; + eye.y += yoffset; + location.y += yoffset; + if (eye.y < 0.0) + { + eye.y = 0.0; + } + if (location.y < 0.0) + { + location.y = 0.0; + } + Vector3 direction = v3Scale(v3Sub(location, eye), WORLD_SCALING); + + Vector3 x = {0.0, Rg + eye.y * WORLD_SCALING, 0.0}; Vector3 v = v3Normalize(direction); Vector3 s = v3Normalize(v3Sub(sun_position, x)); @@ -1197,7 +1210,16 @@ void brunetonGetLightingStatus(Renderer* renderer, LightStatus* status, Vector3 LightDefinition sun, irradiance; double muS; - double r0 = Rg + (max(lightingGetStatusLocation(status).y, 0.0) + GROUND_OFFSET) * WORLD_SCALING; + double altitude = lightingGetStatusLocation(status).y; + + double yoffset = GROUND_OFFSET - renderer->getWaterHeightInfo(renderer).base_height; + altitude += yoffset; + if (altitude < 0.0) + { + altitude = 0.0; + } + + double r0 = Rg + altitude * WORLD_SCALING; Vector3 up = {0.0, 1.0, 0.0}; Vector3 sun_position = v3Scale(renderer->atmosphere->getSunDirection(renderer), SUN_DISTANCE); Vector3 x = {0.0, r0, 0.0}; diff --git a/lib_paysages/renderer.c b/lib_paysages/renderer.c index 48fffbb..a83118d 100644 --- a/lib_paysages/renderer.c +++ b/lib_paysages/renderer.c @@ -6,7 +6,7 @@ #include "scenery.h" RayCastingResult _RAYCASTING_NULL = {0}; -HeightInfo _WATER_HEIGHT_INFO = {-1000000.0, -1000000.0, -1000000.0}; +HeightInfo _WATER_HEIGHT_INFO = {0.0, 0.0, 0.0}; static void* _renderFirstPass(void* data) {