Join Craig Barr for an in-depth discussion in this video Material instances, part of Unreal Essential Training.
- View Offline
- The material setup in Unreal Engine 4 is incredibly powerful, but it's also very efficient. So we're going to take a look at how we can take advantage of the power of the Unreal Engine with a very efficient manner of using materials. So typically what will happen is that if we have a material and we create that material, for example, let's go into these Rocks here, and if we double-click on this rock we can see that this rock material is quite a complex network, so there's a lot going on inside this material.
And of course we're utilizing that quite a bit across this environment. Now if we wanted to change an aspect of that material, perhaps the color of the rock, or the way the moss is dispersed across these rocks, and then be able to apply that to different subset of sets of rocks we're going to have to create a whole new material and that can actually get quite intensive on the engine, because now it has two materials to calculate. Well in Unreal Engine 4 you have the ability to take advantage of instances. And this is an instance of a material. So these material instances in Unreal Engine 4 allow you to promote parameters to the top level basically under the format of a new material, but it is not as computationally expensive as a full material.
So this way you're essentially creating not a full duplicate, but an instance. Much like you would work in a 3D content creation package where you create an instance of a piece of geometry where everything that happens to the parent geometry, any changes made are populated to that instance. Same thing here with material instances, however what we can do is promote a couple parameters that will allow us to change a few things on the fly, and it's very light and efficient on the overall calculation of your game. Let's take a look at how we can do that with this rock texture.
So if we go into our rock there, if I just double-click on our rock material it'll bring up a tab. I would advise you dock it on the top up here of the user interface, so that it allows you to work with it in a little bigger view. As you can see the network for this rock material is quite large. Let's just take a quick little tour as to what's happening here on this material. Here's our main material node, and you can see that we have something going on here into the Base Color, things driving a Metallic finish on the overall rock material, Roughness, of course Normal in there, and then we have things driving Displacement, Tessellation, and a basic Ambient inclusion map here driven into the AO input.
But as you can see the network gets quite large. And to duplicate this material could add to the calculation overall of the engine. But what if I want to just create some things so that we can control or differentiate some of the rocks in our scene. So maybe the overall color of the rock and maybe the dispersion of the moss on these rocks. So we can kind of change that up and essentially create a new version of this material. Let's look at how we can do that. The first thing to understand is what is required for a material instance to work.
Now anything that changes on the material will promote to a material instance, but I can't change any of the default values via a material instance. And what I mean by that is all of these things are hardwired to the material, but I can create what are referred to as parameters and promote those at the instance level. For example, I want to control this greyness of the rock, or the ambient overall material base color of the rock. Let's do that by adding in a simple parameter, and the way that you do this is right-click in your material editor, and we'll go down and you'll see that there is a folder here called Parameters.
And if we open that up to reveal that you're going to see that we have a bunch of different parameters in here that'll work. Now without diving into all of these here, some basics. Anything that we want to change kind of numeric values on things we'll jump into things like ScalarParameters. And anything that we want to affect an overall color is where you're going to want to apply a Vector. So in this case here with the VectorParameter I'm going to click that and drop that into our scene. What that's going to allow me to do here is create something that will drive the color via a numeric value, but we can also use a color chooser in this.
So right now this is a color, by default it is set to black. Now I know that this color right here is driving the overall ambient grey on this material, and I can test that by simply selecting this node, coming into one of these channels, perhaps the red, and just dialing it up really large here to see what happens. And there you can see that it's affecting that overall color. So I'm going to use control Z or control zed just to undo that, bring it back. I can see the values that are driving that color up here on top of the node. Let's copy those materials into this one.
So I can simply go in here and get something relatively close to it by dialing it in this way, arbitrarily, or I can simply enter in the exact value that we already have on that grey material or that grey color. And let's just make sure that we have what we need on that. And if we hit OK on there we have now the parameter value is matching this one. And we can see the colors look quite the same there.
So now what we're going to do is actually replace this input on this node here, which is a linear interpretation node. We're going to take a look at just replacing this. And I'm going to take the RGB value, which is the top pin, and bring that into the B value to effectively replace this value. And we can see our rock shader looks pretty much the same. Now what we need to do is you can see that there's this title None up here, we need to give this parameter a name. And this is under the General tab, Parameter Name. And I'm going to call this one simply Rock_Color.
We could give this a Group name if we wanted to, maybe we can call this Rock, it doesn't matter actually. We're just going to promote this one and we'll actually do one more. So we keep the parameters simple for our instance. So now we can control that color, so let's leave that one. And now what I want to do is be able to control this moss. This is the main texture that's driving in this moss effect over top of the rock. But also following this back, we can see quite a bit is going on over here as to how those textures are applied. And we can test that again by looking at this Texture Coordinate here and maybe driving down something like the U and the V to see the overall result of that.
And we can see that it's affecting the placement of that texture. And I'm just going to undo that twice to bring it back to that value of 3 and 3, so we need to remember those values on there. Now what I want to do is go back to our Parameter function in here and we talked about Vector applying the color and we talked about Scalar being a numerical factor and we're going to use this as our driving force for the changing that tiling. Now it only has this output, so I can't take advantage of what's happening here in the U, V TextCoordinate node, but what we can do is place down a multiply.
And just to show you a shortcut for that, if I hold down the M key and then left-click that's a good quick little shortcut for dropping down a multiplying node. I'm going to wire the Texture Coordinate into A, and I'm going to wire in this Scalar value into B. We should name this one, so I'm going to click on this one, and I'm going to give this Parameter a name, I'm going to call this one Tiler. We should rename that to Moss Tiler, we'll called it that. That way we can adjust the moss value on there.
Now we want to replace this TextCoordinate here into this Add value at A. There we go, we've done that. We're going to see something happen here. This is changing because our Texture Coordinates originally are at 3 and 3, and our Moss Tiler is set to 0, so what we're going to want to do is actually change this one back to a default of 1 and 1, and probably change this default value here to a 3. And what that's going to do is effectively drive that 3 and 3 into the Multiply. So we're saying that U and V are both 1, but that value's being overwritten here, or multiplied with the value of our Moss Tiler under our Multply node of 3.
So you can see that we're getting that same value now. Alright, so now let's click Save on this, that's important, we need to save our material. And once that is saved we can go right back out to our scene. So I'm going to jump right back outside here. There's our material, now we want to create an instance to be able to control those values here. So let's right-click on that material, and go to Create Material Instance. And let's call this one Rock, we already have Rock 2 and 3, we'll call it Rock 4.
So now we can see that this one here looks the same, because it is, it's identical, nothing has changed in this, but if I double-click on this something interesting happens. We get a different editor. And this is a material instance editor. And this is going to show the parameters that we promoted to the top. So now we can see that underneath this Parameter Group, I should just show, by default you might see it something like this, you're going to want to reveal Parameter Groups. You can see that we've defined this Rock area here and this one we actually didn't give this group a name. So we could rename that here and just call it moss if we wanted to, but that's our Scalar and this is our Vector.
So to enable a change here we want to click on that box of the Rock_Color, and this is where we can either change this numerically here or we can actually go into a color chooser as well. So to test this to make sure it's actually working this is where we could go into something like a red and dial in something more like a red. And you can see that if we go to Unlit, you can see that that's affecting that color quite nicely. So something more realistic is we're probably going to maybe want to make this rock a bit of a different tinge.
So maybe if we wanted to add a little bit of a blue effect overall to that rock, there we go, we'll leave it something like that. So we get this a little bit more of a blue and less of a grey. I'm going to hit OK on that. And then in our Scalar Parameter Value we can see this moss scattered across the rock here. Let's click on our Moss Tiler, so that we can affect this amount here. Now if we go down we're essentially affecting the tiling of that moss. So a smaller value is actually going to scale up the way that is tiled, right? A larger value is actually going to create more moss scattered across it, or more densely packed, so if we doubled it up to something like 6 we're going to get a more densely packed moss structure here across that rock's surface.
Whereas if we went down to something like maybe a 1, we're going to see it more sporadic. So that's fine, we could click Save on that, and that's essentially applying that to our material instance. And we can even see the updated thumbnail in here if we wanted to make that a little bit bigger. We can see that we have a difference in the moss distribution and the overall ambient color of that rock. And that's a quick way to create very efficiently versions of materials. So definitely explore material instances and remember that any parameter you create has to be promote-able to the top and once you've been to do that it's very simple to create a material instance just simply by right-clicking on that material and then dialing in the simple parameters that you want to do.
And now you'll have a very quick, easy, and efficient calculation of your overall scene for your project.
- Customizing the Unreal UI
- Creating a new project
- Creating landscapes
- Blocking out levels
- Assembling a scene
- Working with materials and lights
- Adding post-processing effects
- Defining bodies of water
- Adding atmospherics, foliage, and wind
- Working with the Blueprint editor
- Creating cinematics
- Monitoring performance
- Packaging a game for distribution