Fix cloud texture and post effect colours. Enlarge space. Add more planet data

This commit is contained in:
paramat 2016-07-03 14:52:23 +01:00
parent 4a6c284e8f
commit 8b898bf1b4
4 changed files with 56 additions and 35 deletions

View File

@ -1,4 +1,4 @@
planets 0.1.4 by paramat
planets 0.1.5 by paramat
For Minetest 0.4.13 and later
Depends default
Licenses: Code LGPL 2.1. Media CC BY-SA 3.0

View File

@ -1,7 +1,7 @@
-- Parameters
local pnum = 64 -- number of planets desired
local maxatt = 4096 -- maximum number of attempts to add a planet
local maxatt = 8192 -- maximum number of attempts to add a planet
local np_terrain = {
offset = 0,
@ -35,13 +35,13 @@ minetest.set_mapgen_params({mgname = "singlenode",
-- Create planetary system
-- space is 64 ^ 3 chunks, centred on world centre
-- space is 128 ^ 3 chunks, centred on world centre
-- space table is flat array of planet ids or nil (vacuum chunk)
local space = {}
-- planet definition table indexed by planet id
local def = {}
local spzstr = 64 * 64 -- space array z stride
local spystr = 64 -- space array y stride
local spzstr = 128 * 128 -- space array z stride
local spystr = 128 -- space array y stride
local plid = 0 -- planet id of last planet added, 0 = none
local addatt = 0 -- number of attempts to add a planet
math.randomseed(42) -- set pseudorandom seed
@ -49,19 +49,17 @@ math.randomseed(42) -- set pseudorandom seed
while plid < pnum and addatt <= maxatt do -- avoid infinite attempts
-- create initial planet data to check for obstruction
-- cenx/y/z is planet centre
-- radter = terrain radius / beach top / water level + 4
-- radmax = atmosphere radius or max mountain radius
local cenx = math.random(-2000, 2000)
local ceny = math.random(-2000, 2000)
local cenz = math.random(-2000, 2000)
local radter = 256 -- TODO randomise these
local cenx = math.random(-4000, 4000)
local ceny = math.random(-4000, 4000)
local cenz = math.random(-4000, 4000)
local radmax = 384
-- chunk co-ords of chunk containing planet centre
-- measured from space origin (-32, -32, -32 chunks)
local cenxcc = math.floor((cenx + 32) / 80) + 32
local cenycc = math.floor((ceny + 32) / 80) + 32
local cenzcc = math.floor((cenz + 32) / 80) + 32
-- measured from space origin (-64, -64, -64 chunks)
local cenxcc = math.floor((cenx + 32) / 80) + 64
local cenycc = math.floor((ceny + 32) / 80) + 64
local cenzcc = math.floor((cenz + 32) / 80) + 64
local radmaxc = math.ceil(radmax / 80) -- planet radius in chunks
-- check space is clear for planet
@ -87,11 +85,31 @@ while plid < pnum and addatt <= maxatt do -- avoid infinite attempts
end
end
if clear then -- add planet
-- TODO generate extra planet data here
if clear then -- generate more data and add planet
local tersca = 64 -- terrain scale / cloud height
local radter = 256 -- average terrain level / density gradient zero
local radlav = 128 -- lava core radius
local ocean = true -- liquid ocean
local radwat = 252 -- water level / 4 nodes below terrain squash
-- if oceans set to radter - 4
local atmos = true -- gaseous atmosphere to radmax
local clot = 0.5 -- cloud noise threshold
plid = #def + 1 -- planet id
-- add planet data to def table
def[plid] = {i = cenx, j = ceny, k = cenz, t = radter, m = radmax}
def[plid] = {
x = cenx,
y = ceny,
z = cenz,
m = radmax,
s = tersca,
t = radter,
l = radlav,
o = ocean,
w = radwat,
a = atmos,
c = clot,
}
print ("[planets] Adding planet " .. plid)
for cz = cenzcc - radmaxc, cenzcc + radmaxc do
@ -112,7 +130,7 @@ end
-- Spawn above planet 1
local pdef = def[1]
local spawn_pos = {x = pdef.i, y = pdef.j + pdef.m, z = pdef.k}
local spawn_pos = {x = pdef.x, y = pdef.y + pdef.m, z = pdef.z}
minetest.register_on_newplayer(function(player)
player:setpos(spawn_pos)
@ -180,10 +198,10 @@ minetest.register_on_generated(function(minp, maxp, seed)
local z1 = maxp.z
-- chunk co-ords of chunk
-- measured from space origin (-32, -32, -32 chunks)
local cx0 = math.floor((x0 + 32) / 80) + 32
local cy0 = math.floor((y0 + 32) / 80) + 32
local cz0 = math.floor((z0 + 32) / 80) + 32
-- measured from space origin (-64, -64, -64 chunks)
local cx0 = math.floor((x0 + 32) / 80) + 64
local cy0 = math.floor((y0 + 32) / 80) + 64
local cz0 = math.floor((z0 + 32) / 80) + 64
-- space table index
local spi = cz0 * spzstr + cy0 * spystr + cx0 + 1
-- planet def table index
@ -217,44 +235,47 @@ minetest.register_on_generated(function(minp, maxp, seed)
local nvals_terrain = nobj_terrain:get3dMap_flat(pmapminp, nbuf_terrain)
local nvals_cloud = nobj_cloud:get3dMap_flat(pmapminpclo, nbuf_cloud)
local tersca = (pdef.m - pdef.t) / 2 -- terrain scale
local stot = 3 / tersca -- stone noise threshold
-- auto set stone noise threshold for 3 nodes of fine material
local stot = 3 / pdef.s
local ni = 1 -- noise index
for z = z0, z1 do
for y = y0, y1 do
local vi = area:index(x0, y, z) -- luavoxelmanip index
for x = x0, x1 do
local nodrad = math.sqrt((x - pdef.i) ^ 2 + -- node radius
(y - pdef.j) ^ 2 + (z - pdef.k) ^ 2)
local dengrad = (pdef.t - nodrad) / tersca -- density gradient
local xcr = x - pdef.x -- x centre-relative
local ycr = y - pdef.y
local zcr = z - pdef.z
local nodrad = math.sqrt(xcr ^ 2 + ycr ^ 2 + zcr ^ 2) -- node radius
local dengrad = (pdef.t - nodrad) / pdef.s -- density gradient
local dennoise = nvals_terrain[ni] -- density noise
if nodrad <= pdef.t then -- make oceans shallower
if pdef.o and nodrad <= pdef.w + 4 then -- if ocean squash terrain
dennoise = dennoise / 2
end
local density = dennoise + dengrad -- density
if nodrad <= pdef.t / 2 then -- lava
if nodrad <= pdef.l then -- magma
data[vi] = c_lava
elseif density >= stot then -- stone
data[vi] = c_stone
elseif density >= 0 then -- fine materials
if nodrad <= pdef.t then
if nodrad <= pdef.w + 4 then
data[vi] = c_sand
else
data[vi] = c_grass
end
elseif nodrad <= pdef.t - 4 then -- water
elseif pdef.o and nodrad <= pdef.w then -- ocean
data[vi] = c_water
elseif dengrad >= -1.0 and dengrad <= -0.95 then -- clouds
elseif pdef.a and pdef.c < 2 and
dengrad >= -1.0 and dengrad <= -0.95 then -- clouds
local xq = math.floor((x - x0) / 16) -- quantise position
local yq = math.floor((y - y0) / 16)
local zq = math.floor((z - z0) / 16)
local niq = zq * 25 + yq * 5 + xq + 1
if nvals_cloud[niq] > 0.5 then
if nvals_cloud[niq] > pdef.c then
data[vi] = c_cloud
end
elseif nodrad <= pdef.m then -- air
elseif pdef.a and nodrad <= pdef.m then -- air
data[vi] = c_air
else -- vacuum
data[vi] = c_vacuum

View File

@ -32,7 +32,7 @@ minetest.register_node("planets:cloud", {
diggable = false,
buildable_to = true,
floodable = true,
post_effect_color = {a = 31, r = 241, g = 248, b = 255},
post_effect_color = {a = 47, r = 230, g = 235, b = 254},
groups = {not_in_creative_inventory = 1},
})

Binary file not shown.

Before

Width:  |  Height:  |  Size: 136 B

After

Width:  |  Height:  |  Size: 123 B