Intro to Procedural Levels in Godot 3.1: Perlin Noise Tutorial

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hey it's clear me and in this video we're going to explore the new open simplex noise class from the 3.1 so if you want to run this demo or you'd like to follow along you are going to need an alpha version of Godot because this class is not available on version 3.0 and in the end we are also going to look at a map that's being procedurally generated using this class before understanding what is the open stream flex noise class we have to first know what noise is by looking at this picture you can see what noise is the values that you see don't have any relevance to the others around them so they are just randomly generated and that's mainly what you get when you use something like rent range in the dough the valleys don't take into consideration their neighbors when being generated they're just random and when you put an in an image that's pretty much what you're going to see something that resembles the OTV is when we were out of signal but when we are talking about open simplex noise the values that are being generated take into consideration the values that are around them this gives us something like this just by looking at this picture you can already see that the values you have something in common to the ones that are around them we don't have any abrupt change colors so we don't have anything that is black right besides something that is white you get this nice fade or this gradient when moving from color to color and by using this we are dealing with values that are not completely random they can be called pasado random values and this because of the way that they are being generated there are results that we get are way more natural another thing to keep in mind is if you start to research about it you're probably going to hear a lot of pearly noise and pearly noise is just the father of simplex noise simplex noise was created in 2001 and it is a revision of the purling noise which gives us more performance now pearly noise our simplex noise wherever you want to call it can be used to create an array of things not only maps as we are going to see here but they can also be used to create textures here we can see an example of a texture for a cloud but you can use it to generate textures for anything that you want shaders and of course map generation for games probably one of the most known games that most likely uses Perlin noise is minecraft although I'm pretty sure that for the caves they use something called purling worms terraria is another great example that probably uses purling noise to generate its Maps and the list goes on and on keep in mind that even though these games probably use Perlin noise that might not be the only algorithm that they are using to generate air maps they might be using something else on top of purling noise or simplex noise to create these beautiful worlds now without further ado let's jump into Godot and cities in action we are going to create a new 2d scene and the layout is a little bit different because again I'm using the Alpha and this is the new default layout so let's create a 2d scene I'm going to rename the node demo and we're going to add a new sprite as a child of is no Judy with the sprite selected we are going to go to the inspector and create a new noise texture to it you can already see that we have this black rectangle and now if we click in this section we are able to edit it I'm going to set the width to 1280 by 720 and you can see that we have this property called noise and here we need to create a new open simplex noise we're going to create it now you can already see something that we saw in the examples before and I'm going to zoom out and Center the sprite using the grid and is nap in this scene we're gonna be able to visualize how we can change the configuration of our open simplex noise you generate different kinds of textures with it which is also going to help us when we start to create our map and to edit these configurations we have to click on the noise here in the inspector and it's going to open its configurations the open simplex class abstracts to us the generation of the numbers and exposes some control variables that we can use to again play around and determine how we want our noise to be generated early noise can be used to generate noise in several dimensions ranging from one two and dimensions so I mean as many as you want the implementation that we have in Godot goes from one to four dimensions but here we're only going to take a look at 2d noise the seed as you may already have guessed is the number that is going to be used as a seed to the generation of the other numbers so by changing this we get a different result with the same configuration games also tend to use this value to let players share cool worlds that they found with their friends now the octaves you can think of them as a layer each new octave adds as a new layer of perla noise or simplex noise on top of the layer that's under it so if we change the octaves to 1 you can see that we get this really blurry and kind of boring noise because we only have one layer of Perlin noise and the numbers just go from pure black to pure white and again and again and again and by increasing the number of octaves we are adding more detail to our image an analogy that can be used to better understand what is octaves and what they are used for is think that we are generating a map here and the first octave is giving us the shape of the mountings the second octave gives us the borders that are on our mountains and the third octaves is giving us our pebbles and so on and so forth the period can again just like the octaves be better understand it by using an analogy and you can think of it as how zoomed in we are on our noise by increasing the value we are zooming in into our image and by decreasing this value we are zooming out the persistence defines how much each octave will influence in the overall noise generated and the lower this value less influence will get from the layers of octaves that we are having in our noise you can see the result of changing this by decreasing the value and increasing it if we set our persistence to something like zero you see that we have the same thing that we had before when we only had one octave and that is because that now they don't have any influence on the noise that's being generated so I'm going to change this back to 0.5 and the octaves to 3 and now we are back to the same result that we had before finally the lock narrative defines how quickly the frequency of each consecutive octave will increase but you can abstract it and just think as it has something to do with the frequency on the values of our octaves and I know that this might be a lot to remember at first but with time and while playing with these values you are going to better understand what they are used for and in sum each octave is going to change values with more frequency and this is controlled by our like narrative and they can influence more or less on the final noise which is then controlled by our upper systems and finally we have the period which allows us to zoom in and out from the noise I strongly suggest that you play around with these values and see how they affect the noise that's being generated so you can better understand for yourself what they are used for is the best way to understand but hopefully this explanation gave you a solid base that you can grow from now we're going to look at our game scene where we are procedurally generating a map using the open simplex noise class the scene has a tile map that has three outer tiles one for the grass one for the rocks and lastly one for the scent each one of these tiles has an index that's going to be used in our script to place these tiles based on the noise that we are getting from our open simplex noise now we also have a player that is used to just walk around our map so we can see the results I'll open the game script at first we just define how big we want our map to be by using the width and a height we then have a dictionary that we use to know what are the indexes of our titles and lastly we have a variable that is going to store a reference to our open simplex noise on the ready function we start by calling randomized because we are going to use random numbers here so we do have to call randomized we then create a new instance of the open simplex noise by calling new on the class and we pass to it a seed by using a random integer we then configure our open simplex noise the same way that we were doing before but this time using code so we define the number of octaves the period like narrowly and also the persistence we then call the you generate world function that is going to generate our world the regenerate world function uses two Force one for the width and another one for the height and each time we iterate on the values we're going to set a cell on a given position in our map and when the find in this position with the Chris have to wait from the X and have the height from the Y this way our player is going to appear right in the middle of the generated map and when a calling set Selvi we also need to pass to it an index which is going to represent what tile we are going to set in that given cell and to do that we call a function called get site index that's going to return to us the index of a tile based on the sample that we get from our open simplex noise and to get this noise sample we're calling get noise to D in our open simplex noise instance and passing through two values which is the x and y the values expected in this function are floats so that's why we are converting them from integers to floats the noise generated in the get noise 2d ranges from minus 1 to 1 based on these values we can determine which type of tile we are going to place in that given position and after generating the map we update our bit mask region is way our Auto tile gets updated and our map is going to look fine just as we expected in the get site index we receive our sample if it is lesser than minus 0.1 we're going to return a cent but if it's greater than minus 0.1 but lesser than 0.4 we're going to return a rock and if it all fail we're going to return aggress if I run this game you notice that it takes a while for it to boot up and that is because it's generating the map and when it's done we are now able to move around of our web using our player and you can see that the map that we get is completely procedurally generated you can see some artifacts for instance here we only have this rock we could also have different passes of our map generating algorithm to clean this up but as this is just an example we won't have to worry about them and we can also close the game and run it again to see a different result and there we go a completely different map his approach is not limited to top-down maps you can use it to create platformers or even 3d maps it's only up to your imagination to figure out how you can use them to create all kinds of different maps for your games and you could also add more details by checking different ranges let's pretend that we had different types of sand tiles that had details on them for instance some rocks or some types of artifacts then we could check here okay so if we are in a value that is lesser than minus 0.1 we're going to check if it is lesser than for instance minus 0.2 and we are going to add this type of sand tile but if it's greater than something we're going to add different type of sand and this can also be done for the rock and the grass you can add of course more types of tiles for your game at enemies dungeons and so on and so forth if you want to play around with this demo as always the link for the github repository is in the description thank you so much for watching and I'll see you in the next one
Info
Channel: GDQuest
Views: 34,680
Rating: 4.9712524 out of 5
Keywords: godot noise tutorial, godot opensimplex, godot noise, godot procedural generation, opensimplex noise, open noise, godot tilemap tutorial, godot level generation, procedural level design, game creation tutorial, gdscript, godot 3.1, godot engine procedural generation, godot perlin noise, godot 3.1 alpha 2, godot 3 tutorial
Id: m6mu4uPGrMk
Channel Id: undefined
Length: 12min 18sec (738 seconds)
Published: Thu Nov 15 2018
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.