Complete Rain Shader - UE4 Materials 101 - Episode 18

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
[Music] in today's episode we're gonna put together a complete rain effect this episode is the culmination of the last five weeks worth of tutorials that we've been working on and so we're gonna take a look at the wetness that we created in episode 13 the drops that we created in episode 14 the drips that we created an episode 15 the ripples that we create an episode 16 and the puddles that we created in episode 17 we're gonna take all these elements and put them together to create a complete rain function then we're gonna be able to take that function and drop it into any other material to make it look like that material is receiving the effects of rain so let's go ahead and jump right in and get started all right so here we are in unreal and you can see that I've already dragged in the functions that we created in previous episodes I have my wetness function my puddles function my drops function and my drips function so we're gonna go ahead and combine all these together the first thing that I want to do is create a couple of default values that will represent the properties of the material that I'm applying the rain to so I'm gonna create a couple of constants this first one is a constant vector E and that's the color this represents the color of the surface that we're going to be applying our rain to and let's just make it kind of a kind of a dark gray color and I'm gonna plug that right into the base color here the next thing that I need to create is a normal and that's also of x3 but in this case we're gonna make a flat normal so I'm gonna make it 0 0 and 1 and the next thing we need is specular roughness value and so I'm just gonna go ahead and create a couple of constants for these so for specular I'm gonna make it 0.5 which is the default most commonly used specular value and for the roughness I'm just gonna make that one 0.5 as well all right so we've got a couple of default values there and now we have our wetness function and I can take this the outputs of our wetness function and plug them into the material here so I can take the base color specular and the roughness and we'll just start to get an idea for what this effect is gonna look like so right now our wetness mask defaults to zero and so it doesn't look wet at all but if I take a value of one and I plug that into our wetness mask we'll get a cube over here in our preview that looks a little bit more wet so what we're gonna be doing is using our drops our drips and our puddles to build up this wetness mask you can see my cube looks like it's a little bit wet now of course there's no effects here for for rain because we haven't added those in yet well let's go ahead and get started doing that let's start off with our drops and the first thing that we need to do is so if this were a function I would create an input but in this case I'm just gonna create a constant and this constant is 4 if it's raining or not and how hard it's raining so we're gonna give it a value of 1 which means full rain and then I need to combine the drops with the drips so here's my drips function and I'm gonna add a linear interpolate node to blend between the normals of the drops and the normals of the drips I just want to point out if you're looking at this episode for the first time and you haven't seen the previous episodes you probably want to go back and create the content that I explained in episodes 13 through 17 so that you'll have these functions drop strips puddles and wetness okay so we're blending between the normals of drops and drips and we're gonna use the drips mask determine which of these we're gonna want again we also want to take our how hard it's raining and plug that into our drips function all right so we have we're blending between our drops normal and our drips normal and now we actually need to combine that with our normal coming in from outside from our surface and so I'm gonna add a new node here that's called blend angle correct normals this is going to blend our base normal from our outside material with the normal from our drops and our drips so this normal that comes out of here is a combination of these two and now we need to blend depending on if our surface is part of the drops and the drips or not we need to blend between our combined normal and our outside normal so I'm going to add another linear interpolate node and our combined normal is what will get if we've got rain and our surface normal is what will get if there is no rain now I need to take the mask for where the drops are appearing and I need to add it to the math where the drips are appearing so these two masks added together and then I need to saturate them so they don't go above one all right so this is how we're gonna determine when to use our regular normal and when to use our reign normal so here's our reign number normal and B and our standard normal and a and we're gonna mask that using our drops mask and our drips mask and I'll just rearrange the nodes here and clean things up just a little bit okay so we're making good progress now we need to hook up our puddles so the puddles node has a normal input so I'm gonna pass our normal input into that and it also needs values for wind rain and puddles so we already have a rain value over here so I'm going to pass that in but we also need an input for how much wind there is and I'm just gonna give it full wind for now and we need another input for how large the puddles have grown and I'm also gonna give that a full input okay so now that we've got drops drips and puddles combined I can take the resulting normal and pass that right into our normal socket and it's giving me an error saying that I don't have this value for porousness so I need to go ahead and generate that in order to create porousness we need to know like how absorbent or in absorbent the material is now ideally you would paint a texture map that determined like this part of the surface is porous and this part of the surface is impermeable but in our case instead of using dedicated texture for that we're just going to take our roughness and our men our metalness and we're gonna kind of derive a map from that so so here is our roughness value and I'm gonna add a power node and raise this to a power of five and this is just gonna adjust the contrast on my roughness and then I'm gonna add a new input for how metallic the surface is and in this case again I'm just going to be using constants but eventually when I make this into a function I'm gonna replace these constants with inputs so this is my metallic and I'm going to inverse this so I'll add a one - note - inverse to invert my metallic value and then I'm going to multiply these two values together and this is the value that I'm gonna use for how porous the surface is so I can plug my porous value that I've generated based on my roughness in my metalness we're gonna plug that into the porousness value here on my wetness node and I'm also gonna plug this into the porousness value here on my trips node all right so we've got a shader that's working and you can see that it's actually doing something that looks good so I'm gonna zoom in here and you can see that now I've got rain drips on the top and raindrops running down the side so that's pretty cool getting close to being done but I'm not quite there because I still have to create this wetness mask so what I'm gonna do is I'm gonna take the mask coming out of my puddles and I'm gonna combine it with the other masks that already have so I'm gonna create a max so whichever is greater the puddle mask or the combination of the drops and drips mask so I'm gonna combine these two maps together with a max node and then I'm gonna add a saturate [Music] and now the last thing that I want to do right now my wetness is only coming from where my puddles are where my drops are and where my drips are and what I actually want to do is make it so that my object as a whole can just be wet aside from drops trips and puddles that can just have wet parts of it and so I'm gonna add a new constant node and this one is gonna determine like this is kind of like how long it's been raining so when rain starts everything starts out dry and then after it's been raining for a few seconds everything just has a general overall amount of wetness and so that's what this is gonna represent and again I'm just going to give this a value of one for now but when we turn it into a function I'm gonna replace this with a value that we can use to control that all right so now I'm gonna add a saturate node and now I'm gonna multiply by seven and the reason that I'm doing this is even though my overall wetness goes to one I don't want any part of the object to have an ambient amount of wetness of more than 0.7 so I'm gonna add this multiply here and multiply by 0.7 now I'm going to take this overall wetness value and add it in right here so I'm going to do an ADD node I'm gonna add my overall wetness with the wetness mask from my drop strips and puddles and once again I'm gonna saturate it to make sure that this value never goes above one and then this is gonna become my new wetness mask so I've combined the masks of my drops drips puddles and ambient here and so wherever there are drops drips puddles or just general wetness that's where the wetness is gonna show up all right so we're looking pretty good now one thing that you'll notice is that I'm not seeing any puddles here and that's because the scale of my puddles is such that it's not lining up in world space with the location of my cube here but once we apply this to the scene you'll see that that that we actually do have puddles okay I'm just gonna do a little bit of off-screen clean up and I'm gonna convert this into a function and I'll be right back to show you what I did all right so here's our rain function and this is doing exactly what I just walked you through only this time it's a function instead of plugging into a root node over here on the right I have output nodes so I have output for roughness specular base color and normal so here's my wetness function and I'm passing into it the base color of my material the specular of my material the roughness of my material and the metallic of my material I'm combining roughness and metallic to create a porousness mask or how permeable the surface is I'm also having an input here for wetness which is how wet everything is in general and you can see again I'm multiplying that by 0.7 then I have my drops my drips and I'm combining the normals of those that I'm combining the masks of those I'm also combining the normals of the drops and drips with my external normal the normal of my material then I have my wind input my puddles input and I'm bringing the normal from outside into the puddles function and then the puddles function passes out a normal and also a mask of its own and here I'm combining the drops drips puddle mask with the wetness with the ambient wetness and then passing that into wetness as the wet masks so this is the function and if I take this function and drop it into any other material you'll be able to see how I'm taking the materials properties passing it through the rain function and then getting the result of something that looks wet now before we take this function and start adding it into materials there's one more thing that I want to say regarding performance this is probably the most expensive version of this function that you're going to want to create if we jump back here to our demo material you can see that we're using two hundred and thirty four instructions which is not exactly a cheap shader so what you'll want to do is create different versions of this combined function depending on what type of an object you're applying the rain to so for example if I were going to apply this shader to a floor material I would definitely want to make sure that I had up had puddles but I do not need drips because drips are dripping down the sides of things then a floor is not going to have sides conversely if I were applying this rain effect to a prop I know that props are not going to have large flat surfaces and so I wouldn't need the puddles but I would need the drops on the drip so you're gonna want to create several different versions of this weather rain function depending on which types of surfaces you're going to be applying it to and remove the effects that don't necessarily apply so that you'll be able to get the best performance so let's go ahead and take a look at a material so here's a material that ships with unreal it's called M wood oak and it's a pretty simple straightforward Tyrael you can see that it has base color roughness and normal input values and I went ahead and made a copy of this material and added my rain function to it so you can see I have my base color my roughness and my normal materials here's the rain function that we just created and I'm passing in our values for wind rain wet and puddles and you can see that whereas my Oakwood looked really dry before now it has raindrops on the top it has rain drips running down the sides and if it were large enough I'd be able to see puddles but in this case I can't see puddles but anyway so you can see that I've just taken my function and put it into my material and now I'm able to make my material look wet now what I really need to do is take these values here that control the wind rain wetness and puddles and I need to hook them up to my game using blueprint and there are lots of tutorials out there that talk about blueprint and how to bring values in from outside the shader that's a little bit beyond the scope of what I want my channel to do because this is focused specifically on the material editor but I will put a couple of links down in the description that go to tutorials showing you how to set up blueprints because what you'd want to do is you'd want to create the logic in your game that controls the rainstorm so when it starts to rain you might make the win and get a little bit stronger you make the rain start at zero but then kind of slowly ramp its way up to one as the rain continued you'd want it to get wet and then you'd want to slowly make the puddles grow over time so these are all values that you can pass in from outside the shader using blueprint and again I'm not going to go over that in this tutorial but I will put some links in the description for how to setup blueprints and control shader parameters using blueprint alright so let's go ahead and take a look at what a scene looks like when you add all of the when you add the rain function to all of the materials so here's the default scene that comes with a simple default level of unreal and what I've done is I've added the chair material the table material and this metal material that's on the floor so that all of these have the rain function in them and you can see that I've got a pretty nice-looking rain effect so here the raindrops on the table a little bit of a puddle over here a nice puddle over here on the ground and you can see that the chair has raindrops and it has rain drips running down the side now from here what I'm gonna want to do is tweak things you can notice maybe that these raindrops are a little bit too large maybe the ripples are a little bit too large you know I can go into each of the functions that I've created and adjust the scale and the size of these things so that they give me the exact effect that I'm looking for but I think that what you'll see is overall we have a pretty nice system for imitating the effects of rain that's exactly what we're going for so what we've seen is a combination of episodes 13 through 17 with wetness drops drips ripples and puddles and I hope this series of videos has helped you see what is possible to do with a shader and unreal you know a lot of people just make a shader that just has a normal map and a base color map and maybe a roughness map and and call it good but there's so much more that you can do with shaders and it's really cool so I hope the tape that you'll take the time to learn how to do these kinds of things so that you'll be able to achieve some amazing effects in your games and be sure to subscribe to the channel and tune in next week where we'll start taking a look at another really cool shader thanks everybody [Music]
Info
Channel: Ben Cloward
Views: 12,238
Rating: undefined out of 5
Keywords: UE4, Unreal, Unreal Engine, shader, material, material editor, game development, real-time, tutorial, training, Unity, graphics, 3d, GPU, tech art, computer graphics, fundamentals, basics, beginning, learning, rain, water, ripples, puddle, drops, drips, wet, wetness
Id: tUemJLSaFxw
Channel Id: undefined
Length: 21min 40sec (1300 seconds)
Published: Thu Mar 19 2020
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.