Chapter 14. Lighting and Shaders

In this chapter we’ll look at lighting and materials, which are the primary thing—besides the textures that you use—that determine how your game looks. In particular, we’ll take a closer look at the Standard shader, which is a shader designed to make it simple to create good-looking materials. We’ll also talk about how to write your own shaders, which give you a huge amount of control over how objects appear in game. Finally, we’ll discuss how to use global illumination and lightmapping, which can create a great-looking environment by realistically modeling how light bounces in a scene.

Materials and Shaders

In Unity, the appearance of objects is defined by the material attached to it. A material is composed of two things: a shader and data that’s used by that shader.

A shader is a very small program that runs on the graphics card. Every single thing that you see on the screen is the result of a shader calculating the correct color value to show for each pixel.

In Unity, there are two main different types of shaders: surface shaders and vertex-fragment shaders.

Surface shaders are responsible for calculating the color of the surface of an object. As we already discussed in “Materials and Shaders”, there are multiple components that define the color of a surface, including its albedo, smoothness, and so on. A surface shader’s job is to compute the values of each of these properties for every pixel of the object; this surface information is then ...

Get Mobile Game Development with Unity now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.