Check out a free preview of the full Game Development with Unity for Web Developers course:
The "Materials" Lesson is part of the full, Game Development with Unity for Web Developers course featured in this preview video. Here's what you'd learn in this lesson:

Nick demonstrates adding materials to game objects to determine how they should look when rendered. A Material is an asset that combines a shader, a set of textures, and other values to partially determine how a 3D mesh should be rendered.

Get Unlimited Access Now

Transcript from the "Materials" Lesson

[00:00:00]
>> Now we've got a little bit of camera movement and that tends to make the game a lot more dynamic and interesting. And that will be really nice when the lighting is responding to materials. So as the camera moves around, we'll get kind of a different material response as the angle changes between the camera and the lights.

[00:00:23] So we're gonna assign some materials to make this game look a lot better than just a couple of gray cubes and spheres. But first, what is a material? This isn't something that's unique to Unity, this is true for really any 3D applications. But a material is in an asset that combines both a shader and a set of textures or other values like colors, floating-point numbers, to partially determine how a 3D mesh should be rendered.

[00:00:54] It could also be a 2D mesh, I suppose. So a shader is a small program that runs on the GPU, and generally, it shades each pixel. Although, a shader can also modify the vertices of 3D meshes. And that's how you get vertex shaders that create all sorts of cool interesting effects like tessellation or adding more geometry or kinda ocean waves, something like that, that you might see on a 3D mesh.

[00:01:24] Textures are 2D images that get applied to the 3D surface of a model. So you can kinda think about it like wrapping a globe or something with wallpaper. And it's the shader that helps determine how those textures are actually applied to the 3D model. So, a material just combines all of these elements.

[00:01:50] It combines the shader, it combines the textures, it combines all these certain values into a more easily understandable asset, such as a gold material, for anything in the game that we want to look like a gold, metallic surface. So, we've got a little bit more scene setup. Up to this point, we've had just the black background, but it would be really nice to have a plane on the ground.

[00:02:18] So, let's do that. That's really pretty easy to do in this case. We just want to go to 3D objects in the hierarchy, add a plane, that's it. We can call this Ground if we want to. And actually that's not it, we want this to be at the origin, so let me reset that.

[00:02:41] So the transform should be 0, 0, 0 for position rotation, and 1, 1, 1 for scale. So if we look at this in the scene view, you can see that we've got our little game board here, we've got the collectibles, we've got the players, and then we've got this large plane now.

[00:03:00] And it makes things pretty difficult to see, but once we assign materials, that will be a lot better. So I have just included some materials for us to work with. And if I move this slider, we can actually get a preview of what those are going to look like.

[00:03:23] So I wanna put this wood floor material. I can get a little preview of that. I wanna put this onto the ground plane. So I can just drag that from the project window, drop it on to the ground plane in the scene view. And there it is, now it's in the game view.

[00:03:43] It's that easy to assign materials. Just a little bit more about materials. I have this one selected. You can see that up here, like I said, it's a combination of a shader and textures or another values. Here's the shader. It's using a shader from the universal render pipeline, which is just a lit shader, a lit shader meaning it is using lighting, as opposed to a shader that is unlit, not using lighting.

[00:04:13] There's a couple of surface options, we want this surface to use the metallic physically based rendering workflow, which basically gives us these options here. It is an opaque surface as opposed to a, say transparent or glass surface, something like that. And we want it to receive shadows, we want it to be able to get shadows from our lights.

[00:04:38] And then we have a couple of surface inputs, so here are those textures that I was describing. If I click that, you can see that here is that just base color texture that looks a lot like that wood texture. But there's other textures there too. There's also a metallic smoothness map, which maps out what parts of the surface should be metallic, in this case, none.

[00:05:03] And parts that should be a little bit smoother or rougher, and that's kind of a black and white map. There's also a normal map, a normal map creates the appearance of kinda bumps or divots, and that's how in this, let's see if I can tear this off here, we get, well, maybe not.

[00:05:29] But we get the appearance of there being small little bumps and imperfections in the wood grain there. And that's coming from the normal map. Normal maps look pretty weird. Let me see if I can find one that's maybe a little bit better of an example. Not really, but normal maps look pretty weird, they do have basically each pixel value or each RGB value representing a vector that it should be pushing that particular pixel in.

[00:06:06] So it's pushing those pixels in a direction or an XYZ direction based on the RGB value. And that's how you get those little nice bumps in the shader. So we've applied the wood floor, the play surface, we want to be this kinda like black marble looking thing. And you don't have to drag things into the scene view.

[00:06:32] If you want to be more specific, you can actually select the game object that you want to apply something to and find it's mesh renderer component. Here it's using just a normal lit material. This is the player. I want the player to have this metallic gold material, so I can just drop that into this slot.

[00:06:56] I want the opponent to have kind of this bluish marble material, so we'll do that. And then finally, we want the collectible to have this kind of special emissive quality to it, so we'll drag that and put that here. So right now, this will just appear pink, it's not going to have kind of that glowing surface quality that I was showing previously, but we'll get to how to add that soon with post processing.

[00:07:30] So if I hit the space bar and start, now you can see that we have nicer materials, the games looking a lot better. There is more that we can do, but adding materials to surfaces really gives them a very physical looking quality, that we can push even further with additional effects.

[00:07:52] So that's kind of just a quick introduction to materials. Altering materials is a very deep topic, altering shaders is perhaps an even deeper topic than that. But you can create shaders and your own materials and bring them into Unity and create lots of really cool stuff. These were just downloaded from the Internet, under CC0 license, and there's lots of great resources out there for all sorts of materials that you can use in your games.