3 Ways to Scatter PCG Points on a MESH in Unreal Engine 5

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello in this video I'm going to be covering how to scatter PCG on a mesh how to use the procedural content generation framework to derive points off of a mesh that you've sculpted or imported into Unreal Engine how to scatter points on that mesh and then I'm going be sharing three different ways of controlling those points because once you have a bunch of points you need to be able to filter them and adjust them to control where you're spawning your meshes off of them so we're going to cover noises we're going to cover height how to use the height of the mesh to to filter the points as well as the angle of the surfaces so this should cover all the different ways that you might need to filter points on a mesh we've got a lot to cover so let's get into it I am using this cave mesh as a basis for this tutorial and this is a cave and all of the assets that I'm using in this tutorial I actually show you how to build in my crystal Caverns Master Class where I take you through the process of building an endless stylized cave World in Unreal Engine using PCG using the modeling tools inside engine I cover the materials lighting all that so if you're interested check that in the link below but we're going to be starting with this mesh that I've imported into my level and you can see on the right side here it's just a standard piece of geometry Inside My Level here okay so I'm going to make a new PCG graph in order to spawn the points in I'll right click on the empty space here go to PCG and choose PCG graph I'll call it PCG scatter example I will drag that into my environment and I'll just zoom out here to make sure it covers the area of my mesh that I want to be spawning on top of okay so let's open up this graph here let's first talk about how to get the point data from the mesh into our graph the first node we will add here is called a mesh sampler so right click type in mesh and we'll get mesh sampler now this will allow us to input the mesh that we have saved in our content browser for the cave in this case but it could be any type of mesh you're using so I'm going to come here type in cave and this will be the cave mesh that I'm adding it does not end here however because this is a generic mesh from our Conta browser we've dragged this mesh into our environment or modeled it in our environment either one so Unreal Engine knows the mesh specifically to get the points from and Sample but it doesn't necessarily know where you've put it in your environment and so we need a second step here in order to get that data into our graph we're going to use a get actor data node to get that data so I'll right click and type in get and we'll choose get actor data here now this is going to look at our actual scene or our level that we've added our PCG volume to and look for things inside that level to get the correct information from and this particular type of data is just one position so we want to get the position of the mesh that we have inside of our level and the way that we'll find that mesh is using a tag if I come here to actor filter and I'll drop it down and I'll choose all World actors so it's going to sample all the world actors or look for them in our level and choose the one by tag here which is what What It Is by default so under here by tag I'll make a tag that we'll use to find the mesh so I'll type in cave and pay close attention to your capitalization and and everything for this tag because you'll need to make sure that you do exactly the same on your mesh in your level so I'll I'll use this as a tag here and under mode I don't want to parse actor components in fact if you leave it this way it will crash Unreal Engine because what we really just need is one single point in our level that will tell us the position of our cave in this case so we'll get single point here all right so now we need a way of combining these points and moving the mesh sampler points to the position of the get actor data and that will be done using a copy points node so we'll plug in the source into mesh sampler and the target into get actor data okay so if we hit save and we debug this you will not see anything by default and that's because we need to add that tag that we're looking for to our mesh so I'll go ahead and click on that mesh on the right side here we will type in tag and it will take us to our component tag tags and our actor tags we want to add an actor tag so hit the plus button here and we'll type in the exact same tag that we put in our graph so once I hit enter on that you'll see the points suddenly appear directly on our mesh success these are actually tiny points and in order to actually look at some of the data that we're about to start adding I want to increase their bounds their size so we'll come back into our graph here and we will add a bounds modifier so I'll type in bounds add a bounds modifier in between these two nodes and the bounds modifier we will just increase our bounds minimum here up to 10 which will just boost all of our points up to visible size so we can actually see our density data on it okay so that's how you add points to a mesh now let's talk about how you would filter this data and actually be able to use it in some way so the first way that I'm going to show you is actually using noise and you probably are familiar with using noise if you used PGG before first going to show you the most basic type of noise so if we drag off here and we just type in noise in this recent version of Moll engine they've actually shown density noise here which is really helpful because they actually did away with that noise type of noise node instead they're using attribute noise now and you can add density to an attribute noise it's there so if you click on either one of these you'll get an attribute noise we just want to make sure that our input source here is density and the rest you can leave as it is this attribute noise if we come and look at it in the density channel so density if you're not familiar is the color of the points it's not the actual density of the points a little confusing for that reason it's just the color on the points and this color on the points is what we use to filter everything in PCG that's how it works this density noise here wow it's giving us a ton of just random density in the points which is great so this is a certain type of noise and you can see it's pretty General I'll say over all the points so if we want to start cutting out some of these points we will use a filter drag off of here and type in filter we want a density filter so if we look at that node we can see that it's starting to cut out some of the points and all we have to really do is play with these lower and upper bounds here and it we'll just start cutting out more and more points depending on what we choose so this is great but it's it's not really letting us control any sort of more organic placement it's pretty General and over all the points so the other type of noise we could use here is called a spatial noise so I'll disconnect this attribute noise and in place we will type in spatial noise noise and we will connect that in between now before I actually use the density filter on it I'm going to come over and debug the spatial Noise by hitting deep and we can see gray everywhere and this is fine I have to usually do a few adjustments to the noise to get it to show up correctly for me what I usually do is I increase the contrast of the noise to 10 so that it has a little bit more of a difference between the light and dark values because this is more of an organic type of noise so you're going to need to play with these values to get them to look like how you want increase the contrast and I also usually come to the transform here and I increase the scale to 100 is usually a good place to start for me and this is like a texture that's being repeated across the surface so you can see it's giving us a much more organic looking noise which is really cool and there's pearlin 2D there's also costic 2D a bunch of different noises here so we can now take this data come over to our density filter and cut that out and get a nice organic looking clumping of points which is really cool and in my master class I actually use this to start populating different types of organic growth on the walls so this is really useful for that type of thing okay so so the spatial noise gives us that type of control and if we wanted to actually spawn meshes in here that would be really easy I could just drag off of this density filter and static mesh spawner and I'll choose one of the meshes I show you how to model as part of the master class so I'll come down here to mesh entries click on it and we'll choose one of the rocks that we built so I'll type in rock and we'll choose one of those and uh that's a kind of a funky look but it will start spawning our points and we might need to actually use the density filter to cut this out quite a bit more to get something usable okay so this is one way of controlling our points with noise now let's talk about spatial data we have two ways of approaching this the first approach is using the height of the mesh and this is an approach that will work on meshes but it will also work on landscape so if you you know have a mountain and you want to have the trees only grow a certain distance up the mountain and then cut off and then you have like snow on the top of the mountain that's when you start using height to mask out things the way we do that remove this spatial noise here and what we're going to make is an execute blueprint node so I'm going to right click and type in execute and we'll get execute blueprint and we'll connect that up now we have to use this node because the function that we're going to be accessing doesn't actually have its own node yet maybe in the future it will you'll find this tutorial later and search it and find the node that we want but at the moment we need to access this function through the blueprint so when we make one of these we have this blueprint element type here so we're going to click on the drop down and we're just going to type in height and we should see height to density so we're going to go ahead and click on that now let's look at this by pressing D on that node at first it looks just white everywhere it doesn't really show us any sort of gradient for height but that's because when we're talking about height it doesn't actually know where the height area that we want to control in our mesh actually is so we need to actually offset the gradient that it's using for height up or down so that it lines up with the area of the mesh that we actually want to use and mask if I come over here to the gradient offset here offset it by 100 we can see it's uh down where the water is here so it's not quite high enough so I'll I'll come back and maybe I'll make it 1,000 and you can see now it has masked above and below 1,000 and if we want this to be a more smooth gradient we just have to come in here to the gradient scale and let's try increasing that to 100 that'll start to smooth out the gradient maybe we will again increase that to 1,000 and that will give us a much more gradual look to our height and we can offset it back down a little bit if we want maybe 700 then we can use our density filter same as before to cut out the points oh we need to adjust our range now so now we're just spawning our points on the roof I'm actually going to disable these meshes for the moment so this is a way that you could actually use these points to cut off only specific areas of the ceiling or if we want to invert it we could also just use it to cut off the ground so you just have rocks on the ground so this is how you use height to actually affect and mask out your points and all it is is just coming in here and adjusting these values so the actual gradient offset to get it into the right area of your mesh and then the gradient scale to control how blended it is and then you're using density filter to cut out those color values between zero and one okay so that's using height to mask our meshes the last way that we're going to cover is how to use the angle of the surface what we're going to be using is called normals normals on a mesh are what tell the light how to move along the surface it's just a piece of data that's contained in the mesh and Records what angle that mesh is actually pointing so it's used for lighting data you can use it for materials and you can also use it for PCG if I go ahead and delete this height to density and we're going to drag off and this time we're just going to type in normal and we're going to choose normal to density click on that and let's go ahead and debug that node all right so right away it's actually giving us a similar look to our height mask and what it's doing is if we look in this node we have a normal input and we have an x y and a zv value these are axises so right now there's a zero in the X Y and the Z which is the up and down has a positive one in it that means that it's masking out all these surface normals that are pointing up and then it has a sort of a gradient as they're starting to point up less and you can always control the strength and offset to adjust that you can see here all these surfaces all these faces of the mesh that are pointing up are white because it's one now if we wanted to have all the surfaces that are pointing down be white we would just change this to negative one now all the surfaces that are pointing down are white and then again we can use our density filter to cut them out I'll mess with my bounds here so I cut out that and then we'll uncheck invert so it's just grabbing the roof okay so you can see this is like a really great way to start spawning you know different types of rocks different types of foliage that would only grow from the ground or above if I switch it back to positive one here we're just getting our points from the ground and if we come here to our normal to deny node and we grab the x value for example we'll get all the surfaces pointing in the positive X Direction and if we want all the surfaces pointing in the positive X Direction and the negative X Direction so you can see here we can't put a positive and a negative one in at the same time we will just make another node here just copy that node and instead of positive one we'll make it negative 1 and the node that we will use to add these together is you guess it called the add node so I'll disconnect this here right click and make an add node I'll just connect up the A and B to these two outputs and you'll get an error here and that is because it doesn't actually know what type of data to add yet so all we have to do is come over to the input source one change it to density and the input source 2 change it to density now it's adding those two densities together so now if we connect that up we can see we're getting the faces pointing in the positive and negative X Direction so you can use these face directions to do any type of masking that you need so this is the basis for all the type of spawning that we would need to do on a mesh so further down the road it will look something like this where you have rocks on the ground slag tights on the ceiling slag mites actually I get confused which is which crystals any type of growth that you need on a mesh you can achieve using these different placement strategies all right hopefully you found this video helpful if you did shoot me a thumbs up and a comment if you have any questions about how you'd apply this to a different situation definitely drop them below and like I said all of the assets and the entire cave work world I used in this example I show you how to build from scratch in my crystal Caverns Master Class you can find out more in this video right here if you'd like to take a look and otherwise I will see you in the next one
Info
Channel: Aziel Arts
Views: 3,826
Rating: undefined out of 5
Keywords:
Id: Y70rxO0Q2J8
Channel Id: undefined
Length: 14min 44sec (884 seconds)
Published: Mon May 13 2024
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.