Unreal Engine 5.2 PCG Tutorial - Sampling Landscape Auto Materials

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hey everyone I've got a pretty basic landscape here I have set up an auto material on it that calculates whether or not it's a cliff and based on the height it'll either spawn snow or sand and then based on whether or not it's snow or sand I'm going to spawn these rocks or these clear statues and I've also added in a painted layer that I can use for a road and if you follow my previous tutorial you'll learn how to uh treat the painted layer to either you know create edges for it or whatever else you want to do with a painted layer and so this creates a very quick very convenient effect that you can use to very very quickly populate landscapes so if you just paint out here you get some pretty quick new landscape data and it as you can see just updates on the Fly based on what you've done with the land so uh yeah let me show you how to do it all right I've sculpted up a basic New World let me create the material material M underscore Auto material and I'm going to just whip this up pretty quickly start with the texture sample and make four copies of that three will be the Autumn material and one will be a painted layer all right so the first one sandstone second one is going to be sand third one is going to be snow and last one is going to be concrete and let me add a little scaling to this I'll take the texture coordinate and just multiply it by 0.01 so it doesn't have some extreme tiling just plug those into the UVs all right and now a landscape layer blend I'm going to have two layers the first one is going to be Auto second one is going to be concrete and I'll plug concrete into concrete and auto I need to calculate so for Auto I'm going to start off with a world aligned blend and this will let me create the cliff I'll just toss up to scalars 15 is going to be sharpness and negative 5 is going to be biased just hook them straight on up since I'm just whipping this up for demo purposes I'm not going to worry about making these parameters and now the alpha is going to connect to a linear interpolate a lerp node and I'll hook that up to Alpha and so the closer it is to zero the more a is going to get and that's going to be my sandstone and then I can hook that up to the auto layer and now I need to determine if it is sand or snow so for that I will add a world position coordinate and I'm going to calculate based on the Z first I will subtract a scalar that's going to be the height where the difference happens and I'll say 3 500. and now I'll clamp it from zero to one so if it's below 3 500 it's going to be zero and now I'll calculate the blending range so all I have to do for that is divide this number which goes from 3500 on up by 500 then 0 to 1 will be the equivalent of 3 500 to 4000 and I can clamp it at one and this is the lerp for this one and so the closer it is to zero the more it is sand and the closer it is to one the more it is snow and I can just hook that right up here and hook this on up and if I apply this to the landscape M underscore Auto material let's go into the paint tool shift 2 to pull up the landscape menu and auto and concrete need layer info so let me just create a weight Blended layer for each of them white Blended layer for concrete and there we go we've got our snow we've got our sand uh Sandstone it's hard to tell because it's extremely bright right now but let me quickly paint a little bit here uh yeah 0.5 works painted some concrete on down and let's fix this shininess so I'm going to create two more scalars just hold down one and left click and metallic I'm going to make a zero and roughness I'm going to make one and I think I selected the wrong texture for sandstone there we go Canyon Sandstone is what I want there that's a little more visible okay great so we've got our sand our Sandstone our snow and our concrete so next let's apply physical material and that's what we're going to sample so for that physical material output and I'll have four values one for each type and now I need to create a physical material and before I create a physical material I need to update the physics project settings and add an entry for each different physical material so I'll have sandstone sand snow and concrete close that and I can create my physical materials let's go into PCG Auto material and I'm going to right click go to physics physical material Select Physical material and hit OK first one BPM Sandstone duplicate that PM underscore snow look at that pretty much sand and duplicate that for PM underscore concrete you can open each one of them up and now I'll select my Surface type that I just created in the project settings and I'm just going to match the tab headers here so Sandstone sand and the last one is going to be concrete and now for the physical material I'll select PM unders sandstone okay monitors or sand be underscore snow and PM underscore concrete okay so now I need to assign these physical materials so concrete is going to be easy I'll select landscape layer sample and set it to concrete and this will just return a value from 0 to 1 based on how much concrete is painted on the on the position for the other one I'm going to select auto but Auto splits into one of three different properties so for that I need to basically rebuild this lerp logic so if I take the world aligned blend which is creating my Cliff face the closer it is to zero the more a it is and a is my value that I'm using for Sandstone so if I lurp from 1 to 0 based on Alpha I get my Sandstone value and then I just have to multiply that by Auto to combine its to combine its weight with concrete and I've got sandstone and let me just name this one right here sandstone and I'm going to take this and reverse it so a0 B1 hook up the alpha and this will be not Sandstone so not Sandstone is going to plug into snow versus sand and it will use the same lerp from the absolute World position so I need two of these one for snow one for sand and sand the closer this value is to a the more it's sand so I'll go from one to zero for sand and to name this sand and zero to one will be snow and I apologize for the ugliness and disorganization here so if it is sand I multiply it by not sandstone and then I multiply that by Auto and that's going to be my weight of sand this isn't perfect concrete actually gets weighted a little over what it should be but it's going to be close enough for these purposes and if you want any more details on how to create physical materials and auto layers you should look up another tutorial that's focused on those because they will go into far greater detail and give you a far better result than what this is giving you all right so I should have my physical materials now let's create a tool to test that blueprint actor BP underscore debug phys Matt and open it up for this I'm just going to go into the construction script and this will be just pretty quick and dirty I'm going to do a line Trace by Channel and we'll actually use the Slime Trace by channel for the PCG graph but for now we're just doing some testing stuff with it get actor location is going to be the start and end of the Slime Trace for the start I'm going to add let's say 10 000 just to make it ridiculously big and for the end I'm going to subtract 10 000. Trace Channel I suggest setting it to camera it seems to work a bit better in the editor and let's draw some debug lines for the duration out hits going to get the surface type and cast it to a string and then I'm going to just do a print string and that's all we need for debug purposes compile save drag it out into the world and we see sand concrete sandstone and snow so that's exactly what we want to see you can go ahead and delete this and we're done with that debug tool next let's go ahead and create the PCG graph BCG Auto material open that up and a blueprint BP underscore Fizz material and for this I'm going to add a spline and a PCG spline I'm going to go ahead and expand it a little bit and let's move this a little off of Center and make it a closed loop the PCG let me go ahead and select that PCG underscore Auto material compile save and I should be able to drag this out into the world let's uh go right here we should see all the materials right here I can make it a little tiny bit bigger there we go okay now let's go into the PCG we're going to get spline data and I'll have it set to actor filter itself the spline and the PCG are in the same blueprint so this will find the spline spline sampler and I'm going to set the spline sampler distance on interior and the interior sample spacing let's set it up a little bit for development purposes and now I can do a projection node I'll project the landscape to it line all that up and here is where I'm going to sample the physical material so I need a new note for that blueprint all classes p2g blueprint elements I'll call this pcgb underscore Fizz mat and now I can open this up all right I'm going to first override the node title and I'm going to call this Fizz Matt and now I'm going to expose to the library and set the category at custom description get the physical material and there we go now I'll update the execute with context I'm going to first promote context to a variable I'll just call it context and hook that up now I'm going to break the input and add a for each Loop hook that on up break the PCG tagged data from the for each Loop and when it's completed I'm going to do this return node the PCG tagged data I will cast to PCG spatial data and the PCG spatial data will be two point Theta with context hook the context up and this is going to go into a Point Loop with another reference to context here and then the Point Loop is going to go out into a piece G tagged data let's make an array I'll promote this array to variable and delete that and now I'm going to take this array and add this value to the array and let's rename this array piece G tagged data and now on the return node I'll take this PCG tagged data and I will make a PCG data collection and I'll pass that out in the return node okay and we've got our execute with context so let's create a Point Loop all right for the Point Loop I'm going to promote points to a local variable I'll call it point and let me hook it on up and promote the metadata to a local variable meta data and hook that on up to now I will take points and I will break it I only want the transform I don't need all the rest of these properties so I'm just going into break PCG point and unselecting everything here and let me break the transform and for location I will add and subtract from location just like I did in the debug node and here I will do a line Trace by Channel hook that on up and the start will be adding from the location and subtracting from the location and instead of Simply adding values to the Z axis I'm going to rotate a vector and that Vector is going to be 0 0 1. and I'm going to rotate it by the rotation and then this I will multiply by a float convert this to float and let's just do 500 so I'll add 500 to the start and subtract 500 from the end and this means that if the point has been projected onto the landscape and rotated it will still Point straight into the landscape which I find makes it a little more accurate in some strange edge cases all right draw debug type let's start off with drawing the debug type and set the visibility the trace channel to camera the out hits I'm going to get surface type and make this a string and the string I'm going to add into metadata I'm going to set string attribute to this return value attribute name is going to B is matte the point is going to be point and I'll hook this on up set the out point to point as well align these on up and check return value and now I need to actually go and create the metadata so back in the execute with context after two points data with context I'm going to add mutable metadata and I'm going to create a string on that mutable metadata and that's going to be called Fizz at and I need to hook all of this up so let me move all of this over a little bit and I'll add a sequence node here and first I will hook up the mutable metadata and then I'll hook up the Point Loop okay and now this should be getting me the values that I need let's find out I've got my fismet graph in here and if I inspect this and select fifth material fismet concrete Sandstone snow perfect that's exactly what I want to see and if I move this we should see the line traces there we go next let's add some stuff to this thing based on that so I'm going to do a point filter and if Fizz mat is equal to constant threshold string let's say if it's equal to sand let's do one thing and pipe the outside filter in for things that aren't equal to sand and this will be snow and I'll just ignore cliff and for now I'll also ignore concrete so let's see if it's equal to sand let's do a static mesh spawner and I'm going to select mesh entry Rock and for the snow let me select the mesh entry statue all right we got some statues but they're very tiny so let's make them a little larger I'll just add a transform points hook that up in here and add a transform points here and hook them up here the Rocks let's just uh make sure their uniform scale and set them from say two to four these things 10 to 15 for the statues and let's see what we got okay the statues are more visible similar says to the Rocks excellent and I can expand this tiny bit and you'll notice something's weird it's happening every other time and I can just drag this over here and I'll click the force regen button gone first region it's there so what's happening is every other region this Trace is colliding with these statues and I can tell you right now that it's not colliding with the Rocks because the Rocks don't actually have an equilision this is a new project if I went to the Rock static mesh and I just do that now starter content props SM Rock and I'll just uh generate a simple Collision here and save and back under here now if I reach in they're alternating oh that's excellent okay so how do I fix this well let's add a little more debugging into the PCG blueprint Point Loop body I'm going to take the out hit and break it and I'll expand the break hit result and under hit actor I'm going to find the name and I find that the object path string gives me the most information and now I'm going to log string and I'll just drop this into the loop compile save and so now if I open the output log let's see what we've got landscape streaming proxy that's what I want to be hitting but here we go BP underscore Fizz material so it's hitting itself and the objects that it's hitting are tagged as BP Fizz material so to fix this what I'm going to do is add actors to ignore so let's do that now let me get rid of this logging it's told me what I need to know so let's uh promote this to a variable I'll just leave it named actors to ignore compile and let's add an actor I can't because uh it's not letting me do it in a class itself I could do it if I create it as a variable and set it once it was in the world but it won't let me create it from the blueprint itself but I can actually handle that in a slightly different way I'm going to add an ignore list variable type actor but actor is going to be a class reference and let me change this to an array and now if I compile this I can add my class references like BP underscore Fizz material a couple others you might want to add are static mesh PCG volume and I've even found uh instanced foliage actor can also cause problems when you've painted foliage the trace will impact that as well so now I've got these I need to do something with these ignore list values so back in the execute with context I'll just do it once for the whole node and I can do it right here so let's move this return node down here and drag the ignore list in I'm going to do for each loop on the ignore list and now I can create a sequence to pipe up to the for each Loop zero will be the for each Loop and one will be once it's completed so I'm going to run through the ignore list and I will get all actors of class which gives me another array this I'm going to do another for each Loop and that gives me my individual actors I want to ignore so I can simply add to this array and that is going to provide me my ignore list compile save and we've got the stuff we want if I click on Regen it still works okay so now we've got everything working so let me turn off this debug turn off the draw debug type to none file save and let me show you how to add in the road close all of this stuff that I don't need anymore and open up the auto material as for the road we have a projection node earlier on in this graph so we have the layer data and so we see here concrete is populated as well as Auto so what I'm going to do is break this point filter and add another Point filter because the concrete data is more accurate than the physical material because concrete can go uh on a gradient between zero and one whereas the physical material is just yes it's concrete yes it's sand it's it's just a fixed value so now I'll say if concrete constant threshold is greater than say float 0.5 we'll do something with that otherwise we'll go here and now a static mesh spawner and let's just add let's add some bushes to the road save and there we go we got our little bits of bushes on the road and if I expand that everything is Auto populating let me just crank this down a little bit more make it two thousand and if I draw on this landscape if I sculpt everything now I can crank it up I can flatten it and I've got these things populating on the flattened landscape and there we go so I hope you do some interesting things with it it definitely is a huge Time Saver it gets you really close to where you need to go and then you can tweak from there all right enjoy
Info
Channel: Michael Royalty
Views: 11,926
Rating: undefined out of 5
Keywords:
Id: dZ6FaD6CQOo
Channel Id: undefined
Length: 29min 45sec (1785 seconds)
Published: Fri Jul 28 2023
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.