Distance Fields (Part 1) | 5-Minute Materials [UE4/UE5]

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
[Music] off my seat please that's where i sit excuse me excuse me here you go hello and welcome back to five minute materials the show where we demystify every node in the unreal engine material graph today we are here to look at distance fields so what is a distance field well if we go into our scene up here where it says show we can hit that we're going to go to visualize and we're going to click on mesh distance fields so now what we have here looks kind of spooky what we are looking at are some raycasts that are done offline and they basically say how close are we to a surface so if we were to grab this windmill and we'll just chuck it way up in the sky little darling this is just a visual representation of you know where the distance fields are and how accurate they are to the mesh so what can these actually be used for today we're going to be talking about how materials can interact with distance fields so let's just go ahead and grab a cube fantastic and we're going to create a new material we're going to pop that material onto the cube and we're going to open up this material i'm going to put its base color to zero for now and also it's specular down to zero we now have a black cube fantastic the node we're going to be looking at is called distance to nearest surface you don't have to plug anything into it although depending on what you're doing you might want to use world position excluding material offsets but if we were to just plug this into the base color then you can see nothing useful is coming out of this right and the reason this is happening is because this cube itself is emitting a distance field so any material that is using distance fields in its shader calculation more often than not you don't want it to be emitting a distance field so let's go into here we're going to go effect distance field lighting untick that and now our tube is completely white now the reason this cube is completely white is because it is more than one centimeter away from a distance field so what we're going to do is this distance near a surface we're going to divide it by a number so this means that the gradient from black to white is going to be as large as whatever we divide it by we want the gradient from black to white to be 100 units big instead of being a single unit big and now as we move this down you can see that the color changes from black being it's zero units away from a distance field to white meaning it is a hundred or more units away from a distance field so more often than not what you're going to want to do with this is to saturate it and one minus so now our cube is black by default and it becomes white as it approaches a distance field so your imagination is probably racing at this point thinking okay well uh what can i possibly use this for well what do we usually use a black and white mask for you may ask alert let's go to alert and we're going to put this mask into the alpha and we can just you know use two colors or something and yeah this is doing exactly what we'd expect it to do it's lurping between green and purple using the distance field you pee so this is still pretty useless arguably so what if we were to do something like add time then put it through a sine wave and then put that into the base color okay well now we have this sort of radiating [Music] effect coming from a distance field to prevent this part here from flashing white we can just multiply the result from the sine wave by the initial mask and so that's going to say okay do this radiating effect except the bit that was usually black we're going to keep it black so now we have this if we wanted to make more bands we could multiply before the sign so if we say multiply by five then there's going to be five bands and if we wanted to slow it down we could say divide time by let's just say three so this will be three times slower now so when i look at this first thing i think of is ripples in water imagine that this pier is our landscape and we have these ripples you know doing their thing i actually use this already in my water shader if we were to exaggerate this effect by going into the material instance and turning the refraction of the ripples up then you can see very clearly that we're using distance fields to create ripples in the water from the shore so you know we can move this anywhere so we could take this water plane we could put it over this bridge and wherever the bridge intersects with the water it's going to create ripples you can actually see in my river material i create turbulence around distance fields and also create foam and i also do some stuff so that things behind the flow of water build up and then in front of the water it dips down a bit another really wacky thing we could do is use this gradient to kind of displace this mesh so if we were to say uh maybe a distance of like 50 and if we were to get the vertex normal world space of this mesh and we'll mask it in the r and g so it isn't the up and down null uh and then what we could do is multiply it by a number and then multiply it by the result here so you might be able to guess what this is going to do essentially what we've created now is like a blob right so as it as it comes down to the ground it just blobs outwards uh you know we can you know you could use this for like your slimes or something i guess and so you know this is pretty whack uh and it looks kind of weird but essentially this is how uh this is how metabols are created um if we were to not mask the r and the g and just do all directions then you'll see that this tends to i guess like engulf anything that it comes near so it's it's fun and i'm sure that you could find a you know a way to implement this in your game so basically to recap a distance field is a field of distance around an object that a material can read from by dividing the distance to nearest surface by any number you can increase the gradient from zero to one the length of it if you then one minus that it will flip it around so that it's white near the distance field and black when it's away from it which is usually more useful in most cases and then after that you are free to do whatever you want with it so what i'd suggest is plugging it into the base color to make sure that it's kind of doing what you want it to do and like reacting to the distance fields however you want it to and then after you've visualized how it's interacting just go nuts do some wacky stuff with it so if you enjoyed today's video and you want to help out these tutorials and stuff the best thing that you can do is to like the video and subscribe to the channel and if you want to stay up to date with all the future videos whenever they come out make sure you click that little bell icon thingo because youtube and algorithm and then blah blah blah blah if you have any questions at all about materials or animation or just unreal engine development in general feel free to join our discord it's a very friendly place if you've got questions that you think are like really dumb and you're afraid you're going to be laughed at you don't have to worry about it whatsoever everyone there is super friendly if you do want to go the extra mile in supporting this youtube channel and these tutorials you can subscribe to our patreon below for as little as one dollar per month so with that i say goodbye goodbye [Music] [Music]
Info
Channel: PrismaticaDev
Views: 105,029
Rating: undefined out of 5
Keywords: ue4 distance fields, unreal engine distance field shadows, unreal engine distance field ambient occlusion, unreal engine distance field, ue5 distance field, ue5 generate mesh distance fields, ue4 distance field ambient occlusion, ue4 distance field shadows, ue4 distance field ao, ue4 water ripples, ue4 slime shader, ue4 ripple material, ue4 ripple effect, ue4 blob, ue4 slime effect, ue4 water material, ue4 water tutorial, ue4 water ripple material, ue4 water interaction
Id: yzvq8aonDYQ
Channel Id: undefined
Length: 9min 20sec (560 seconds)
Published: Mon Jul 12 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.