Version: 2017.2
Синтаксис ShaderLab: GrabPass
Синтаксис ShaderLab: Fallback

ShaderLab: SubShader Tags

Subshader’ы используют теги, чтобы сообщить о том, как и когда они должны рендериться движком.

Syntax

Tags { "TagName1" = "Value1" "TagName2" = "Value2" }

Устанавливает значение Value1 в TagName1, Value2 в TagName2. Можно использовать сколько угодно тегов.

Details

Теги – это обычные пары “ключ-значение” (key-value). В SubShader’е теги используются для определения очередности рендеринга, и других параметров subshader’а. Обратите внимание, что следующие теги для распознавания Unity, должны быть в секции SubShader, а не в секции Pass.

In addition to built-in tags recognized by Unity, you can use your own tags and query them using Material.GetTag function.

Rendering Order - Queue tag

Вы можете определять порядок отрисовки ваших объектов с помощью тэга Queue. Шейдер решает к какой очереди отрисовки относятся его объекты, таким образом любые Transparent шейдеры (шейдеры с прозрачностью) отрисовываются после отрисовки всех непрозрачных объектов и так далее.

Есть четыре предопределённых очередей отрисовки, но могут присутствовать и дополнительные очереди между ними. Предопределённые очереди:

  • Background - this render queue is rendered before any others. You’d typically use this for things that really need to be in the background.
  • Geometry (default) - this is used for most objects. Opaque geometry uses this queue.
  • AlphaTest - alpha tested geometry uses this queue. It’s a separate queue from Geometry one since it’s more efficient to render alpha-tested objects after all solid ones are drawn.
  • Transparent - this render queue is rendered after Geometry and AlphaTest, in back-to-front order. Anything alpha-blended (i.e. shaders that don’t write to depth buffer) should go here (glass, particle effects).
  • Overlay - this render queue is meant for overlay effects. Anything rendered last should go here (e.g. lens flares).
Shader "Transparent Queue Example"
{
     SubShader
     {
        Tags { "Queue" = "Transparent" }
        Pass
        {
            // rest of the shader body...
        }
    }
}

Пример, поясняющий как отрендерить что-то в transparent очереди

For special uses in-between queues can be used. Internally each queue is represented by integer index; Background is 1000, Geometry is 2000, AlphaTest is 2450, Transparent is 3000 and Overlay is 4000. If a shader uses a queue like this:

Tags { "Queue" = "Geometry+1" }

Это заставит объект отрендериться после всех непрозрачных объектов, но перед прозрачными объектами, т.к. индекс очереди будет 2001 (geometry + 1). Это полезно в ситуациях, где вы хотите, чтобы определённые объекты всегда рисовались между другими наборами объектов. Например, в большинстве случаев, прозрачная вода должна рисоваться после непрозрачных объектов, но перед прозрачными.

Queues up to 2500 (“Geometry+500”) are consided “opaque” and optimize the drawing order of the objects for best performance. Higher rendering queues are considered for “transparent objects” and sort objects by distance, starting rendering from the furthest ones and ending with the closest ones. Skyboxes are drawn in between all opaque and all transparent objects.

Тег RenderType

RenderType tag categorizes shaders into several predefined groups, e.g. is is an opaque shader, or an alpha-tested shader etc. This is used by Shader Replacement and in some cases used to produce camera’s depth texture.

DisableBatching tag

Some shaders (mostly ones that do object-space vertex deformations) do not work when Draw Call Batching is used – that’s because batching transforms all geometry into world space, so “object space” is lost.

DisableBatching tag can be used to indicate that. There are three possible values: “True” (always disables batching for this shader), “False” (does not disable batching; this is default) and “LODFading” (disable batching when LOD fading is active; mostly used on trees).

Тег ForceNoShadowCasting

If ForceNoShadowCasting tag is given and has a value of “True”, then an object that is rendered using this subshader will never cast shadows. This is mostly useful when you are using shader replacement on transparent objects and you do not wont to inherit a shadow pass from another subshader.

Тег IgnoreProjector

If IgnoreProjector tag is given and has a value of “True”, then an object that uses this shader will not be affected by Projectors. This is mostly useful on semitransparent objects, because there is no good way for Projectors to affect them.

CanUseSpriteAtlas tag

Set CanUseSpriteAtlas tag to “False” if the shader is meant for sprites, and will not work when they are packed into atlases (see Sprite Packer).

PreviewType tag

PreviewType indicates how the material inspector preview should display the material. By default materials are displayed as spheres, but PreviewType can also be set to “Plane” (will display as 2D) or “Skybox” (will display as skybox).

См. также

Проходам тоже можно назначать теги, см. Теги проходов.

Синтаксис ShaderLab: GrabPass
Синтаксис ShaderLab: Fallback