Golden ratio 4 noise canyon generation, bugfixes, continental scale height variation

This commit is contained in:
paramat 2014-02-19 08:19:17 +00:00
parent e580ce7730
commit 1155082ec0
4 changed files with 84 additions and 39 deletions

View File

@ -1,4 +1,4 @@
watershed 0.2.0 by paramat watershed 0.2.1 by paramat
For latest stable Minetest back to 0.4.8 For latest stable Minetest back to 0.4.8
Depends default Depends default
Licenses: code WTFPL Licenses: code WTFPL

View File

@ -1,26 +1,22 @@
-- watershed 0.2.0 by paramat -- watershed 0.2.1 by paramat
-- For latest stable Minetest and back to 0.4.8 -- For latest stable Minetest and back to 0.4.8
-- Depends default -- Depends default
-- License: code WTFPL -- License: code WTFPL
-- TODO
-- Faults and strata
-- Arctan gradient?
-- Parameters -- Parameters
local YMIN = 6000 local YMIN = 6000
local YMAX = 8000 local YMAX = 8000 -- Top of atmosphere / mountains / floatlands
local TERCEN = 7008 -- Terrain centre local TERCEN = 7008 -- Terrain centre
local YWAT = 7024 -- Sea level local YWAT = 7104 -- Sea level
local TERSCA = 384 -- Vertical terrain scale local TERSCA = 512 -- Vertical terrain scale
local XLSAMP = 0 -- Extra large scale height variation amplitude
local BASAMP = 0.3 -- Base terrain amplitude local BASAMP = 0.3 -- Base terrain amplitude
local CANAMP = 0.7 -- Canyon terrain amplitude local CANAMP = 0.7 -- Canyon terrain amplitude
local CANEXP = 1.33 -- Canyon shape exponent local CANEXP = 1.33 -- Canyon shape exponent
local TSTONE = 0.02 -- Density threshold for stone local TSTONE = 0.015 -- Density threshold for stone
local TDIRT = 0.01 -- Density threshold for dirt local TRIV = -0.027 -- Maximum densitybase threshold for river water
local TRIV = -0.016 -- Maximum densitybase threshold for river water local TSAND = -0.03 -- Maximum densitybase threshold for sand
local TSAND = -0.02 -- Maximum densitybase threshold for sand
local PINCHA = 47 local PINCHA = 47
local APTCHA = 47 local APTCHA = 47
@ -41,6 +37,17 @@ local np_rough = {
persist = 0.63 persist = 0.63
} }
-- 3D alt noise for rough terrain
local np_roughalt = {
offset = 0,
scale = 1,
spread = {x=828, y=828, z=828},
seed = -7,
octaves = 6,
persist = 0.63
}
-- 3D noise for smooth terrain -- 3D noise for smooth terrain
local np_smooth = { local np_smooth = {
@ -52,6 +59,17 @@ local np_smooth = {
persist = 0.4 persist = 0.4
} }
-- 3D alt noise for smooth terrain
local np_smoothalt = {
offset = 0,
scale = 1,
spread = {x=828, y=828, z=828},
seed = -7,
octaves = 6,
persist = 0.4
}
-- 2D noise for base terrain / riverbed height / mountain ranges, terrain blend, river and river sand depth -- 2D noise for base terrain / riverbed height / mountain ranges, terrain blend, river and river sand depth
local np_base = { local np_base = {
@ -74,6 +92,17 @@ local np_biome = {
persist = 0.5 persist = 0.5
} }
-- 2D noise for extra large scale height variation
local np_xlscale = {
offset = 0,
scale = 1,
spread = {x=8192, y=8192, z=8192},
seed = -72,
octaves = 3,
persist = 0.4
}
-- Stuff -- Stuff
watershed = {} watershed = {}
@ -107,7 +136,6 @@ minetest.register_on_generated(function(minp, maxp, seed)
local c_sand = minetest.get_content_id("default:sand") local c_sand = minetest.get_content_id("default:sand")
local c_desand = minetest.get_content_id("default:desert_sand") local c_desand = minetest.get_content_id("default:desert_sand")
local c_snowblock = minetest.get_content_id("default:snowblock") local c_snowblock = minetest.get_content_id("default:snowblock")
local c_dirt = minetest.get_content_id("default:dirt")
local c_dirtsnow = minetest.get_content_id("default:dirt_with_snow") local c_dirtsnow = minetest.get_content_id("default:dirt_with_snow")
local c_jungrass = minetest.get_content_id("default:junglegrass") local c_jungrass = minetest.get_content_id("default:junglegrass")
@ -115,6 +143,7 @@ minetest.register_on_generated(function(minp, maxp, seed)
local c_wsstone = minetest.get_content_id("watershed:stone") local c_wsstone = minetest.get_content_id("watershed:stone")
local c_wsredstone = minetest.get_content_id("watershed:redstone") local c_wsredstone = minetest.get_content_id("watershed:redstone")
local c_wsgrass = minetest.get_content_id("watershed:grass") local c_wsgrass = minetest.get_content_id("watershed:grass")
local c_wsdirt = minetest.get_content_id("watershed:dirt")
local sidelen = x1 - x0 + 1 local sidelen = x1 - x0 + 1
local chulens = {x=sidelen, y=sidelen, z=sidelen} local chulens = {x=sidelen, y=sidelen, z=sidelen}
@ -123,9 +152,12 @@ minetest.register_on_generated(function(minp, maxp, seed)
local nvals_rough = minetest.get_perlin_map(np_rough, chulens):get3dMap_flat(minposxyz) local nvals_rough = minetest.get_perlin_map(np_rough, chulens):get3dMap_flat(minposxyz)
local nvals_smooth = minetest.get_perlin_map(np_smooth, chulens):get3dMap_flat(minposxyz) local nvals_smooth = minetest.get_perlin_map(np_smooth, chulens):get3dMap_flat(minposxyz)
local nvals_roughalt = minetest.get_perlin_map(np_roughalt, chulens):get3dMap_flat(minposxyz)
local nvals_smoothalt = minetest.get_perlin_map(np_smoothalt, chulens):get3dMap_flat(minposxyz)
local nvals_base = minetest.get_perlin_map(np_base, chulens):get2dMap_flat(minposxz) local nvals_base = minetest.get_perlin_map(np_base, chulens):get2dMap_flat(minposxz)
local nvals_biome = minetest.get_perlin_map(np_biome, chulens):get2dMap_flat(minposxz) local nvals_biome = minetest.get_perlin_map(np_biome, chulens):get2dMap_flat(minposxz)
local nvals_xlscale = minetest.get_perlin_map(np_xlscale, chulens):get2dMap_flat(minposxz)
local nixyz = 1 local nixyz = 1
local nixz = 1 local nixz = 1
@ -150,18 +182,19 @@ minetest.register_on_generated(function(minp, maxp, seed)
local si = x - x0 + 1 local si = x - x0 + 1
local grad = (TERCEN - y) / TERSCA local grad = (TERCEN - y) / TERSCA
local n_base = nvals_base[nixz] local n_base = nvals_base[nixz]
local n_biome = nvals_biome[nixz]
local terblen = 1 - math.abs(n_base) local terblen = 1 - math.abs(n_base)
local densitybase = terblen * BASAMP local densitybase = terblen * BASAMP + nvals_xlscale[nixz] * XLSAMP + grad
+ grad
local triv = TRIV * (1 - terblen * 1.1) -- 1.1 river disappears before ridge top local triv = TRIV * (1 - terblen * 1.1) -- 1.1 river disappears before ridge top
local tsand = TSAND * (1 - terblen * 1.1) local tsand = TSAND * (1 - terblen * 1.1)
local tstone = TSTONE * (1 + grad * 1.5) local tstone = TSTONE * (1 + grad * 1.5)
local density = densitybase local density = densitybase + math.abs(
+ math.abs(nvals_rough[nixyz] * terblen + nvals_smooth[nixyz] * (1 - terblen)) ^ CANEXP * CANAMP (nvals_rough[nixyz] + nvals_roughalt[nixyz]) / 2 * terblen
local n_biome = nvals_biome[nixz] + (nvals_smooth[nixyz] + nvals_smoothalt[nixyz]) / 2 * (1 - terblen)
) ^ CANEXP * CANAMP
if density >= tstone then -- stone if density >= tstone then -- stone
if n_biome > 0.5 then if n_biome > 0.7 then
data[vi] = c_wsredstone data[vi] = c_wsredstone
else else
data[vi] = c_wsstone data[vi] = c_wsstone
@ -175,16 +208,16 @@ minetest.register_on_generated(function(minp, maxp, seed)
data[vi] = c_desand data[vi] = c_desand
under[si] = 5 -- desert under[si] = 5 -- desert
elseif n_biome > 0.2 then elseif n_biome > 0.2 then
data[vi] = c_dirt data[vi] = c_wsdirt
under[si] = 4 -- rainforest under[si] = 4 -- rainforest
elseif n_biome > -0.2 then elseif n_biome > -0.2 then
data[vi] = c_dirt data[vi] = c_wsdirt
under[si] = 3 -- grassland under[si] = 3 -- grassland
elseif n_biome > -0.7 then elseif n_biome > -0.7 then
data[vi] = c_dirt data[vi] = c_wsdirt
under[si] = 2 -- forest under[si] = 2 -- forest
else else
data[vi] = c_dirt data[vi] = c_wsdirt
under[si] = 1 -- taiga under[si] = 1 -- taiga
end end
end end
@ -199,22 +232,25 @@ minetest.register_on_generated(function(minp, maxp, seed)
else -- possible above surface air node else -- possible above surface air node
if y >= YWAT and under[si] ~= 0 then if y >= YWAT and under[si] ~= 0 then
if under[si] == 1 then if under[si] == 1 then
if trees and math.random(PINCHA) == 2 then if math.random(PINCHA) == 2 then
watershed_pinetree(x, y, z, area, data) watershed_pinetree(x, y, z, area, data)
else else
data[viu] = c_dirtsnow data[viu] = c_dirtsnow
data[vi] = c_snowblock data[vi] = c_snowblock
end end
elseif under[si] == 2 then -- surface node turned to grass elseif under[si] == 2 then
if trees and math.random(APTCHA) == 2 then if math.random(APTCHA) == 2 then
watershed_appletree(x, y, z, area, data) watershed_appletree(x, y, z, area, data)
elseif math.random(FLOCHA) == 2 then else
data[viu] = c_wsgrass
if math.random(FLOCHA) == 2 then
data[viu] = c_wsgrass data[viu] = c_wsgrass
watershed_flower(data, vi) watershed_flower(data, vi)
elseif math.random(FOGCHA) == 2 then elseif math.random(FOGCHA) == 2 then
data[viu] = c_wsgrass data[viu] = c_wsgrass
watershed_grass(data, vi) watershed_grass(data, vi)
end end
end
elseif under[si] == 3 then elseif under[si] == 3 then
data[viu] = c_wsgrass data[viu] = c_wsgrass
if math.random(GRACHA) == 2 then if math.random(GRACHA) == 2 then
@ -238,14 +274,14 @@ minetest.register_on_generated(function(minp, maxp, seed)
stable[si] = 0 stable[si] = 0
under[si] = 0 under[si] = 0
end end
nixyz = nixyz + 1 -- increment 3D noise index nixyz = nixyz + 1
nixz = nixz + 1 -- increment 2D noise index nixz = nixz + 1
vi = vi + 1 vi = vi + 1
viu = viu + 1 viu = viu + 1
end end
nixz = nixz - 80 -- rewind 2D noise index by 80 nodes for next x row above nixz = nixz - 80
end end
nixz = nixz + 80 -- fast-forward 2D noise index by 80 nodes for next northward xy plane nixz = nixz + 80
end end
vm:set_data(data) vm:set_data(data)

View File

@ -1,6 +1,6 @@
minetest.register_node("watershed:needles", { minetest.register_node("watershed:needles", {
description = "WS Pine Needles", description = "WS Pine Needles",
tiles = {"paragen_needles.png"}, tiles = {"watershed_needles.png"},
is_ground_content = false, is_ground_content = false,
groups = {snappy=3, leafdecay=3}, groups = {snappy=3, leafdecay=3},
sounds = default.node_sound_leaves_defaults(), sounds = default.node_sound_leaves_defaults(),
@ -17,6 +17,15 @@ minetest.register_node("watershed:jungleleaf", {
sounds = default.node_sound_leaves_defaults(), sounds = default.node_sound_leaves_defaults(),
}) })
minetest.register_node("watershed:dirt", {
description = "WS Dirt",
tiles = {"default_dirt.png"},
is_ground_content = false,
groups = {crumbly=3,soil=1},
drop = "default:dirt",
sounds = default.node_sound_dirt_defaults(),
})
minetest.register_node("watershed:grass", { minetest.register_node("watershed:grass", {
description = "WS Grass", description = "WS Grass",
tiles = {"default_grass.png", "default_dirt.png", "default_grass.png"}, tiles = {"default_grass.png", "default_dirt.png", "default_grass.png"},
@ -63,7 +72,7 @@ minetest.register_node("watershed:water", {
liquid_alternative_source = "watershed:water", liquid_alternative_source = "watershed:water",
liquid_viscosity = WATER_VISC, liquid_viscosity = WATER_VISC,
liquid_renewable = false, liquid_renewable = false,
liquid_range = 3, liquid_range = 4,
post_effect_color = {a=64, r=100, g=100, b=200}, post_effect_color = {a=64, r=100, g=100, b=200},
groups = {water=3, liquid=3, puts_out_fire=1}, groups = {water=3, liquid=3, puts_out_fire=1},
}) })
@ -100,7 +109,7 @@ minetest.register_node("watershed:waterflow", {
liquid_alternative_source = "watershed:water", liquid_alternative_source = "watershed:water",
liquid_viscosity = WATER_VISC, liquid_viscosity = WATER_VISC,
liquid_renewable = false, liquid_renewable = false,
liquid_range = 3, liquid_range = 4,
post_effect_color = {a=64, r=100, g=100, b=200}, post_effect_color = {a=64, r=100, g=100, b=200},
groups = {water=3, liquid=3, puts_out_fire=1, not_in_creative_inventory=1}, groups = {water=3, liquid=3, puts_out_fire=1, not_in_creative_inventory=1},
}) })

Binary file not shown.

After

Width:  |  Height:  |  Size: 860 B