Unreal Engine 5.2 PCG Tutorial - Landscape Material Sampling

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hey everyone today I'm going to show you how to use PCG graph to sample landscape layer data it'll allow you to Auto populate static meshes on layers I'll also show you how to detect the edges of layers which can allow you to create a harsh border between two terrains you can also let you create a path lined with trees that is looking pretty satisfying just a word of caution before you jump into this tutorial there is a bug in version 5.2 that's going to be fixed in version 5.3 if your landscape is set to component subsections two by two the landscape sampler is going to be a little off from what you need so this is not going to work for that you need the component subsections to be one by one and unfortunately the default open world map is set to 2x2 so you will need to create your own landscape all right I've got a new map open I've created my landscape and its component sub sections are set to one by one I've created three different layers and painted two of them onto the landscape let's get started first off I'm going to create a PCG graph I'll call it PCG underscore land Escape layers and I'll drag that into the world now let's open up and I'll show you what we're looking at so you can get this data in at least three ways one of them is to do a surface sampler and plug in landscape into the surface sampler and let's inspect it and if I scroll over to the right I see sandstone dirt and snow and the total of these layers is weighted from zero to one and if you look at landscape height this does not appear so make sure you're getting the data from landscape we can also get the data from a get landscape data node and if we inspect this then we see the same data sampled although it will return a few more points than the surface sampler sixteen thousand versus 145 so quite a few more points but in this case I'm going to do something else I'm going to create a blueprint and I will call it BP underscore landscape layers and if I open it up I'm going to add a spline component and a PCG component the PCG graph all simply set to this PCG underscore landscape layers BCG that I just created and the spline let me zoom out a little bit I'm going to expand the spline a fair bit and set it to closed loop and I'll compile save close that and let's delete this PCG volume from the world and add my blueprint in and it's a little small now so let's expand this all right back in the PCG graph I'm going to use a get spline data node I've said itself because the spline is on the same actor that holds the PCG volume and now I'm going to do a spline sampler and set it to distance on interior and now I'm just going to hook it up to a projection node and project landscape as the Target and just like the surface sampler using landscape as the target gives me layer information all right so now let's add a point filter to do something with the layer information I'm going to just use Sandstone as the target attribute and you'll just use whatever your layer is named you will want to check use constant threshold and you'll see this warning can't broadcast threshold type to Target type well change the type to float instead of double and that should clear up that error and I'm just going to set it to 0.5 and now if I add a transform point this will let me preview the point filter debug selected and there we go there are my Sandstone layers so let me just add a static mesh spawner for this and turn off debug for the static mesh spawner I'm going to use I'm a good old fallback SM Rock and let me change this to no Collision just so it spawns faster and there we go a bunch of rocks a few too many rocks let's fix this by for now just changing sample space into 500. few less rocks we'll clean that up later all right so next I'm going to create a follow-up Point filter and pipe the outside information into this one so we've eliminated anything that is sandstone greater than 0.5 this one I'm going to say if snow is greater than 0.5 we'll use it and let me just copy these transform points and static mesh spawner I'm going to set this one to Roman statue and now we've got Roman statues on the other side and now let's create this border between the two so what I've done is well let me show you after this point filter where I've split off sandstone I'm going to check is snow greater than zero which means snow has been painted anywhere at all and I will hook up the inside filter to this and if it is greater than zero I want to make those crazy spikes and if it's not I'll just drop it back into this rock spawner so there you go you see that this has created a bit of a border and I I created this border by taking away from the Sandstone basically but you could do it on the other side or both sides if you want all right so let's grab this drop in a transform points and let's make these distinct just to start off with so for the scale Min and Max I've undone these locks so that I can set these values to different values and I'm going to uncheck uniform scale so let's make them point two to point four in their X and Y width which is going to make them a little spiky and then two to four for their Z scale rotation let's do negative 45 to 45 and 0 to 360. and then offset Minimax let's give them the little offset me to Max and I'll go ahead and do this for other nodes at the end but for now I'm just giving you some nice spikes to denote the Border okay so next let's work on the pathway and to do that let me first paint a path straight through the center here and since this path has taken away from the Sandstone layer and the snow layer we've got nothing here so now I'll reuse this point filter just pipe the outside filter on in and let's say if dirt is greater than in this case I'm going to say greater than zero and now let's drop a transform points just to preview the node so if I debug this I see the points right here and they're all along the pathway the reason I didn't just pipe this straight in is as a safety if I'm working with a lot of layers than a layer without any of this dirt layer might come through so it's just a little safer to put the point filter and say does dirt exist at all all right so next I'm going to pipe this into another Point filter instead of the transform points and what I'm going to do is separate out whether or not I want to spawn a tree or I want to spawn some smaller foliage and for this I'll say is dirt less than 0.75 and if it is I'll drop it into a static mesh spawner and this static mesh spawner is going to be trees there we go there are trees at the edge there and then after this I'm going to drop it into another Point filter and say is dirt less than constant threshold float one and setting it to less than one will make it only appear on the border let's just use this bush static mesh there we go SM Bush nice little thing and now we've got a few bushes a little inset from the trees and I'm not going to use this last set of points but if I debug them you'll see that I've eliminated the very center of the path where it's the strongest so you could put some other doodads here some Twigs whatever you want and leave the bushes and trees on the outside of the path but I am not going to use this at all I'm just going to discard this and now that's pretty much everything this is the graph that I showed you initially except that I just need to add some more Point transforms and let's go ahead and do that now all right I've got that set up let's set up the transforms on this thing these are the Rocks so I'll just jumble them up a little bit negative 50 to 50 negative 20. 20 and 0 to 360 rotation and let's jumble up the Roman statues as well let's make them rotate 0 to 360 and besides let's check this box and size three to five and let's see let's do the trees I find these can move around a lot more and let's just give them a tiny bit of X Y or pitch and roll and then set the yacht from 0 to 360 and making 0.8 to 1.3 and let's pretty much do the same thing for the bushes negative 300 though they're a little smaller so I don't want them moving quite as much and negative five negative five five zero to 360 and point eight to one point three okay so that's getting close but the spikes need to be a lot denser so now what I'm going to do is go and add a density noise node and I'm going to put it right after projection if we look at projection and let me turn off all of these static mesh spawners you can see that all the points are white they're all one density so adding a density noise here will allow me to randomly filter out some of these nodes some of these points as we go on and now if I debug this there we go we got the noise okay so let me add a density filter right in here this is for the rocks and I can turn off debug and re-enable these static meshes and this density filter I'm going to do make it really aggressive and let's add a density filter for the Roman statues and this I'm going to make even more aggressive and one more density filter this time for the trees a little less aggressive on this one 0.8 works and let me take a little time to organize this while we're doing that let me talk about my philosophy of graph layout if you look at these Point filters I'm piping the points One Direction or another but they never loop back on themselves so I'm being really efficient by only touching each point as few times as possible and that's going to let my graph generate faster and use fewer resources doing so all right done with organization let's look at the results well that's uh not very good so what I need to do is back under the spline sampler let's change this back to 100 sample spacing and there we go now I can go find my blueprint and expand it dramatically and we've got the thing that I demoed initially let's bump this to a strength up to one so I can paint some here there we go so you've learned how to access landscape layer info and how to detect the borders via just the general property of how landscape layers work all right have fun
Info
Channel: Michael Royalty
Views: 16,307
Rating: undefined out of 5
Keywords:
Id: tEn4_1s_i0k
Channel Id: undefined
Length: 14min 31sec (871 seconds)
Published: Tue Jul 25 2023
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.