Materials and Shaders
Здесь мы раскроем взаимосвязь и взаимодействие между материалами (Materials) и шейдерами (Shaders) в Unity. Шейдер содержит код, который определяет, какие будут свойства и ассеты. Материалы позволяют настраивать эти свойства и назначать ассеты.

A Shader is implemented through a Material
Создание нового материала (2 способа):
* Assets>Create>Material;
* Create в Project View.
После создания материала его можно применить к объекту и настроить через Inspector. Для применения к объекту просто перетащите его из Project View на объект в Scene View или Hierarchy View.
Setting Material Properties
Можно выбрать, какой шейдер будет использоваться материалом, открыв выпадающее меню Shader в Inspector и указав нужный шейдер. Доступные для модификации свойства изменятся сообразно выбранному шейдеру. Если применить материал к активному объекту в сцене, изменение настроек материала будет отображаться на объекте в реальном времени.
There are two ways to apply a Texture to a property.
- Drag it from the Project View on top of the Texture square
- Click the button, and choose the texture from the drop-down list that appears
Два свойства, доступных для всех текстур:
| Tiling | Размер текстуры. |
| Offset | Смещение текстуры. |
Built-in Shaders
There is a library of built-in Shaders that come standard with every installation of Unity. There are over 30 of these built-in Shaders, and six basic families.
- Normal: For opaque textured objects.
- Transparent: For partly transparent objects. The texture's alpha channel defines the level of transparency.
- TransparentCutOut: For objects that have only fully opaque and fully transparent areas, like fences.
- Self-Illuminated: For objects that have light emitting parts.
- Reflective: For opaque textured objects that reflect an environment Cubemap.
- Lightmapped: For objects that have an additional Lightmap texture and corresponding texture UV channel.
In each group, built-in shaders range by complexity, from the simple VertexLit to the complex Parallax Bumped with Specular. For more information about performance of Shaders, please read the built-in Shader performance page
В Unity есть библиотека встроенных шейдеров. Они разделенны на шесть основных групп.
* Normal: для непрозрачных текстурируемых объектов.
* Transparent: для частично прозрачных объектов. Альфа-канал текстуры определяет прозрачность области.
* TransparentCutOut: для объектов, у которых области или полностью прозрачные или полностью непрозрачные.
* Self-Illuminated: для объектов, участки которых излучают свет.
* Reflective: для непрозрачных текстурированных объектов, которые отражают окружающую среду.
* Lightmapped: для объектов, у которых есть дополнительная текстура-лайтмап и соответствующий UV-канал для текстуры.
В каждой группе шейдеры ранжируются от простого VertexLit до сложного Parallax Bumped with Specular. Подробная информация о производительности шейдеров — performance page.
Эта таблица содержит уменьшенные эскизы встроенных шейдеров:

Матрица встроенных шейдеров.
Shader technical details
Unity использует расширяемую систему шейдеров, позволяющую настраивать внешний вид графики в игре. Это работает так:A Shader basically defines a formula for how the in-game shading should look. Within any given Shader is a number of properties (typically textures). Shaders are implemented through Materials, which are attached directly to individual GameObjects. Within a Material, you will choose a Shader, then define the properties (usually textures and colors, but properties can vary) that are used by the Shader.
This is rather complex, so let's look at a workflow diagram:

On the left side of the graph is the Carbody Shader. 2 different Materials are created from this: Blue car Material and Red car Material. Each of these Materials have 2 textures assigned; the Car Texture defines the main texture of the car, and a Color FX texture. These properties are used by the shader to make the car finish look like 2-tone paint. This can be seen on the front of the red car: it is yellow where it faces the camera and then fades towards purple as the angle increases. The car materials are attached to the 2 cars. The car wheels, lights and windows don't have the color change effect, and must hence use a different Material. At the bottom of the graph there is a Simple Metal Shader. The Wheel Material is using this Shader. Note that even though the same Car Texture is reused here, the end result is quite different from the car body, as the Shader used in the Material is different.
Шейдер определяет:
- The method to render an object. This includes using different methods depending on the graphics card of the end user.
- Any vertex and fragment programs used to render.
- Some texture properties that are assignable within Materials.
- Color and number settings that are assignable within Materials.
Материал определяет:
- Какая текстура используется для рендеринга;
- Какой цвет используется для рендеринга;
- Ассеты, используемые для рендеринга (например, Cubemap).
Shaders are meant to be written by graphics programmers. They are created using the ShaderLab language, which is quite simple. However, getting a shader to work well on a variety graphics cards is an involved job and requires a fairly comprehensive knowledge of how graphics cards work.


