Unreal Engine 5.2 PCG Tutorial - Using a Height Filter to Place Trees on a Mountain

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
thank you hello everyone I'm going to show you how to put trees on a mountain just like this by using PCG graph these trees are separated by height with sparse coverage on high Z level and thicker coverage on the lower Z level I've already created this mountain but if you don't have one you can simply create a new open world map and paint a mountain in with the landscape tool you'll also need the procedural content generation framework plugin so if you don't see the PCG graph you can add it by going to edit plugins and searching for procedural let's get to it right click in your content browser to create a PCG graph I'm going to name mine PCG underscore Mountain trees tutorial and drag and drop it into the level since I'm using a single graph for this I'm just going to zero out its position and scale it to cover the entire level yeah that seems big enough now let's open the graph the first thing I'll do is add a surface sampler node connected to landscape height this will place points all over the landscape which I'll use as the basis for everything then the important node for this tutorial the point filter Point filter lets you access a bunch of the properties you pull in from the landscape node in this case I'm going to select position position is a vector and I only want the z-axis so we'll type period and Z after it to access the Z variable next I want to filter on a fixed value so I'm going to check use constant threshold and select float I've got my height filter I'm going to start with 7000 units because I know that's about the height of my lower border between ground and snow you'll notice if you debug this node it doesn't look like it's working that's because you need to connect another node to it to see the results I think it's showing you both the inside and outside results by default so I'll look up transform points node here and there we go I don't want these trees to go all the way up to the top of the mountain they should stop at the snow line here so let me add another Point filter you can hold down control to disconnect a link and pop it onto a new node I'll filter on position.z just like the last one but this time I'm setting it to less than make it a constant end float and I'll set it to let's start with 14 000 units hook the transform points node back in and debug it to see the results let's take a look that's removed the top and now I have a band of trees now there's a peak that I want to make sure the top line is just below I think I can lower it a bit so let's try 13 000. that looks good I'll take a look at the bottom line that looks a little low so 7 500. great looking at the span of trees it seems a little too crisp I'm going to add a little Randomness to it in this transform node let's set the X and Y to plus and minus 500 and while I'm at it I'll set the rotation between 0 and 360 to let those trees face any direction and I'll also set the scale to 0.8 to 1.5 because that seems to be a decent size range for these trees looking at these points you can see they're now floating off the ground now that's not that good because I'm going to drop them down and that will add the randomness I'm looking for to do that use a projection node and connect the projection Target up to the landscape height I'll debug this to check and there they're all on the surface again and the edge looks a lot less crisp here's a problem though most trees don't grow on Cliff sides so I'm going to remove them to do that I can hook up a normal to density node which will set the density of nodes based on the surface angle let's debug that and here's a problem the points aren't rotating to the landscape and that's because we use the landscape height node in the projection and Landscape height does not include rotation so let's remove that and hook it up to the landscape node much better now all I need is the density filter node which will let me remove the points on a steeper slope which are set to a lower density by the normal density node I'll debug and the cliff faces are better let's pull that back a little bit though 0.4 seems good yeah I'm happy with that to finish it up I'm going to add a self-printing node which will remove overlapping points and finally the static mesh spawner I'm going to detour into the marketplace to get the trees I need for this project I'm going to use the temperate vegetation Spruce Forest asset pack by project nature it's free on the marketplace and it looks great when importing it you may run into a version mismatch just check the box to show all versions and select the highest version number available 5.1 in this case then it'll import just fine back to the graph I'm going to hook up the static mesh spawner and then in the static mesh spawner I'm going to add a mesh entry and select the half tree as the static mesh as a force of habit I set the meshes to static with no Collision no Collision is especially useful because spawning colliders can get expensive and when you're dealing with a lot of objects you want them to spawn as fast as possible and let's take a look here's a problem they're all rotated in random directions and that's because of the projection node I set the rotation with it but I never zeroed it out I could uncheck the projector rotations option but then my normal density node wouldn't work so instead I'm going to add a transform points node after the density filter this will let me reset the rotation a check absolute rotation and set the rotation from 0 to 360. that's fixed it checking absolute makes the rotation start from zero instead of being relative to its current location now I can go back to the earlier transform node and remove the rotation since it's being overridden by the projection node now there's another thing I want to fix let me zoom in here and the debug blocks are hiding it so let me toggle them off the trees are partly hovering off the ground to fix that I can go back to the transform node and set the Z position to negative 100 this loses the roots but the trees look a lot better it's hard to see with the outline so let me deselect them there this is looking pretty good I just have a few more updates to do on the meshes now see how these trees are swinging the wind it looks great but at a distance it's hardly noticeable and it could cause some frame drops so I'm going to use the world position offset distance to stop movement when the tree is far away let me set it to 1 to demonstrate and here's another issue this pack doesn't come with nanite enabled by default and the world position offset only seems to work with nanite so let's go into the pack and enable nanite filtered static mesh right click enable nanite back to the world view you can see the trees have stopped moving let me turn that back to zero they're moving again I'm going to back up the view a bit until I can't really see them moving this looks good okay so I want the trees to stop moving at this distance from the camera but I don't really know how far it is fortunately I have an easy reference point I can set the instance end call distance and when the trees disappear I know I've found the right distance let's start with 7 500. perfect okay so I'll set zero Cooling and set the world position offset distance to 7 500. now if I'm this far away they don't move but if I'm closer they do now that I've streamlined the tree performance I'm going to add some more tree meshes to keep all my previous settings I click the drop down on the index and select duplicate then I just have to open up each one of them and select the new mesh duplicate is nice because you only have to set up your static mesh settings once then you get to copy them to the rest that's the last one so let's take a look and that's the upper layer of trees let's copy everything and make the lower trees just gotta drag everything down so it's not overlapping hook up Landscape to the projection node and set the outside node of our first point filter to this one I'll change the point filter on this set of trees to be a lower bounce let me set it to 500 to show you what it does you can use this lower bounds filter if you have some lowlands that you don't want the trees going into or maybe you've set up a river or Island and don't want the trees to go down to the water level I'm going to leave it at zero because I want trees all the way to the edge of the map now that I've got the trees placed I'll change their meshes over to the ones I want to use for the lower Forest the full tree meshes are a bit thicker and denser so it'll give good coverage there are only three of these so I'll delete the fourth entry these trees look a little sparse for the forest I'm going for I'm going to fix this by changing up the surface sampler node I know that setting the points to 1 X and Y to 75 and Z to 10 will have some good results C to 10 will let trees Stack Up on slopes which I think looks pretty good now here's another problem the upper trees are now too dense so I'm going to add a density filter in there and let's see density filter lets me randomly remove points because the surface sampler has set all of the nodes to a random density let's start with 0.4 that seems a little too dense let's try 0.7 there we go one last thing I think the two types of trees can be too close together so I'm going to make it so that the upper trees remove the lower trees when they're close to each other like right here to do that I'm going to set up a difference node I want to remove the lower trees when there's an overlap so I'll use the lower trees as the source and the upper trees as the difference change it to Binary to make sure that it's removing every overlap and it didn't work that's because I set the z-axis to 10 in the surface sampler so these points can look like they're overlapping without actually touching so to fix that I'll plug a bounds node into the upper trees before I plug them into the difference node that will let me set their size back to something easier to work with 75 is 7.5 times 10 so I'll start with Z at 7.5 and I want this to be a little bigger so I'll double it to 2 2 and 15. there's still one lower tree remaining so I'll increase Z to 25 and 25 and that removed the tree I'll zoom out for one last look at everything the upper trees are looking a little sparse so go back to the first density filter and reduce it to 0.3 that looks great and that's everything I have to show thanks for watching this tutorial I'll catch you next time all right this was bothering me so I'm just going to tidy up these nodes before ending if I highlight the top set of nodes and press C that'll add a comment and I can name it upper trees and I'll set it to a nice blue color say that looks good and I can drag drag the comment box up and if I highlight all of these nodes and press Q on the keyboard that will line them up I can do the same thing for the bottom I'll call it lower trees you can't see that but there we go lower trees and I'll make this one green oh and that's bright all right I'll highlight them and press Q as well and let's move this bounce modifier up and lastly I'll set the first three nodes hit q line them up and there we go that's a lot nicer now I'm done
Info
Channel: Michael Royalty
Views: 597
Rating: undefined out of 5
Keywords:
Id: pveLvjpDY5I
Channel Id: undefined
Length: 13min 20sec (800 seconds)
Published: Thu Jun 01 2023
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.