CS304: Game Programming
Material, Texture & Model
The 3D Mode
In Unity, when you start a new project, you can select if you want to do a 2D
or a 3D game. This sets the editor in the 2D / 3D mode:
By default, the Scene View will be set to 3D view, although it is possible to
switch to 2D view at any time.
3D Game Objects (Primitive Meshes)
Unity has some pre-defined primitive meshes:
Cube Sphere Capsule
Cylinder Plane Quad
3D Transforms
All 3D game objects have a Transform component:
Translation, Rotation and Scale can be set in the transform or applied directly
on the Scene View using the control gizmos.
Translation Rotation Scale
Vertices, Triangles, Meshes
A mesh is a collection of 3D points (vertices) that, when combined together,
define a physical presence of an object. Every mesh is made up of a series of
triangles, given by its vertices.
Triangles are used because:
3 points determine a unique triangle with sides that don’t cross each other.
3 points determine a triangle in a unique plane (flat shape).
Mesh Filter and Renderer
Mesh Filter: The Mesh Filter takes a mesh from your assets and passes it to
the Mesh Renderer for rendering on the screen.
Mesh Renderer: Takes the geometry of the object from the mesh filter and
renders it at the position defined by the objects Transform component.
Cast Shadows: If enabled, this Mesh will create shadows when a shadow-
creating light shines on it.
Receive Shadows: If enabled, this Mesh will display any shadows being
cast upon it.
Materials : A list of Materials to render model with (see later).
Use Light Probes: Enable probe-based lighting for this mesh (see further
lectures).
Models (1/2)
A model is a mesh with its applied material, texture and shader.
Supported formats: Importing meshes into Unity can be achieved from two
main types of files:
Exported 3D file formats, such as .FBX or .OBJ.
Proprietary 3D application files, such as .Max and .Blend file formats from
3D Studio Max or Blender for example.
Unity can read .FBX, .dae (Collada), .3DS, .dxf and .obj files.
Models (2/2)
A model has a Model Material applied to it.
A material can be seen as the skin of the mesh.
Every mesh needs a material in order to be seen on the screen.
The model material (saved in a file) has two parts: the texture and the
shader.
Materials *
Unity provides a default material for every mesh (simple, plain grey material).
One of its basic parameters is a texture. A
texture is a simple image file:
We can create a new material in Unity and assign the texture to it. Then, it
is possible to apply the new material to the object:
Shaders
Shaders in Unity are used through Materials. The shader code tells the ma-
terial which properties it takes (colors, textures, transparency, etc.).
The default shader is the Standard Shader,
used in the default material. It is a very
versatile shader that can be configured in
multiple ways.
There are three sections in the shader
material:
1 Rendering Mode: Opaque (default).
Opaque (default).
Cutout: the alpha channel of the diffuse
image is used to cut out parts of the tex-
ture.
Fade: to make the object invisible.
Transparent: to make it transparent,
preserving it’s reflectivity.
The Standard Shader
2 Main Maps: Properties defined by texture maps:
Albido: combination of an optional texture and a colour value to tint the
texture (white: unaffected).
Metallic: “metalness” of the material’s surface, defined by a texture or a
slider. The texture colour defines how metallic each point is (0 red for
totally metallic, 255 red for no metallic).
Smoothness specifies how diffuse/sharp reflections are (0 → 1).
Alpha channel of the texture defines the smoothness.
Normal map: defines apparent bumpiness of the surface.
Height map: defines apparent height of the surface.
Occlusion: how it reacts to ambient light.
Emission: to make the material contribute to the scene lighting
Tiling and offset control position of the map.
3 Secondary maps: to define additional surface details, drawn on top of
the main maps.
The Standard Shader has an alternative (Standard, Specular Setup) that uses
Specular instead of Metallic. It can be also defined with a texture and colour,
and it is analogous to the metallic property in the Standard shader.
Shaders