Hello and welcome back to code place so continuing on with the series creating voxel chunks in Unreal Engine using blueprints in the last episode we implemented the create face and the get face vertices function so by the end of it we were able to create cubes anywhere In the world we want or you can create faces also so in this episode we’ll be going over like creating the noise map since we don’t want cubes Ivonne profit some generation so we’ll be generating noise maps using the fast nice plugin so again if you don’t have the fast noise Plug-in installed just search in the marketplace for FNG or the fast noise generator it’s free you can add it so we’ll go over that but and we’ll be doing most of like the whole of the noise generation thing in the construction script so I will basically Break this pin here and I will do a sequence node ok and we will basically need three things so the first pin will go to a noise generation the second one will be going to our mesh building and the third one will be going to add anything but you Can remove this third one and use this computed but we will be changing our mesh building logic in the next episodes so that we will be able to create proper voxel meshes rather than just cubes but for now we will be just focusing over the first sequence that would be Generating not basically filling our chunk block data with the noise light manthis generated so the first thing we will do is get a blocks data okay and we’ll resize it and we’ll resize it to three times the size of a chunk so we will get our size we’ll multiply this by An integer and he says this to this value so currently I have my size set to 16 so the resize value would be 4 0 9 6 and that’s what our array will be resized to and it’s a good practice to do the resize if you know the length of the At compile-time only that way Unreal Engine won’t have to increase or allocate more memory to area at random so it gives a slight performance boost so once we have done the resize we will be constructing the fasteners wrapper so construct the search for us can we construct object from class and We select the class fast no its wrapper and outer thing can be self okay so this will basically add the first noise wrapper to the current blueprint object and once we have that this we can set it up you can call set up noise second fast Noise okay so the set up phase noise takes in quite a lot of values but you don’t need to change anything like the defaults of good enough but these basically affect how the height map is generated so you can play around with these and you’ll get different results You can join the noise type so I like to go with the Perlin noise the seed you can change frequency will change how rocky or smooth the terrain is and other things also you can change like we can have quintic interpolation or linear anything you want so you can have these Values exposed as variables or you can just leave them as default and I’ll leave it at that so next what we need to do is to for loops that would be our x and y for loop for each loop we’ll duplicate this and the last index Would be one minus the size so we’ll take a size and subtract one out of it and this would be last index since the Unreal Engine 4 loops run inclusive of the last index by subtracting this to be 1 the last index would be 15 and the Loop will run from 0 to 15 so that would be 16 iterations so we will complete this connect this execution pincer so we have two nested for-loops here and what we are going to do is take their index and multiply that by 100 we multiplied by an integer and that would be hundred Okay the unreal in unreal works in centimeters so I want my blocks to be one meter by one meter so the difference in their positions would be by 100 so that’s why I’m multiplying both x and y by hundred so again I’ll multiply this I just copied this node yep and with this I multiplied this by both next we get the actor location since we want our chunk height map to be affected by this world position we will get afterthe location okay and we will split this structure and what we will do is add these values to these integers will you See we do an integer addition and add X so rather than doing this as truncation will convert the integers to float because we will be multiplying by scale for proper noise so we will do an ADD we’ll be adding the to the Y value also Z value is something that we won’t be Messing around with since we will be generating the Z value on our own and this will convert these two floats the reason I want x and y to be float is now we will be multiplying them by a scale value so this scale won’t be the chunk scale but This would be the my scale if you pass in integral values to the noise input it behaves weirdly so it’s better you multiply this by some small number 0.15 works pretty nice now you can even have this number as variable on this and you can customize this so this basically changes The scale like if you consider the noise has a 2d image so house ohm then it would be will depend on the scale okay with this out of the way will again take the return value of the wrapper yeah and we’ll call get noise 2d you can even do 3d noise So that’s bit advanced but we’ll be using 2d noise here and this would be exhibited in the loop body of an inner for loop for loop macros and will pass in the x and y values okay so with this we’ll get a return value which will be a Z value and this value will be between minus 1 and 1 but we want this to be a positive value only and that to till 16 so we’ll be doing some conversion so we’ll add 1 to it so now the value is between 0 to 2 since this it has been Shifted next we will divide this by 2 and we’ll be dividing this by 2 now the value would be between 0 & 1 and finally we’ll multiply this by our size so we do an integer to float multiplication and we’ll be get we get our sides again here ok so now the value Will be between 0 and 16 so I’ll just go over it we get a value between minus 1 and 1 from get nice 2d then we shifted the value is between zero and two by adding 1 to it then we divided by two so the values between 0 & 1 and finally we Multiplied by size so the final value would be between 0 and 16 so it would be a float value what we’ll do is Frank ate it so now it will be an integral value between 0 and 16 you can even see what it does okay so finally with this out of The way what we’ll do is we’ll run another for loop so you get this out here and we’ll copy this for loop actually and the second for loop will run on the completion of the first one and the first for loops first index would be 0 and the last index with the Z Value that we generated and second-world for loops first value would be the Z value and the last index would be our size minus 1 so we have that we’ll just get this here again and yeah so this for loop will fill the blocks array with stone blocks that add a big blocks and This for loop will fill the remaining in the rest of the chunk with air blocks so that we get our transparent blocks also so next thing we need to do is filling up blocks again we have the x y&z values for our blocks but what we need is the Block index since our blocks there is a 1 dimensional array now we will be implementing this get block index function so this will again be a pure function sense and wouldn’t be modifying anything on the member variables so first thing we’ll have as position and this can be an incorrect And what it will output be an index and this would be an integer so I will just split this structure in here and we will get our size also so we will be inputting 3x we’ll be inputting 3 XY and z values and finally we will be getting The index between 0 & 4 0 9 6 and to do that what we will do is multiply by X by my size I will multiply my Z also by to size 2 times so I’ll add another pin and connect size to both finally I will do An addition mode and this will add my x y&z values so this is again basically saying that this but I first move along the y axis then along the x axis and then along the z axis so this way these three positions correspond to a 1 dimensional array and I basically return This with this I can enter X Y Z values and then can get the block index so getting back in the construction script in the loop body will be calling that block index let’s split this pin here also copy paste it since both of the Loop bodies will need it and my Z value is from here only now actually the Z value is the index of this loop just connect these back ok and my x and y values are the index when these loops that’s the X that’s the Y the end And this is the wine with this out of the way we will get the blocks array again and we’ll call set array element then we will call to pick at this node also this as the target array and the loop body of each of these will be Setting this in the index will be the corresponding that block index and the first loop will set them as the stone blocks and the second loop will set them as a blocks yeah and with that we have basically finished our noise map generation so there isn’t anything that I’ll be able to show you visually like showing whether this works or not in the next episode we’ll be going over mesh building and after that you will be able to see the noise map generation is working so just go over it one since it’s a bit complicated so the first Thing we do is resize our blocks array to three times the size like size size cube basically then we construct our first noise wrapper and we call the set of fasteners where we get the noise then we give the noise properties then we have two for loops which run from zero To size minus 1 again then your loop is inclusive of the last index so these both will run 16 times we take the index multiply it by 100 and convert them to floats and also add the actors location then we multiply the final value by the scale value which is 0.15 again this Could be a variable on the blueprint and then we pass these to get noise to D this will return a value between minus 1 and 1 so we basically shifted to 0 to 2 divided by 2 so the value is between 0 and 1 and you multiply it by our sides So the values between 0 and 16 and we truncate the float value so at the end this value will actually between the 0 and 15 with 15 inclusive and then we run two for loops these are not nested loops but they are sequentially called 1 The first for loop runs from zero to the truncated value that we get in the net second for loop runs from the truncated value to the size minus one and with this we basically fill up the array with the first for loop we fill the blocks With the value of stone and with the second for loop we fill the blocks with the value of air so we have some opaque blocks and some transparent blocks and to get the block index we use this red block index function which basically multiplies x y&z position and adds them To convert three int values to a single index and that’s all for this video and I hope you like it if you have any suggestions please leave them down below in the comments and do share it with your friends it really helps me out and in the next episode we’ll be going over The mesh building part and it would be the last episode of the series since after that you’ll be able to create your jumps and do whatever and expand it further so I made well another episode regarding what further can be done with this system and how you can optimize it In all but it should just be a talk I won’t be shown anything so that’s it for today thank you Video Information
This video, titled ‘UE4 Blueprint Tutorial – Minecraft like Voxel Terrain Generation : Part 3 Noise & Height Map’, was uploaded by CodeBlaze on 2020-06-18 07:56:03. It has garnered 5387 views and 72 likes. The duration of the video is 00:16:10 or 970 seconds.
This is simple blueprint tutorial series for minecraft like voxel terrain generation
Playlist – https://www.youtube.com/playlist?list=PLgji-9GMuqkKHBbUZroj_h7rd36Jdtygf
Voxel Chunks in Unity – https://www.youtube.com/playlist?list=PLgji-9GMuqkI77VmFk0Rol4AWKp-OgkGr
Project Source – https://github.com/BLaZeKiLL/UE4-Voxel-Tutorial/tree/master
Auburns Fast Noise Library – https://github.com/Auburns/FastNoise Fast Noise Generator Plugin – https://www.unrealengine.com/marketplace/en-US/product/fast-noise-generator
Follow me on Insta – https://www.instagram.com/code.blaze/
#UnrealEngine4 #Minecraft #WithMe