Biome finding?

User avatar
0gb.us
Member
 
Posts: 841
Joined: Sun Sep 16, 2012 01:55

Biome finding?

by 0gb.us » Tue Mar 12, 2013 10:30

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!
 

User avatar
PilzAdam
Member
 
Posts: 4026
Joined: Fri Jul 20, 2012 16:19
GitHub: PilzAdam
IRC: PilzAdam

by PilzAdam » Tue Mar 12, 2013 14:58

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
Last edited by PilzAdam on Tue Mar 12, 2013 14:59, edited 1 time in total.
 

User avatar
0gb.us
Member
 
Posts: 841
Joined: Sun Sep 16, 2012 01:55

by 0gb.us » Tue Mar 12, 2013 21:49

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!
 

prestidigitator
Member
 
Posts: 632
Joined: Thu Feb 21, 2013 23:54

by prestidigitator » Wed Mar 13, 2013 00:38

I was already working on the noise generation (noise.cpp) as it turns out. Ported to Lua but not yet tested.
 

User avatar
PilzAdam
Member
 
Posts: 4026
Joined: Fri Jul 20, 2012 16:19
GitHub: PilzAdam
IRC: PilzAdam

by PilzAdam » Wed Mar 13, 2013 15:39

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?
 

prestidigitator
Member
 
Posts: 632
Joined: Thu Feb 21, 2013 23:54

by prestidigitator » Wed Mar 13, 2013 16:56

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.
 

User avatar
PilzAdam
Member
 
Posts: 4026
Joined: Fri Jul 20, 2012 16:19
GitHub: PilzAdam
IRC: PilzAdam

by PilzAdam » Wed Mar 13, 2013 17:19

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.
 

prestidigitator
Member
 
Posts: 632
Joined: Thu Feb 21, 2013 23:54

by prestidigitator » Wed Mar 13, 2013 17:24

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.
 

prestidigitator
Member
 
Posts: 632
Joined: Thu Feb 21, 2013 23:54

by prestidigitator » Wed Mar 13, 2013 17:29

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.
Last edited by prestidigitator on Wed Mar 13, 2013 17:29, edited 1 time in total.
 

prestidigitator
Member
 
Posts: 632
Joined: Thu Feb 21, 2013 23:54

by prestidigitator » Fri Mar 15, 2013 10:49

I got a little distracted by the noise. Heh. See here: http://forum.minetest.net/viewtopic.php?pid=75927#p75927
 

paramat
Member
 
Posts: 2662
Joined: Sun Oct 28, 2012 00:05
GitHub: paramat

by paramat » Sat Mar 16, 2013 03:20

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.
Last edited by paramat on Sun Mar 17, 2013 19:39, edited 1 time in total.
I rely on donations to help provide an income https://forum.minetest.net/viewtopic.php?f=3&t=14935
 


Return to WIP Mods

Who is online

Users browsing this forum: No registered users and 5 guests

cron