Foliage Normals - UE4 Materials 101 - Episode 33

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
[Music] today we're gonna go over or different methods for creating normals for foliage normals on foliage needs special treatment this is because the foliage is made out of flat plains but the plains actually represent a volume of foliage so we don't want them to act like Plains at all two weeks ago we talked about animating the individual leaves so that they don't move like planes and last week we talked about fading out the plains so you don't see them at glancing angles this week we're going to talk about adjusting the normals of the planes so that they don't light like planes either I guess you can see we're going to great lengths to hide the fact that we're using planes for foliage so our four methods for foliage normals are number one Faith's normals number two bent normals number three object pivot normals and number four camera normals we're gonna go over how to create each of these types of normals and talked a little bit about the positives and negatives for each and then at the end if you stick around we might just throw in one more way to create foliage normals for good measure so first we're gonna talk about face normals before we begin there are two changes that I want to make that are gonna make visualizing our normals a little bit easier first of all we have a skylight in our scene that kind of illuminates everything uniformly and so I'm gonna turn this off so that we can tell our directional lights a little bit more clearly the other thing that I'm gonna do is turn off our really nice foliage subsurface scattering translucence at the translucency that we added a couple of weeks ago so I'm just gonna switch over here to our shader and disconnect our subsurface color and what you're gonna see is that the directional light source on our leaves is going to be a lot stronger now we'll make it easier for us to tell when we've made changes that improve the lighting so let's talk about face normals face normals are what you'd get by default when you build your foliage from flat plains the vertex normals point straight in the direction that the planes are facing and although these normals are correct for the plains they actually light really poorly now on this particular tree mesh we actually have the second kind of normals that we're going to talk about we have vent normals and so in order to simulate what face normals are gonna look like we need to make a couple of changes in the shader and this is not something that I recommend that you do I'm just gonna use this technique so that I can show you what face normals look like without actually having to go back and change my geometry and re-export my tree so this is the bit that we did last week that creates a face normal and what I'm gonna do is this normal is in world space and so I need to add a vector transform node and I need to transform it from world space to tangent space so I'm gonna come over here and set the source to world and the destination to tangent and then just like we did with our tangent space normal map here I need to multiply this normal by our two-sided sine node so that we get the normals flipped in the right direction on the back faces and now I happen to know that this is gonna give us a normal that's inverted and so I need to actually multiply it by negative one to flip it and this is gonna give us our proper face normal so that's why R this into our normal socket and take a look at what we get all right so right away you can see that our lighting is kind of modely like there isn't a definite direction to our lighting we have some branches on this side that should be the lit side that are actually black now one method that I like to use for visualizing my normals is I like to use this menu here and switch to buffer visualizations old normal and this is going to show us actually what our normal looks like with the vector itself visualized as a color and I have this sphere over here because this sphere has actually correct normals for the directions of the phases of the sphere and so we can compare that sphere with our tree here can you see how I have these large areas of various different colors that are just kind of chunky looking well that chunkiness is gonna end up in our lighting and that's not what we want so if you create a tree with flat planes you need to go in and do something with the normals of the planes if you just leave them at their default settings what you're gonna end up with is this really chunky looking lighting where some of the planes are dark and some of them are light and it just doesn't seem to light correctly at all so the first type of normals our face normals are what we're trying to avoid now in this case like I said we already have bent normals on our tree and I'm just simulating them by using this d DX D dy method to give us explicit face normals but I'm not recommending that you actually do this alright let's talk about bent normals so if we switch over here to the view of our mesh you can see that we have our tree mesh here and I have the normals toggled on so they're actually visualized as lines that's what all these little green lines are if we zoom in here you can see at the ends of the branches there are these little green lines that are pointed outward in kind of facing away from the center of the tree this is what we call bent normals now the way that you do this in your 3d software that you use to generate your tree mesh you can take a sphere or a hemisphere and tell your software to bake the normals from the hem as we're onto the geometry of your tree you can transfer those normals over now I'm not going to get into exactly how to do that in in one specific 3d package or another you should be able to figure out how to do that and maybe I'll link some tutorials for how to do that in the description down below but this channel isn't really focused on on how to make a geometry or how to use 3ds max or Maya and those kinds of things but I just want you to know that that's how you do it you transfer the normals from a hemisphere or a sphere onto the normals of your vegetation and what you end up with is these normals that go from the center of the tree outward and this is what we call bent normals so if we switch back over to our shader and we wire in the original normal that we were using you'll be able to see that this is what our bent normals look like okay so now you can see that a lot of that model enos that we were getting before is gone and our lighting is a lot more uniform where we're not we're not getting those weird patches of black in the middle of our bright areas and so that's a significant improvement if we switch over to our world normals visualization mode you can also see that things are much smoother there and if we compare our normals on our tree with the normals on our sphere you can see that on this part of the tree that's kind of pointing in this direction over here we've got the same normals on the sphere that are pointing in that direction so if we look at all of our different directions we're getting approximately the same colors on the tree as we are on the sphere which is exactly what we're looking for so this is our second method bent normals and you do it by adjusting the normals on the mesh itself in your 3d program all right well let's talk about our third method which is object pivot normals and this is a good method to use if you are unable to change the normals on your geometry for some reason or maybe you want one type of normal for your geometry and another type of normals for your lighting in your shader what we can do is we can actually generate a normal vector from several different positions the way that we create a vector is we subtract one position for another so right now I have available to me in the shader the position of the object itself and I also have the position of the pixel that I'm currently rendering and if I subtract the pixel position from the object position that will gives me a vector that goes in the direction leading away from the object out toward the pixel that I'm currently rendering so let's go ahead and do that first we need our world position and then we also need our object position and like I said if we subtract these two we end up with a vector that goes from the object position out to the pixel position that we're currently rendering now in order to use this for lighting we first need to normalize it and then just as we did over here we need to transform it from world space which is the space we computed it in to tangent space and once we have an in tangent space then we need to flip it when it's on the reverse side of the polygon so we're gonna multiply it by our two-sided sign and now let's take a look at what these normals look like all right so you can see that we're getting some normals that are kind of similar to the bent normals that we had before and if you compare them to our sphere over here you can see that our lighting matches the the sphere and so the normals that we're getting are pointed in the proper directions this is what we want now one thing that you might notice is that these normals are really uniform they're really smooth and that may be what you want but we're actually not using our normal map right now so the next thing that I want to do is switch back to our shader and show you how to incorporate our normal map another thing that I want to emphasize is this method that we've used for our foliage normals doesn't use vertex normals at all so you might be able to get away with not creating vertex normals and just generating them with this method okay so here we have the the normal that we created and we've transformed it to tangent space and now all we need to do is take our normal map and combine our normal map with the normal that we generated and we can do that with a blend angle correct normals node so we'll wire our generated normal into the base normal socket and we'll wire our leaf normal into the additional normal socket and then we'll multiply that by our two-sided sign to flip the normals and we'll save this and take a look at our result all right and now you can see that our normals are not quite so uniform they're actually being tweaked a little bit by the normal map now I don't know if you can see but I actually did make a mistake can you see how these normals are smeared well the reason they're doing that is because we forgot to use the UV coordinates that we're generating up here so here you can see that we have our UV coordinates for a texture sample for our normal map and we actually need to wire these into the copy of the normal map that we created and now you can see that fix the problem for us no more normal smearing all right so this method looks pretty good let's talk about method number four method number four is actually using the camera vector as our surface normal so the camera vector is a vector that goes from the from your eye or from the the camera in the scene toward the object or the pixel that's currently being rendered so in order to use the camera vector for the normal first we need to add the camera vector obviously and then just like we did before we need to transform that vector because it starts out in world space we need to transform it into tangent space and then we also need to flip it on the backsides of the polygons so now we've taken our camera vector transformed it into tangent space flipped it on the backside of the polygons and we can use this as our normal so let's pass this in and see if what we get from this all right now what you can see is that we're using this camera vector as our normal and so the direction that the foliage is facing is really just the direction that I'm looking at it so as I rotate around you can see that it's changing so that the normals are the color on the sphere that I'm looking at and this is a really uniform way of creating normals it's a really good method for using normals for planes that you want to appear to always face you so in this case my tree is made out of planes and if I want to make it look like those planes are always looking at the camera then I can use this camera vector method alright so let's go over our methods again the default method that we're using is bent normals because we have geometry with normals that are bent I also use this method down here to create face normals which is what you would get if you didn't and the normals in the geometry then I use this method here to generate a normal using the object position and subtracting the object position from the current world position and finally we have this method here using the camera vector as the normal now I did promise you one additional method and what I want to do is create a method that's a little bit of a hybrid between the camera vector method and the object pivot normal method and so what I'm going to do is I'm going to take my camera vector and I'm going to bring it up here and we're going to use the camera vector method for the branches of our tree and the object pivot normal method for the leaves of the tree and so if you'll remember we created a mask using the Alpha channel of our diffuse texture and we're using that math to generate the translucency color for a leave so this mask is colored white for leaves and black for everything else so if I come over here and I add a linear interpolate node I can blend between my camera normal method and my object pivot method using this leaf mask then I'm going to take the result of my linear interpolate and chain and pass that into my transform vector node then I'm gonna combine it with my normal map and then I'm gonna flip the normals on the backsides of the leaves and then this is what I'm gonna use for my final normal and so now if we take a look at the normals on our leaves you can see that the leaves are using the normals from the object pivot method and the branches are using the normals from the camera vector method and this really helps to separate out the leaves from the branches now we've been using this debug view method but what I want to do now is switch back to our normal lit and show you what the tree looks like with the normals the way that we intended them to be now I'm gonna turn back on our subsurface scattering our translucency for our leaves and I'm also gonna come back over here and turn on our skylight again and so now we get our final result today we talked about four different kinds of normals we talked about face normals vent normals object pivot normals camera normals and then we even made a hybrid method at the end here using both the object pivot method and the camera normals so I hope this is useful for you now you have a bunch of different methods that you can use for generating normals for your foliage and what I want you to do is I'd encourage you to play around with these different methods and see which of these gives you the best results on your foliage I hope you enjoyed today's tutorial give it a like if you did and if you haven't already please subscribe to my channel we'll have another video next week about fading out our foliage when you get too close and also using a bit of a dither method for the fade-out stick around for that one and we'll see in the next video [Music]
Info
Channel: Ben Cloward
Views: 5,546
Rating: undefined out of 5
Keywords:
Id: E_IiqijpfS0
Channel Id: undefined
Length: 18min 52sec (1132 seconds)
Published: Thu Jul 02 2020
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.