Hello Everyone!
I have become a bit fascinated with procedural generation lately and decided to try my hand at some terrain generation. After doing some googling (google knows everything you know... ) I decided I'd start with using a simplex noise filter. Luckily someone had already translate the original example written by Ken Perlin in Java to Lua. It was in the form of a module however. Also they where including the LuaBit functions for their bitwise operations.
In any case LevyBreak posted his original translation here: http://www.facepunch.com/threads/834088
I took this, stripped out the 3D and 4D operations and converted it so that it built a table and returned it. It made it easier to use in LOVE, as I think loading the module was causing some goofiness in the loader.
MapGen I based on another Java script which was written by Wade Kallhoff http://mavdisk.mnsu.edu/kallhw/
The original source can be found here: http://mavdisk.mnsu.edu/kallhw/world/world.txt
I also modified LuaBit (because the way it was built using do <stuff> end) was causing issues with it working in LOVE as well: Attempt to index global "bit" a nil value... wat?! ) and included that so that we didn't need to get messy with the functions in the Simplex Noise library.
In any case, I was originally disappointed with the results, mainly because I had never knowingly seen the results of perlin/simplex noise filters before. After doing some googling trying to figure out what I could have possibly done wrong, I discovered that this is the way the filter actually turns out. Silly me.
So I was happy again.
Just a pre-warning however, this is still extremely simple. I just wanted to share what I had so far.
The only variables you can actually modify, currently, is the noiseScale and tileScale. By default the tileScale is set to 10x10 pixels. The noiseScale is set to 0.1 by default, I currently have it being set in the function call to 0.05.
In any case, I hope to make this more useful as I work on it, and eventually turn it into a full blown library for LOVE. So if anyone has any suggestions, critiques, comments or contributions feel free to share!
Some future features I already have in mind:
- Ability to fine tune noise detail and add random seed capability
- Add the ability to pre-gen a map using noise and apply other filters on top of it. For instance, pre-gen using diamond-square fractal noise and modify it by simplex (which would probably turn out much better looking maps) and allow you to fine tune how the filter is applied.
- Add the ability to generate a Lua table in a format which can be used by Advanced Tiled Loader http://love2d.org/wiki/Advanced_Tiled_Loader (because I like it)
In any case, I found this to be a very interesting learning experience so far, and easier than I had originally anticipated it to be. I hope this helps someone else out as well.
*Edit: Durr... helps if I upload the file. lol
Making some noise! (Simplex style)
Making some noise! (Simplex style)
Last edited by Nergal on Fri Oct 28, 2011 3:42 am, edited 1 time in total.
"There would come a time I'd wake at night, and the possibilities before me were like so many dark doors..."
- josefnpat
- Inner party member
- Posts: 955
- Joined: Wed Oct 05, 2011 1:36 am
- Location: your basement
- Contact:
Re: Making some noise! (Simplex style)
This is some nice code to get ported over to lua. I bet there's lots of lovers that wouldn't mind being able to use this and fine tune it to use in their own applications.
Missing Sentinel Software | Twitter
FORCIBLY IGNORED.
<leafo> when in doubt delete all of your code
<bartbes> git rm -r *
<bartbes> git commit -m "Fixed all bugs"
<bartbes> git push
FORCIBLY IGNORED.
<leafo> when in doubt delete all of your code
<bartbes> git rm -r *
<bartbes> git commit -m "Fixed all bugs"
<bartbes> git push
- slime
- Solid Snayke
- Posts: 3166
- Joined: Mon Aug 23, 2010 6:45 am
- Location: Nova Scotia, Canada
- Contact:
Re: Making some noise! (Simplex style)
Sweet! There's also a nice LuaJIT implementation of simplex noise for those who use LuaJIT with love (although luajit breaks slightly with the upcoming version of love...), it's many times faster than a pure Lua implementation could ever be.
http://staffwww.itn.liu.se/~stegu/simpl ... /Noise.lua
http://staffwww.itn.liu.se/~stegu/simpl ... /Noise.lua
Re: Making some noise! (Simplex style)
Hey, that looks pretty good slime.
It actually looks like it would run in straight Lua as well however... unless I'm mistaken. Going over it, it actually looks quite a bit better than the implementation I'm using. I'm going to test it out and see.
I agree LuaJIT is definitely a better approach for speed. Try generating a 500x500 tile map with my example for instance, and you'll see there is a significant speed hit. Of course rendering 5000 rectangles is also a hit in and of itself. I'll probably include the ability to simply render the entire thing as an image at some point.
It actually looks like it would run in straight Lua as well however... unless I'm mistaken. Going over it, it actually looks quite a bit better than the implementation I'm using. I'm going to test it out and see.
I agree LuaJIT is definitely a better approach for speed. Try generating a 500x500 tile map with my example for instance, and you'll see there is a significant speed hit. Of course rendering 5000 rectangles is also a hit in and of itself. I'll probably include the ability to simply render the entire thing as an image at some point.
"There would come a time I'd wake at night, and the possibilities before me were like so many dark doors..."
- slime
- Solid Snayke
- Posts: 3166
- Joined: Mon Aug 23, 2010 6:45 am
- Location: Nova Scotia, Canada
- Contact:
Re: Making some noise! (Simplex style)
A huge portion of the speed increase from it is because it uses LuaJIT's FFI to use C datatypes, so it can't be ported straight to pure Lua.
Re: Making some noise! (Simplex style)
I completely missed that. Thanks for pointing that out so I didn't waist a bunch of time trying to get it to work.slime wrote:A huge portion of the speed increase from it is because it uses LuaJIT's FFI to use C datatypes, so it can't be ported straight to pure Lua.
"There would come a time I'd wake at night, and the possibilities before me were like so many dark doors..."
Who is online
Users browsing this forum: Bing [Bot] and 5 guests