Paint PCG! Using Textures and Landscape Layers with PCG in Unreal Engine 5

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello and welcome in this video I'm going to be covering how to use textures to drive your PCG graphs we're going to be covering how to use Simple textures to drive things like placement and scale how to use more complicated textures like you might export from Gaia or World machine to drive an entire landscape worth of PCG and what we're going to cover at the end which is going to make it all work together is how to drive PCG specifically with landscape layers which could be driven by textures or painted this is really exciting because it unlocks a lot of potential to be able to combine the existing World building and Landscape tools inside of Unreal Engine with PCGS streamlined approach to foliage and object placement so let's get into it so I'm going to be starting with this stylized environment if you'd like to learn how to build this particular environment which was inspired by the Zelda games definitely check out the video below but we're going to use this as a starting point because we're going to start to use textures to do different things to this this existing PCG graph so I'm going to open up that graph here and we can see over here is all of the logic related to spawning the foliage we have grass rocks flowers trees plants and bushes I'm going to disconnect this from the surface sampler and if you're a little lost at this point you might want to check out my beginner's guide PCG video which I will link below but if you're tracking with me so far we're going to grab this surface sampler and I'm going to right click in the empty space here and type in texture and we're going to get texture data this node is going to allow me to read an existing texture I've already imported into Unreal Engine as some data in order to affect my graph and if we click on it here we see the texture input right here now I have this black and white mask here you can use black and white values to drive this mask or if you have a texture that has different types of masks embedded in red green or blue channels that also works we're going to grab this simple sphere this simple mask to start with I'm going to drag this texture directly into the input here and by default you're probably going to get an error now that's because the texture needs to be using some very specific compression settings so let me open up the texture here by default this particular node in PCG will only let us use the texture if we choose some very specific settings you can always check by what that is by hovering over the aor here what I'm going to do is change the compression settings to to Vector displacement map and we're going to go ahead and hit save come back over to my PCG graph I'm going to remove the texture and then read it and you'll see we no longer get an error below that texture value we can choose what color Channel we want to drive this particular mask and if you had textures embedded in red green or blue channels this is where you'd be able to choose that but I'm going to go ahead and choose red because it's just a black and white mask that will work just fine for me now I'm going to move this graph down and take a look at what this node is giving me if I select the node mode and hit D to debug and I move my camera up here if I zoom out here we can see the texture data contained as points here by default it might be a lot of points and we don't actually need this amount of points in order to drive our graph we actually want to use less points because it's going to be easier on the computer to simulate so the way I would adjust that is coming back over here to my texture data node and coming down here to texal size texal size is going to be that size of the point and by increasing this size we're going to tell PCG to use fewer and larger points in order to resolve our image I'm going to up this to maybe 200 and see how it looks we can see we're getting much bigger cubes which represent our PCG points and this is going to work a lot nicer I could even up it to 300 if I want it to be extra efficient and that will still probably work pretty well for what we're going to use it for which is to cut out the existing points that we have on our graph so you'll see I have this surface sampler here and this is what I'm using to drive the full foliage of the PCD graph what we can do in order to use this texture as a mask use a difference node so I'm going to right click here make a difference node and I will plug the source into the point from the surface sampler here which if I hit D just to look at what they are and I will uncheck debugging on the texture data here by pressing D and we'll take a look and these are all the points that I'm using to drive my PCG graph that are sampled from the landscape if I now plug this texture data node into the difference node we can see that it is taking the points from the texture data node and cutting that section out of my existing Point data you can see it's making this circle on our landscape which is exactly what we want now we can go ahead and plug this straight into our foliage spawning section here but by default you will get a few errors in your graph in the spatial noise here we see an error and a warning in the density filter and that is easily solved by disconnecting this again and making a a two points node two point which will make sure all the data is getting converted correctly into the point format which is what these other nodes need to use in order to spawn meshes and stuff so we're going to connect that up here and stop debugging the difference node and we can see we have a perfectly circular cutout bald spot in our PCG graph if we want to adjust these particular position of this circle or the size we can do that inside of our texture data node by coming over here to texture data we have these transform options here so if I reduce the scale here to something like2 it's going to make a little tiny Circle in the center and we can also use this to change its location and placement on the landscape as we tile it it's cutting out the additional shapes that this is tiled into for even more settings you can always come here to the use Advanced tiling section check it on and you have a few more settings here for tiling below that is how you use a texture to cut out existing points what if we want to use use a texture to spawn the points themselves we can do that I'm just going to go ahead and duplicate this texture data node down here and let's use this soft Circle texture I've already changed its compression type so it should work fine looks like it does I'm going to go ahead and debug that node and take a look and we can see that there are colors now to our points because it's picking up on the fact that this texture has a black to white gradient and so it's reflecting that gradient in the density values of the points which are really just a black or white value or gray value something cool about using textures is that we can use their color values to actually drive additional properties we can use them to cut out our points but we can also use them to drive things like scale so let's try that back in my graph here I'm going to rightclick in the empty space and type in Blueprint and we're going to choose this execute blueprint node here now this is a way to access additional tools that aren't necessarily readily available to us by searching this execute blue print gives us access to choose additional functions that maybe are under development or just haven't been made into nodes for whatever reason within this drop down here under the blueprint element type we can type in scale and we will find scale by density if I click on that it will fill in this blueprint with the name scale by density and now I can use it as an existing node now I will plug in the texture data and you'll see by default it automatically creates a two points node for me which is great and let's go ahead and debug this scale by density node by default you will see nothing and that is because if we look at the scale density section here we can see the scale minimum and scale maximum which are the minimum size and maximum size that the points will be when using the texture as both zero so if I change the scale Max to one now we can see our points scaling from one down to zero using the black and white values of the texture if we always wanted to flip this and use the white values as the smallest size we can always do that by just flipping the numbers here adding one into Min and zero into max we can also affect the density exponent which will control how quickly or intensely they scale down to their minimum size and remember you don't have to use zero as the minimum size you could use 0.5 as well I'm going to default this and go back to 0 to one as my settings let's use this to actually spawn some trees so I will drag off of here and make a transform points node in case we need to adjust these sides of the trees here and drag off of that and make a static mesh Spawner in the static mesh spawner I'll hit the little plus icon here expand little descriptor here and under static Mish I will type in tree and I will use it to choose one of my trees here and I will choose tree large 01 which will give us a funky looking tree shape here these assets I'm using are part of a Marketplace pack I will link that pack below this video so I have too many trees right now normally what I would do is go back adjust the number of points being sampled from the landscape but in this case it's a texture so what I have to do is go back to the texture data here and increase that texal size maybe I'll try 600 that will make a lot fewer trees here and I can always adjust the randomness the points with a minimum and maximum scale here in the transform point section A random rotation which is 0 to 360 as the maximum we can see we're getting a fun little plump of trees here so that's great you're probably wondering okay I can see how we can use Simple textures to drive PCG but what if I have more complicated textures or my landscape is not flat because up until this point we've just been using a flat texture on a flat landscape so let's jump into a more complicated example that's going to be using maps that you may have exported from World machine or Gaia okay so I'm going to be using this level as this example and this is a landscape that I have imported from a height map exported from Gaia and we can see here if we look at the landscape settings under manage and import I have loaded my height map in here in the import section I have these various landscape materials which are driven by different textures I can really quickly show you what they are for example I have this texture which I exported which I'm using to tell my landscape where there should be foliage that's growing next to the water so these are much more complicated Maps than I was using before like I said you can either get them from Gaia or World machine if you'd like a tutorial on how to get that from Gaia drop a comment below and let me know I'm happy to make one of those so I have a map here for foliage height which is telling the landscape the actual shape it should be the river bed specifically so we can have some mud at the bottom of the river rock and sand they all have different maps and they're all driving these materials on the landscape how do I use those same maps to drive my PCG graph so I can have foliage being spawned in particular areas on my landscape and this is you'll notice is a much larger landscape than we were dealing with before so let me open up my PCG graph that I've already added in here one quick note this PCG graph will need to be the size and shape of your landscape exactly in order for this particular method to work later on i' be showing you a method in which you don't need that to be the case since we're using a texture we need the texture to line up with the textures of the landscape and that is what needs to happen a quick way to make sure your PCG graph and Landscape are completely lined up is to check your landscape make sure your PCD graph is at zero in the X and zero in the Y so it's in the center of the world and if your landscape was also created in the center of world then it should line up perfectly the size will be if we click on our landscape here we can see the resolution inverts right here and that is the number we just have to half that number in order to come up with the size that we need our PCG volume to be in X and Y 217 for me I can come back here to the scale and I've made it 1,00 and 8 in X and in y I know it's not exactly half but we could add in 0.5 here just to make it 100% perfect and then you just have to make sure that the height of the PCG volume here is lining up with the height of your landscape but the actual bounds should match it exactly in this case so let's open up our PCD graph here again I'm actually using the same foliage spawning that I was using in the previous level so let's come over here right click and make a new texture node get texture data we will come in here to the texture I will drag in the foliage map here that I already converted over to Vector displacement which I showed you how to do earlier drag that texture in preemptively since this landscape is so large I really want to make sure that my texal size starts out pretty big even before I tried to debug it and look at it because it might slow my computer down significantly so I'm going to increase my texal density size here to 500 and then if we come over here hit D to debug this node we come up here really high you can see that it is completely white and that is because we're not actually sampling pulling the correct color channel in our texture so I'll come over here to my color Channel and switch it to Red which case you will start to see the correct texture from the landscape coming through but you will notice we have another problem and that is this texture is flat and the landscape is not flat so how do we get it to match the landscape so what we're going to be using is called a projection node so I'm going to come over here to my graph right click in the empty space type in projection we will create that node and the in is going to be connected to my texture data here I'll stop debugging the get texture node what I need in order to project it is what I'm projecting on which in this case is a landscape so I'll expand the input node here grab the landscape and connect it into projection Target now if we look at that projection node by debugging it we can see that my texture has been projected down onto the landscape if you're not seeing this just double check that your PCG bound here is tall enough to Encompass the full height and depth of your landscape that's something I sometimes run into if you don't see this just double check that so we can see here that if we want to spawn foliage only around the river which is what I want to do here we have a white value that's close to the river gradually expands out to a darker value so all we need to use now to filter those points is a density filter I'm going to type in filter and choose density filter here we will take a look at that node by debugging it and now we have just the points that are surrounding that River area and we can always adjust our bounds here by Contracting either the upper bound or lower bound which it whichever happens to be specific to our texture that looks pretty good actually it's pretty well placed on the particular green areas of my landscape now I need to introduce some Randomness to these points because I'm going to be using these particular points to spawn my foliage and at the moment they are very much in a gridlike format so I need to do quite a bit of work to them in order to make them feel more random as if I was sampling them from the landscape at the end of the density filter I will add a transform point we just need to add some rotation and translation to these points so under the rotation Max I will go ahead and up that to 360 in the Za axis I'll go ahead and debug these points now they are all rotating a random Direction next I will come over to the translation if you are unsure of what random translation to add to the points A good rule of thumb to follow is to come over here to your texture data and take a look at your texal size and if you can imagine that the texal size is the complete width of each of your points you can be pretty sure that half of that texal size will be a good number to start with both in the positive and negative Direction in terms of positioning and you can always go above that but that's a good place to start if I come back here to the transform points come over here to the minimum offset I know that it could be -250 which is half of 500 which was our texal densities and -250 the X and Y here in the maximum it will be postive 250 and positive 250 if we come over here we can see that our points are looking a lot more random and of course you can always up these values higher than this these numbers but this is the kind of minimum Threshold at which the point will move enough for it to start to look random so let's go add a node that we added before again which is scale by density all right right click type in Blueprint and add execute blueprint we'll put that right after the transform points and I will choose scale by density here and we'll choose the maximum as one and we'll take a look at what this node is giving us what I'm trying to achieve here is that the foliage that's closer to the water or further away from the water is smaller which gives the feeling like the water is feeding the actual foliage itself which is why it happens to be growing here in the desert this kind of Oasis look I will actually increase the density exponent here to two to create more of a contrast between the inside objects and the outside objects I can even increase the scale Max to be 1.5 maybe final thing I can add in order to give it a more natural look is some sort of noise we can see that later on in my foliage spawning I'm using spatial density noise and density filters in order to filter out different amounts of points in order to spawn my foliage when you sample the landscape it gives you a very speckled noisy look to the density of your point by density again I mean the color value from white to black that it has we need to add that noise back in for this case I'm going to use a attribute noise which if you were using previous versions of Unreal Engine was called density noise now it's attribute noise stop debugging the skill density I'll right click and type in noise and I will choose attribute Noise by default it is set to density so if I debug this we can see it adds back in that speckled density noise that we are familiar with from sampling Landscapes I will plug this attribute noise into my foliage and take a look at what we have all right that looks pretty good um it's looking a little sparse to me so I might want to increase the number of points which I could do at this point it's always good to start on the low side of the points and then gradually increase them just for the sake of keeping it optimized but at this point I could come back over to the get texture data node here we can lower the texal size so remember that means we're increasing the number of points because each point is up against each other and when they get smaller there's room for more points so I will lower it down to 300 suddenly we get a lot more foliage we could even try to drop it to 100 see how that looks that gives us something very dense depends on the look that you're going for as well as your machine's specs in what it can actually handle in this case if you're curious about ways to optimize PCG I will link that video below as well I have a few tips for how I particularly optimize it mine is running pretty smoothly here and I'm also using these more stylized assets which helps a lot and allows me to make it a lot more dense I just used one texture map in this case I could use the texture placement map I'm using for the sand or the rocks to spawn a separate graph of PCG or spawn rocks only on the sand foliage on the green the opportunity is pretty much endless to whatever your creative direction is whatever Maps you've exported out of those other softwares speaking of which what if we don't want to use textures or we want to use landscape layers that we're painting this is where things start to get interesting because you will know that you can drive landscape layers by texture Maps so if we're able to connect PCG to our landscape layers themselves then we have the best of both worlds and we have the ability to custom paint areas where we want the PCG foliage to spawn which gives you a lot more creative control so I know sometimes when you're using PCG it can be difficult when you want more creative control over where things are placed this is a way to achieve that okay so I'm going to be using this level as an example and I've already painted a few different areas with different landscape layers if we open up our landscape mode from the top left drop down here and we come to the paint tab here if you've already set up your landscape layers this is where you would be able to click on one of them and paint a particular area with the different landscape material in this case I'm going to use the actual grass to be the layer that drives the placement of my PCG foliage so let's open up our PCG graph that I've already added to this level and same I have the foliage being spawned same exact foliage spawning I'm using in the previous two examples but in this case we're going to start with our surface sampler because we're going to start by sampling our landscape if you are unsure of how to actually set up these landscape layers let me know in the comments and I'll maybe make a video about it but we'll start this particular tutorial from you having set up your landscape layers as separate paintable layers here in your material the asset pack that I also linked Below in the description has these layers already set up for you but you could also make your own landscape layers it's not too complicated to do but imagining that we've already set up those layers here how do we actually access the data that's in contained in these landscape lers the first thing we will do is Select our little surface sampler here now I want to look at what data I'm getting here from the landscape because it's not just points so I want to see if I'm able to get the data from this node about what points on the landscape overlap app with these various layers so I'm going to right click on the surface sampler choose instead of debug inspect and this is a way to look at the data that we're getting from each node in this bottom panel below here if you're not seeing anything there you'll need to come up to the drop down at the top and choose the graph that you currently have open when you do that you will start to see a list of points here these are all the points that it's sampling from the landscape in this case if we scroll here to the right we will eventually come to our actual landscape layer names whatever you created as your landscape layer names will show up here and we'll be getting points from those so now that I know that that data exists inside this node we can find a way to filter it out and use it in our PCG graph so I'm going to contract this down and drag off of this node and what I'm going to get is called a point filter this point filter is what it sounds like it's going to filter out the points from a particular attribute and so all I have to do is come to the Target attribute here type in the name of the layer make sure it's the exact name that it is named on the left side here I will type grass only cuz that is the name of my landscape layer that I'm going to be painting right away you'll get an error and that is because the data type here which is a double by default is not the same data as you're getting from that layer you'll see it's just it's a number so in this case it would be a float which is a single number I'm coming over here going to expand this and choose use constant threshold and now I can change the type of data from a double to a float which should remove the error there now if we go ahead and debug this node it's not actually going to show us what it's filtering out and that is because you can see on the output here of the node you have inside the filter or outside the filter so let's add a transform points node so we can debug that and actually see what these different outputs are giving us so I'll drag off of inside filter which is the points inside that layer you've painted and make a transform node we go ahead and debug that transform points we can see we're finally getting actual points from our landscape layer and we can actually adjust in our filter the float value that we're cutting off so I increase this here this will cut further into the areas of the Mask between those two layers that is you know between zero and one opacity so if I cut this off at 0.5 of the way through that blend between those two layers it's going to cut off the point and this might actually we want to increase more till it's just in inside our painted area here and this will depend on how soft your mask is what type of blending you're using for your landscape layers so this is great now I can go ahead grab this output here plug it directly into my foliage spawner here take a look at what we have it is now spawning my foliage inside of that landscap L wherever I have painted it so I'm actually going to increase the density somewhat in my Surface sampler maybe to3 so I have some more foliage being spawned and now I can go ahead and paint anywhere I want graph to be simulated which is pretty exciting one problem we have though is that we've lost that ability to scale these points by their distance from the center because if we take a look if I disconnect this here and we take a look at the points they're purely noisy points here I don't have any of that data of which points are on the fringes of the layer and therefore should be smaller we can still get this data because we have each of those layers separated so we know when the layers are connecting to each other so we can use that data to to get that scale data back into the point if I come to these Point filter here and I copy paste them and in my points filter here instead of grass only I type in sand I can get the points from the sand layer then I just need to right click in the empty space and make a distance node and I will plug the source into the first set of points that's sampling the grass and the target into the second set of points that's sampling the sand let's go ahead and look at that node what we're getting we don't see anything reflected in the density because we have to come back to the distance node and make sure we have set on density when we check that we should see some sort of color variation in some cases it will be so close together in terms of distance that you won't actually see it reflected so you'll need to come over here to the maximum distance in your distance node and lower it until you start to see the gradient reflected in your point now that we have this data we can come back in the blueprint node change it to scale by density again connect that up make make sure we adjust our scale Max to one and now we can see our points scaling up and down based on how far they are on the fringes of the layer and we can increase our scale Min maybe five so it's not small on the fringes maybe our scale Max two maybe increase our density exponent a little bit so now that we've adjusted our scale of our points we can add that attribute noise back in in order to be used by our foliage spawning so I'll drag off of that node and make attribute noise so that we have our noisy points I can go ahead and plug that into my foliage spawner here and now we have all of our foliage and logic working correctly so now we have PCG driven by textures and we have PCG driven by landscape layers the cool thing is that we know how to do both of those things we can combine them into a much more powerful combination what I mean by that is that if you have PCD being driven by landscape layers and you have landscape layers being driven by textures you kind of get the best of both worlds so what do I mean by that I'm going to jump back over here to the example where I was showing you Landscapes driven by maps from Gaia or World machine what we did was we took those textures separately into PCG used it to spawn the points on the surface this might be exactly what you need in some situations but if you want it to work a little more efficiently and a little more automatically what we can do is come over to our PCG graph that I have set up here and I'll go ahead and drag in that third PCG example into this volume and you'll see it works automatically and that is because when you're using textures that you export from any of these softwares these texture maps that drive the height and the placement of landscape layers what it's really doing is driving landscape layers by connecting PCG up to those landscape layers like we did in our third example we are able to paint on those layers we're able to use texture Maps it's really flexible to whatever setup you need to build and you can iterate very quickly all right I hope you found this video helpful I linked all the videos and assets that I mentioned and used below this video in the description if you like this you found it helpful in some way it illuminated some new part of Unreal Engine empowered you in your own artwork please let me know by giving me a thumbs up or a comment and let me know how you're using it if you have questions definitely drop them in the comments below I'll do my best to answer them as best I can if you are interested in some form of coaching or mentorship I'm starting a waiting list for the new year for those of you who want more personalized attention more one-on-one time with me for to teach you and really build a curriculum around you as an artist and your needs I will put a link to the waiting list to that below this video otherwise I will see you in the next one
Info
Channel: Aziel Arts
Views: 11,413
Rating: undefined out of 5
Keywords:
Id: G_uIWC6-RsM
Channel Id: undefined
Length: 28min 38sec (1718 seconds)
Published: Sat Feb 03 2024
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.