Unity shaderLab中,经常会看到 各种Tag(标签)。这里大致分为两类Tag,SubShader Tag 和 Pass Tag。·
SubShader Tag
Sub的这些只能是在SubShader中,但是不能再Pass中,我们还能使用material.GetTag 函数查询他们。
Rendering Order - Queue tag
在3D引擎中,我们经常要对 透明和不透明物体进行排序。先渲染不透明再渲染透明物体,Unity使用 Queue标签,分别放入不同的渲染队列中。
-
Background
- 背景,一般天空盒之类的使用这个标签,最早被渲染 -
Geometry
(default) 适用于大部分不透明的物体 -
AlphaTest
- 如果Shader要使用AlphaTest功能 使用这个队列性能更高 -
Transparent
- 这个渲染队列在AlphaTest之后,Shader中有用到Alpha Blend的,或者深入不写入的都应该放在这个队列。 -
- this render queue is meant for overlay effects. Anything rendered last should go here (e.g. lens flares).Overlay 最后渲染的队列,全屏幕后期的 都应该使用这个
Shader "Transparent Queue Example" { SubShader { Tags { "Queue" = "Transparent" } Pass { // rest of the shader body... } } }
RenderType tag
RenderType tag可以用自定义的字符串,在使用ShadeReplacement,全局替换渲染的时候有用。
DisableBatching tag
很多着色器中,如果使用的Batching技术,物体的模型空间中的位置信息都没了。如果要设计的模型空间坐标系的操作的shader,就得禁用 Batching,保存模型空间的信息。 我们可以使用 "DisableBatching "="True",默认都是“False”
ForceNoShadowCasting tag
如果要替换一个半透明的物体的Shader,如果想要这个物体不需要产生阴影,就用这个。半透明物体渲染如果不需要阴影就加上标签。
IgnoreProjector tag
Unity 有种Projector 投影效果,如果加上这个Tag,那么就不会受到投影影响。(贴花,Projector阴影效果)
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
正常我们都是用一个球体观察材质,设置标签”Plane“ 或者 "Skybox"
Pass Tag
Pass Tag 一般控制灯光相关的信息,这些跟SubShader Tag一样,只能在Pass块里面起效果。
LightMode tag
渲染路径标签, 一般现在渲染分为了 三类,顶点渲染路径,向前的渲染,对于的延迟渲染路径。
-
Always: Always rendered; no lighting is applied.
-
ForwardBase: Used in Forward rendering, ambient, main directional light, vertex/SH lights and lightmaps are applied. 只受到环境光,主要(强度最大那个)的方向光,球协光照和lightMap影响
-
ForwardAdd: Used in Forward rendering; additive per-pixel lights are applied, one pass per light. 如果灯光类型是 NO-IMPORT 或者其他类型光源 就会用到这个
-
Deferred: Used in Deferred Shading; renders g-buffer. 延迟渲染的,渲染到Gbuffer
-
ShadowCaster: Renders object depth into the shadowmap or a depth texture. 生成阴影要用深度图shader
-
MotionVectors: Used to calculate per-object motion vectors. 计算物件移动向量
-
PrepassBase: Used in legacy Deferred Lighting, renders normals and specular exponent.
-
PrepassFinal: Used in legacy Deferred Lighting, renders final color by combining textures, lighting and emission.
-
Vertex: Used in legacy Vertex Lit rendering when object is not lightmapped; all vertex lights are applied.
-
VertexLMRGBM: Used in legacy Vertex Lit rendering when object is lightmapped; on platforms where lightmap is RGBM encoded (PC & console).
-
VertexLM: Used in legacy Vertex Lit rendering when object is lightmapped; on platforms where lightmap is double-LDR encoded (mobile platforms).
-
PassFlags tag
-
A pass can indicate flags that change how rendering pipeline passes data to it. This is done by using PassFlags tag, with a value that is space-separated flag names. Currently the flags supported are:
- OnlyDirectional: When used in ForwardBase pass type, this flag makes it so that only the main directional light and ambient/lightprobe data is passed into the shader. This means that data of non-important lights is not passed into vertex-light or spherical harmonics shader variables. See Forward rendering for details.
RequireOptions tag
A pass can indicate that it should only be rendered when some external conditions are met. This is done by using RequireOptions tag, whose value is a string of space separated options. Currently the options supported by Unity are:
- SoftVegetation: Render this pass only if Soft Vegetation is on in Quality Settings.