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