Subtitles section Play video
Materials in Unity are the assets that control
the visual appearance of game objects.
Applied to a renderer component,
the material is essentially an asset
that brings together a shader, a script
that controls the appearance of a rendered surface
and it's required properties, such as
colours and textures.
Materials can be made by using the
Create button on the project panel.
And once you've created this asset
it can be assigned to a renderer component
and a shader can be chosen from the drop down list.
Materials can also be generated from
models brought in from 3D packages
but we will discuss this later.
As a basic example
if we have a primitive cube in Unity
and an example material ready to use on it
we can assign this to the mesh renderer.
The mesh renderer is the component used
to render any 3D mesh.
We'll assign this to the materials slot.
By default a primitive mesh has
Unity's default-diffuse material assigned to it.
We will replace this with our example material.
Whilst I have assigned this material
by dragging it directly to the material's property
I could also assign it by dragging it to the model
or dropping it in to the scene.
And you can see that Unity previews what that
material would look like on the mesh
that we're dropping on to.
Once assigned we see settings for this material
below other components in the inspector.
It's important to know that this part of the inspector's
settings are simply a shortcut to editing
the material asset.
This is important because when changing the
properties of a material on the object
you are actually changing the material asset itself.
For example if I make this material red.
The asset has been made red.
So for example
if I have a sphere
and assign the same material
it too will be red.
And when adjusting that material on
either of those two objects
we're simply adjusting the asset so any object
using that material will be changed too.
When introducing 3D assets from
a modelling application Unity will create
the materials in a materials subfolder
in the location of the asset
as well as assigning textures for you.
For example this blast door asset has been
brought in to Unity and we have saved
it's textures in to folder called Textures
which Unity automatically searches
in order to reassign it to the material
that it creates.
The two parts of the asset are the door
and the frame.
Both of these assets share the same material
and simply use different parts of the texture
to render them.
The material that's being created is
Prop_Blastdoor
and I can see that if I click on it
it's highlighted in the project panel.
As standard when introducing this
we would be shown a diffuse shader.
This is a flat standard look for
rendering 3D meshes.
We have a normal map for this asset
so we can instead choose a bumped shader
such as Bump Diffuse
to make use of this texture.
The normal map is a way of storing
height and directional information
that is projected onto the surface
of a flat mesh
in order to give it the appearance of
surface detail without adding
vertices to the geometry itself.
And if you look at the mesh in the scene or
game view you can see the difference
that this makes.
So the dents, grooves and scratches
on our blast door are accentuated
in the normal map texture.
We could also extend this to give
it a shiny surface by choosing
Bumped Specular.
Here, in addition to the texture and the normal map
we are also able to set the shininess.
So we've gone from our default flat look
to our nice shiny looking dented door
simply by adjusting the shader.
We haven't had to add any more detail to the
original model, and that's the true power
of using materials.
Unity ships with many shaders that will
cover all manner of game development needs
and you can also write your own shaders
and assign them.
You can create these also from using the
create button on the project panel.