Unity Shader 中各種Tag


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的,或者深入不寫入的都應該放在這個隊列。

  • 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...
        }
    }
}

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.


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM