From 83728cc9320ef1662cefb86995a6ee95125d6e54 Mon Sep 17 00:00:00 2001 From: Gael-de-Sailly Date: Tue, 22 Dec 2020 18:34:30 +0100 Subject: [PATCH] Fixed lakes elevation There were sometimes missing water patches near a lake's edge, when the neighbour catchment area was lower. This commit allows to divide a cell into several mini-catchment basins, to fill only a part of it with water. --- heightmap.lua | 20 +++++++++++++++++++- polygons.lua | 2 +- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/heightmap.lua b/heightmap.lua index f189249..10424a6 100644 --- a/heightmap.lua +++ b/heightmap.lua @@ -99,7 +99,25 @@ local function heightmaps(minp, maxp) xf, zf )) - local lake_height = math.max(math.floor(poly.lake), terrain_height) + -- Spatial gradient of the interpolation + local slope_x = zf*(vdem[3]-vdem[4]) + (1-zf)*(vdem[2]-vdem[1]) < 0 + local slope_z = xf*(vdem[3]-vdem[2]) + (1-xf)*(vdem[4]-vdem[1]) < 0 + local lake_id = 0 + if slope_x then + if slope_z then + lake_id = 3 + else + lake_id = 2 + end + else + if slope_z then + lake_id = 4 + else + lake_id = 1 + end + end + local lake_height = math.max(math.floor(poly.lake[lake_id]), terrain_height) + if imax > 0 and depth_factor_max > 0 then terrain_height = math.min(math.max(lake_height, sea_level) - math.floor(1+depth_factor_max*riverbed_slope), terrain_height) end diff --git a/polygons.lua b/polygons.lua index 0d70068..669ca30 100644 --- a/polygons.lua +++ b/polygons.lua @@ -185,7 +185,7 @@ local function make_polygons(minp, maxp) local poly_dem = {dem[iA], dem[iB], dem[iC], dem[iD]} polygon.dem = poly_dem - polygon.lake = math.min(lakes[iA], lakes[iB], lakes[iC], lakes[iD]) + polygon.lake = {lakes[iA], lakes[iB], lakes[iC], lakes[iD]} -- Now, rivers. -- Load river flux values for the 4 corners