UE4 Interactive Foliage Tutorial UE5

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
welcome back everyone to another video and in today's episode we will create somewhat of an interactive foliage so as you can see over here i have this sphere i have this grass right here and if we move this around you can see that the grass is trying to bend away from this sphere also it works for character it's not that great for the character but as you can see it still does try to move away a little bit it's not perfect but this is as close as i can get it to work so yeah let's go ahead and let's get started [Music] so i have a little bit of foliage already painted over here in this level this is the grass from the june's free assets so i've used the stylized forests meshes plants the sm grass01 so this guy right here but before we can begin we need to enable one of the settings in our project project settings so go ahead go to the settings project settings and look for the mesh and scroll down until you find the engine lighting now engine rendering and then there's a section called lighting and the first thing is generate mesh distance fields so you need to enable this and once you will for unreal engine 4 it's going to ask you to restart this for unreal engine 5 this is enabled already by default at least at the point while when i'm recording this it was enabled already on engine 5. so once you do that the engine will restart and then it's going to build these distances and once it's done go to your model or look for its material so we're going to look for this one so we have the grass instance obviously the instance is not going to do the trick we need the actual material so look for the parent from which this instance is created and we're going to do some adjustments in that one so this is the main material used for this model right here and go ahead find the world position offset pin and just follow it so that you can move these nodes aside so these nodes right here are used for the wind so you can actually see this over here so symbol simple grass wind this is where and how it gets generated we're also going to use this but for now we're going to move this aside so that we can implement our changes so uh let's go ahead let's get started so the first thing that we need to do is we need to look for a node called distance from uh distance to distance to nearest surface so this is going to help us know when some kind of an object is close to the grass to make it bend and over here what we want to do is we want to subtract subtract and then whenever we subtract we need to specify an amount that we want to subtract so i'm going to make this into a scalar parameter and uh let's give this a value of 20. so this is going to be default value is going to be 20 and we're going to call this radius because this is essentially the radius so how far away from the mesh the things start to bend so i'm going to use radius of 20. obviously you can adjust this the bigger you make this the further away the grass will bend from from objects basically so then from the subtract we want to do one minus and once we have done that we want to make sure that we clamp this value so it doesn't go too high or too low we want to keep this within 0 and 1. now that we have done that the next thing that we want to do is we want to look for another node called distance distance field gradient to smooth out this uh this motion of the grass basically so that the bends are not too sharp otherwise it's it's not going to look that great so once we have got this node we want to multiply these two together so i'm going to hold m and click it's going to give me the multiply node and we're going to multiply these values basically together now that we have done that we need to multiply this a little more so another multiply node and we want to multiply this with again with another scalar and this is going to be like the strength of this so how much the grass actually bends so i'm just going to call this power or strength whatever let's plug that into our b route and let's give this some value now the value should be within the couple of uh first thousands so i'm going to make mine something like 2 000 1000 isn't going to be a lot 2000 is going to be a little bit more obviously don't go too high don't go too low but just experiment with with this value a little bit so if you want it to move more give it more if you want it less give it less now the next thing that we need to do is we need to get the vertex normals so right click let's look for vertex uh normal vs so world space and then from here again we can uh not again but this time we need to add instead of multiply so we're going to combine these together so it's going to give us the world space and it's going to give us the calculations that it's made for how far it needs to bend and then it's going to basically know the position where it should be and then we can clamp this so it doesn't go too wild just in case and i'm going to give this some kind of values let's say from -20 not 200 so minus 20 up until 20 so that's the radius in which it can actually bend just in case if it calculates something more or less so it doesn't look too awkward we're gonna just keep it in check so uh and that's basically it now we need to combine these two together so that we have the wind and so that we have the motion so what i'm gonna do is just simply add both of these together so we're going to add our calculations so if you don't have the wind this can go directly into the world position offset if you have wind and you want to use it just combine these two together and then this value can go inside of our world position offset now each time we make some changes to the material it's going to take its time it's going to be a little bit longer than usual to basically save and apply everything and also every time it's going to require you to recompile the shaders for this specific model so this is going to take a couple of seconds so as you can see it's compiling shaders it doesn't see the grass so we're going to wait a couple of seconds it's going to do that meanwhile oh it's already done let's go ahead and let's bring in some kind of a shape so i'm going to bring in a sphere move it up a little bit and now you will see real time whenever i move this that the grass is bending away from this model the wind still works and it's bending nicely away so obviously at this point of course we can make it as big as we want i'm going to make a couple of these just so they're on top of each other like this scale a couple of them down maybe like so and also i'm going to enable physics for all of these so that they would drop down and we would see this nice effect when we hit play so there we go we can move this and the grass moves with it now unfortunately as you can see it does not move with my character and there is another problem the grass is floating so first let's fix the floating part so the issue with that is the fact that well there is a surface over here so it's the same for landscape it's the same for meshes in this case obviously i'm using a mesh but it's it doesn't matter so there is a surface over here and it is detecting it and so it is moving away from this as you can see here are the actual mesh and here is the visual part of it so what we want to do is we want to select that mesh or landscape go to the details scroll down till we find the lighting then for you by default it will look like this so check click on this show advanced scroll down a little bit until you see the effect distance field lighting so whenever you will click that to false you can see it instantly drops to the ground and it no longer detects the the ground basically it only will detect the models that have this enabled which is basically every model because all of them will have this enabled by default now it does not detect our character as you can see so for that we're gonna make a small cheat we're gonna add basically a sphere to our character to the feet of our character well more so to the capsule of our character which is then going to uh bend this grass away from us so what we need to do is first we obviously we want to make this invisible so that we can't really see it so let's go ahead and let's create ourselves a invisible material so let's invisible matte let's open this up what i'm going to do is basically click one and one called one and click twice we're gonna give this some kind of a color zero should be black and then the opacity also needs to be zero so that it is transparent but by default we don't have the opacity so select the base node scroll down until you find the blend mode and make this translucent now we have the opacity so we can save that and the material is good to go there we go so the material is invisible that's all good let's go ahead let's open up our character now and inside of our character let's go ahead and let's add ourselves a sphere and let's make sure that this sphere right here uses the invisible material so that well this sphere is not visible here we go we have the sphere let's move it down maybe let's make this a little bit smaller something like this perhaps obviously totally depends you might have to scale this up or down based on your preferences and then let's scroll this down and let's make sure that we have no collision for this there we go let's hit play and now you can see that the grass is moving but i think it's a little too small so maybe maybe i scaled this down too much so maybe the default size would work just fine and now it seems a little bit too much so obviously you can experiment with this you might maybe want to use two instead of one perhaps so it totally depends on the settings you applied to this so now as you can see it is a little bit better obviously you will still have to experiment with the values uh you can make the sphere bigger obviously you can make the uh the radius is bigger smaller the power more or less so all of these things are still adjustable uh it's totally up to you how you decide to adjust this but yeah i think this is pretty cool uh we can do all kinds of cool things with it it looks amazing it does bend our grass away so that's exactly what we wanted so yeah that's gonna be it for today's video hope you found this useful if you did make sure to subscribe i upload twice a week uh yeah see you in the next one
Info
Channel: It's Me Bro
Views: 34,730
Rating: undefined out of 5
Keywords: ue4, interactive, foliage, ue5, tutorial, world, position, offset, bend, character, affect
Id: qQmQDWOACo0
Channel Id: undefined
Length: 11min 11sec (671 seconds)
Published: Mon Jun 14 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.