Page 1 of 1

Biome finding?

PostPosted: Tue Mar 12, 2013 10:30
by 0gb.us
Is there a way to tell what biome a node is in from Lua? I don't think there is an official way yet, but I bet there are some math-based shenanigans that can be had. I have no experience with perlin noise though. Does anyone have any advice for me? Thanks!

PostPosted: Tue Mar 12, 2013 14:58
by PilzAdam
There is no Lua function (yet), but maybe you can port this to Lua:
https://github.com/minetest/minetest/blob/master/src/mapgen_v6.cpp#L301

PostPosted: Tue Mar 12, 2013 21:49
by 0gb.us
PilzAdam wrote:There is no Lua function (yet), but maybe you can port this to Lua:
https://github.com/minetest/minetest/blob/master/src/mapgen_v6.cpp#L301


That looks like exactly what I need, but will take time to translate, seeing as I don't know C++.

Thanks!

PostPosted: Wed Mar 13, 2013 00:38
by prestidigitator
I was already working on the noise generation (noise.cpp) as it turns out. Ported to Lua but not yet tested.

PostPosted: Wed Mar 13, 2013 15:39
by PilzAdam
prestidigitator wrote:I was already working on the noise generation (noise.cpp) as it turns out. Ported to Lua but not yet tested.

You know that there are functions in the Lua API for that?

PostPosted: Wed Mar 13, 2013 16:56
by prestidigitator
PilzAdam wrote:
prestidigitator wrote:I was already working on the noise generation (noise.cpp) as it turns out. Ported to Lua but not yet tested.

You know that there are functions in the Lua API for that?

I understand that some noise APIs are exposed, but it is not obvious whether these are exactly the same noise functions that will duplicate the calculations of mapgen. The translation to pure Lua wasn't that bad really. There are just a few gotchas such as Lua not having bit-wise operators, so I had to implement an xor() function using modulo and powers of two. I don't expect it to be particularly fast, of course.

PostPosted: Wed Mar 13, 2013 17:19
by PilzAdam
prestidigitator wrote:
PilzAdam wrote:
prestidigitator wrote:I was already working on the noise generation (noise.cpp) as it turns out. Ported to Lua but not yet tested.

You know that there are functions in the Lua API for that?

I understand that some noise APIs are exposed, but it is not obvious whether these are exactly the same noise functions that will duplicate the calculations of mapgen. The translation to pure Lua wasn't that bad really. There are just a few gotchas such as Lua not having bit-wise operators, so I had to implement an xor() function using modulo and powers of two. I don't expect it to be particularly fast, of course.

The Lua API is just a wrapper to core functions, so the noise is definetly the same.
And speed is a very important point when it comes to mapgen, so you should optimise the slow noise functions.

PostPosted: Wed Mar 13, 2013 17:24
by prestidigitator
PilzAdam wrote:The Lua API is just a wrapper to core functions, so the noise is definetly the same.
And speed is a very important point when it comes to mapgen, so you should optimise the slow noise functions.

Which C functions? There are a number of different entry points, and mapgen itself is a little confused about which it wants to use. This creates a bit of a mess, so I just wanted to make sure I had exactly the same calculations. But the good part is that the Lua port doesn't necessarily have to be fast. I don't expect it to do full map generation, but to fill in a bit of functionality where mods may need to calculate a couple of values in the same way that mapgen does. The original question about biomes here is a good example. You don't need to calculate the types of thousands of blocks to figure out whether or not you are in a desert biome.

PostPosted: Wed Mar 13, 2013 17:29
by prestidigitator
Interestingly, the noise implemented in Minetest is not Perlin Noise. It uses coordinate values to calculate pseudo-random values, but does not apply those values as gradients (even though there are functions with "gradient" in their names). So it's really more like interpolated value-based noise rather than Perlin (gradient) noise.

That's okay, of course. Obviously it works. But it would be interesting to switch to full Perlin Noise, or even its successor Simplex Noise (smoother noise and faster interpolation), and see how much that influences the behavior of the map generation.

PostPosted: Fri Mar 15, 2013 10:49
by prestidigitator
I got a little distracted by the noise. Heh. See here: http://forum.minetest.net/viewtopic.php?pid=75927#p75927

PostPosted: Sat Mar 16, 2013 03:20
by paramat
Tested in 0.4.4 this defines desert biomes ...
Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
Code: Select all
local perlin = minetest.env:get_perlin(9130,3,0.5,250)
local noise = perlin:get2d({x=x+150,y=z+50})

With noise > 0.4 for deserts, smooth transition from 0.35 to 0.45.

Not sure if 0.4.5 changes this though, the transition may be from 0.3 to 0.4 now.