Perlin Noise & Terrain Generation

in #programming6 years ago (edited)

raw2d.png

Perlin Noise is an algorithm that is used often to generate things procedurally, often terrain. If you've ever seen Minecraft then you've probably seen terrain generation using Perlin Noise.

So then, how does this work? Perlin Noise is a type of Gradient Noise which was developed by Ken Perlin. To be completely honest, I am not even close to able to describe how these things work in detail, so I would highly recommend you read the wikipedia articles I linked above to understand everything better.

From here, I'll show some examples and a slight bit of code for how this all works. I'll be coding in Roblox, but frankly you can use basically any engine you'd like and as long as you're able to write it this would be able to work nearly the same, I'm just most comfortable with this.

To start, we'd create a grid (we obviously don't have to create the grid separately, but it's easiest to show off). I've colored the grid red & black so you can see that it is a grid.

2018-01-15_06-32-44.gif

This is where Noise comes in. The first option that came to my mind when researching this, was to position the parts randomly based on a few different factors. That's a lot of math I don't want to do, and it would also look pretty ugly.

To my knowledge, most coding languages have a noise function in them. I'm coding in Lua, so I know mine does. Noise will take this grid and based on a few arguments we give send us back a value between -1 and 1 that we will be using as our Y value (height).

2018-01-15_06-36-56.gif

Woah. That went pretty fast. You can see now our checkerboard has some height to it! It raises in some areas, dips in others. Now we have terrain! Generally you're able to color it with Height Mapping, basing the color off of its height for an image like this.

RobloxStudioBeta_2018-01-15_06-40-19.png

I also added a sea level here, as I prefer the look with that. Now we have snowy mountains, some grassy areas, lakes, rivers, etc. With a bigger map, this would look very repetitive and boring. How do we avoid that? Most games that I can think of will generate each different biome using different arguments for Perlin Noise and then randomize what one they generate. This works for the most part, but it winds up with some wonky math. I do not have any reference that I have made for this, but here's someone coding Minecraft in one week instead. It was really neat to watch, and I'd highly recommend it. Source code is also there!

To end this off, Algorithms of all kinds are really cool. Perlin Noise especially is, and we see it in a lot of areas.

Sort:  

Add the tag gamedev :)

Just did! Thanks, didn't know that was a tag ^^

Hola @birdd, upv0t3
Este es un servicio gratuito para nuevos usuarios de steemit, para apoyarlos y motivarlos a seguir generando contenido de valor para la comunidad.
<3 Este es un corazón, o un helado, tu eliges .

: )


N0. R4ND0M:
6001 7109 4888 8774
9048 6816 1301 1088
9680 3697 3100 6149
5832 2592 2025 1436

Congratulations @birdd! You received a personal award!

1 Year on Steemit

Click here to view your Board of Honor

Support SteemitBoard's project! Vote for its witness and get one more award!

Congratulations @birdd! You received a personal award!

Happy Birthday! - You are on the Steem blockchain for 2 years!

You can view your badges on your Steem Board and compare to others on the Steem Ranking

Vote for @Steemitboard as a witness to get one more award and increased upvotes!