Version: 2018.1
Текстуры
Standard Shader

Creating and Using Materials

To create a new Material, use Assets->Create->Material from the main menu or the Project View context menu.

By default, new materials are assigned the Standard Shader, with all map properties empty, like this:

Используйте пункт главного меню Assets->Create->Material или контекстное меню окна Project (Project View) для создания нового материала. После создания, вы можете применить его к объекту и настроить все его свойства в инспекторе (Inspector). Для применения материала к объекту, просто перетащите его из окна Project (Project View) на любой объект в сцене (Scene) или иерархии сцены (Hierarchy).

Установка свойств материала

Вы можете выбрать какой именно шейдер будет использоваться в конкретном материале. Для этого просто раскройте выпадающее меню Shader в инспекторе и выберите подходящий вам шейдер. Выбранный вами шейдер будет задавать доступные для изменения свойства. Свойствами могут выглядеть как цвета, слайдеры, текстуры, числа или векторы. Если вы применили материал к активному объекту в сцене, вы увидите, как в реальном времени будут применяться изменяемые вами свойства.

Существует два способа присваивания текстуры (Texture) свойству.

  1. С помощью перетаскивания текстуры из окна Project на квадратную область свойства Texture
  2. С помощью нажатия кнопки Select и выбора текстуры из появившегося выпадающего списка

Встроенные шейдеры

В дополнение к основным шейдерам, применяемым к игровым объектам, существует ряд других категорий для особых целей:-

  • FX: водные и световые эффекты.
  • GUI: отображение графического интерфейса пользователя (GUI - это аббревиатура для Graphic User Interface, что в переводе означает “графический интерфейс пользователя”).
  • Mobile: Simplified high-performance shader for mobile devices.
  • Nature: деревья и земная поверхность.
  • Particles: эффекты системы частиц.
  • Skybox: For rendering background environments behind all geometry
  • Sprites: For use with the 2D sprite system
  • Toon: отрисовка в мультипликационном стиле.
  • Unlit: For rendering that entirely bypasses all light & shadowing
  • Legacy: The large collection of older shaders which were superseded by the Standard Shader

Технические детали шейдера

A Shader is a script which contains mathematical calculations and algorithms for how the pixels on the surface of a model should look. The standard shader performs complex and realistic lighting calculations. Other shaders may use simpler or different calculations to show different results. Within any given Shader are a number of properties which can be given values by a Material using that shader. These properties can be numbers, colours definitions or textures, which appear in the inspector when viewing a Material. Materials are then used by Renderer components attached to Game Objects, to render each Game Object’s mesh.

It is possible and often desirable to have several different Materials which may reference the same textures. These materials may also use the same or different shaders, depending on the requirements.

Below is an example of a possible set-up combination using three materials, two shaders and one texture.

In the diagram we have a red car and a blue car. Both models use a separate material for the bodywork, “Red car material” and “Blue car material” respectively.

Both these bodywork materials use the same custom shader, “Carbody Shader”. A custom shader may be used because the shader adds extra features specifically for the cars, such as metallic sparkly rendering, or perhaps has a custom damage masking feature.

Each car body material has a reference to the “Car Texture”, which is a texture map containing all the details of the bodywork, without a specific paint colour.

The Carbody shader also accepts a tint colour, which is set to a different colour for the red and blue cars, giving each car a different look while using a single texture for both of them.

The car wheel models use a separate material again, but this time both cars share the same material for their wheels, as the wheels do not differ on each car. The wheel material uses the Standard Shader, and has a reference again to the Car Texture.

Notice how the car texture contains details for the bodywork and wheels - this is a texture atlas, meaning different parts of the texture image are explicitly mapped to different parts of the model.

Even though the bodywork materials are using a texture that also contains the wheel image, the wheel does not appear on the body because that part of the texture is not mapped to the bodywork geometry.

Similarly, the wheel material is using the same texture, which has bodywork detail in it. The bodywork detail does not appear on the wheel, because only the portion of the texture showing the wheel detail is mapped to the wheel geometry.

This mapping is done by the 3D artist in an external 3d application, and is called “UV mapping”.

Если быть точнее, шейдер определяет:

  • The method to render an object. This includes code and mathematical calculations that may include the angles of light sources, the viewing angle, and any other relevant calculations. Shaders can also specify different methods depending on the graphics hardware of the end user.
  • The parameters that can be customised in the material inspector, such as texture maps, colours and numeric values.

Материал определяет:

  • Какие текстуры использовать для отрисовки.
  • The specific values for the shader’s parameters - such as which texture maps, the colour and numeric values to use.

Написанием шейдеров должны заниматься программисты 3D графики. Шейдеры создаются при помощи довольно простого языка ShaderLab. Однако, заставить шейдер правильно работать на множестве различных видеокарт - непростая задача и она требует хороших всесторонних знаний о том, как работают графические адаптеры.

A number of shaders are built into Unity directly, and some more come in the Standard Assets Library.

Текстуры
Standard Shader
Copyright © 2023 Unity Technologies
优美缔软件(上海)有限公司 版权所有
"Unity"、Unity 徽标及其他 Unity 商标是 Unity Technologies 或其附属机构在美国及其他地区的商标或注册商标。其他名称或品牌是其各自所有者的商标。
公安部备案号:
31010902002961