ShaderLab- Pass Tags

25 篇文章 0 订阅
25 篇文章 0 订阅

ShaderLab: Pass Tags

Passes使用Tags来告诉渲染引擎如何和何时将它们渲染。

Syntax

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

指定 TagName1 有值 Value1, TagName2 有值 Value2. 你可以定义任意数量的tags.

Details

Tags是基本的键值对. 在内部一个Pass 的 tags 用来控制该pass在光照管线中有什么作用 (ambient, vertex lit, pixel lit etc.) 和其他一些选项. 注意下面的被Unity定义的tags,必须在Pass区块,不能在SubShader中!

LightMode tag

LightMode tag 定义了 Pass 在光照管线内的作用。 See render pipeline for details. 这些标签是很少手动使用; 通常需要与灯光交互的shader被写成 Surface Shaders 然后所有这些细节都被转交.

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.
  • ForwardAdd: Used in Forward rendering; additive per-pixel lights are applied, one pass per light.
  • Deferred: Used in Deferred Shading; renders g-buffer.
  • ShadowCaster: Renders object depth into the shadowmap or a depth texture.
  • 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

Pass可以声明标志来改变 rendering pipeline传输数据给它的方式。 可以使用 PassFlags tag 来达到目的, 它的值,是space-separated的flag names. 目前支持的标识:

  • OnlyDirectional: 当在pass使用ForwardBase, 这个标志会使只有主要的平行光和环境光/光探头的数据会传入shader。这意味着非重要光线的数据不会被传递到顶点光或球谐着色器变量中. See Forward rendering for details.

RequireOptions tag

A pass can indicate that 只会在满足一定外部条件时才会渲染。 This is done by using RequireOptions tag, whose value is a string of space separated options. Currently the options supported by Unity are:

  • SoftVegetation: 只有当Soft Vegetation在 Quality Settings里打开时,才会渲染.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
### 回答1: 在Unity中,可以使用ShaderLab语言编写自定义着色器。下面是一个简单的UI模糊效果的Shader: ``` Shader "Custom/UIBlur" { Properties { _MainTex ("Texture", 2D) = "white" {} _BlurSize ("Blur Size", Range(0.0, 1.0)) = 0.01 } SubShader { Tags {"Queue"="Transparent" "RenderType"="Transparent"} Pass { ZWrite Off Blend SrcAlpha OneMinusSrcAlpha Cull Off CGPROGRAM #pragma vertex vert #pragma fragment frag #include "UnityCG.cginc" sampler2D _MainTex; float _BlurSize; struct appdata { float4 vertex : POSITION; float2 uv : TEXCOORD0; }; struct v2f { float2 uv : TEXCOORD0; float4 vertex : SV_POSITION; }; v2f vert (appdata v) { v2f o; o.vertex = UnityObjectToClipPos(v.vertex); o.uv = v.uv; return o; } fixed4 frag (v2f i) : SV_Target { fixed4 col = tex2D(_MainTex, i.uv); col += tex2D(_MainTex, i.uv + float2(-0.5, -0.5) * _BlurSize); col += tex2D(_MainTex, i.uv + float2(-0.5, 0.5) * _BlurSize); col += tex2D(_MainTex, i.uv + float2(0.5, -0.5) * _BlurSize); col += tex2D(_MainTex, i.uv + float2(0.5, 0.5) * _BlurSize); col /= 5.0; return col; } ENDCG } } FallBack "UI/Default" } ``` 这个Shader中的`_MainTex`属性指定了需要模糊处理的纹理,`_BlurSize`属性指定了模糊的程度。在Fragment Shader中,使用了多次tex2D采样实现了简单的模糊效果。最后将采样到的颜色进行平均,返回最终的颜色。 在使用这个Shader时,只需要将它应用到需要模糊处理的UI元素的材质上即可。 ### 回答2: 要使用ShaderLab编写UI模糊效果,可以按照以下步骤进行: 1. 创建新的Shader文件:在Unity中创建一个新的着色器文件,并将其命名为BlurEffectUI。 2. 编写Shader语言代码:在新的着色器文件中,使用Shader语言编写模糊效果的代码。可以使用模糊算法,例如高斯模糊或均值模糊。下面是一个使用高斯模糊的例子: ``` Shader "Custom/BlurEffectUI" { Properties { _MainTex ("Texture", 2D) = "white" {} _BlurAmount ("Blur Amount", Range(0.0, 1.0)) = 0.5 } SubShader { Pass { Tags { "Queue" = "Transparent" "RenderType" = "Transparent" } CGPROGRAM #pragma vertex vert #pragma fragment frag #include "UnityCG.cginc" sampler2D _MainTex; float _BlurAmount; struct appdata { float4 vertex : POSITION; float2 uv : TEXCOORD0; }; struct v2f { float2 uv : TEXCOORD0; float4 vertex : SV_POSITION; }; v2f vert (appdata v) { v2f o; o.vertex = UnityObjectToClipPos(v.vertex); o.uv = v.uv; return o; } fixed4 frag (v2f i) : SV_Target { fixed4 col = tex2D(_MainTex, i.uv); col = tex2D(_MainTex, i.uv + float2(-1, -1) * _BlurAmount) * 0.25 + tex2D(_MainTex, i.uv + float2(-1, 1) * _BlurAmount) * 0.25 + tex2D(_MainTex, i.uv + float2(1, -1) * _BlurAmount) * 0.25 + tex2D(_MainTex, i.uv + float2(1, 1) * _BlurAmount) * 0.25; return col; } ENDCG } } } ``` 以上代码是一个示例模糊效果的ShaderLab代码,使用了高斯模糊算法,模糊程度可以通过_BlurAmount参数进行调整。 3. 将着色器应用于UI上的材质:将新编写的着色器文件添加到Unity项目中,并在UI上的材质上应用该着色器。可以通过创建一个新材质,然后将其指定为UI元素上的材质来完成这一步骤。 4. 调整模糊效果:可以通过调整材质上的_BlurAmount属性来控制模糊效果的程度。根据需要,可以在材质上设置其他属性来满足特定的需求。 通过以上步骤,我们可以使用ShaderLab编写UI模糊效果,并将其应用于Unity中的UI元素上。这样,我们就可以在游戏或应用中实现想要的UI模糊效果了。 ### 回答3: 要使用ShaderLab编写UI模糊效果,首先需要了解ShaderLab语言和Unity引擎中UI组件的渲染方式。 ShaderLabUnity引擎中用于编写着色器程序的语言。它具有一系列的内置语法和功能,可以用来编写各种各样的着色器效果。 UI组件在Unity中使用的是Canvas渲染器。要实现模糊效果,可以在ShaderLab中定义一个新的表面着色器(Surface Shader),并在其中添加模糊效果的实现代码。 在定义表面着色器时,需要使用[vertex]和[fragment]标记来指定顶点和片段着色器函数。可以通过在片段着色器中对像素进行模糊处理来实现模糊效果。 一种常见的实现模糊效果的方法是使用高斯模糊算法。该算法通过对像素周围的像素进行加权平均来创建模糊效果。可以在片段着色器中使用多个采样点,对周围的像素进行采样,并进行加权平均来计算最终的颜色值。 除了实现模糊效果的算法,还可以通过使用Uniform变量来控制模糊的程度。Uniform变量可以在C#脚本中进行设置,并在ShaderLab中进行调用。 完成了ShaderLab的编写后,需要将其附加到一个UI组件上。可以在Unity中创建一个新的材质,并将该材质应用到UI组件上。在材质中可以选择刚刚编写的模糊着色器。 通过上述步骤,就可以使用ShaderLab编写UI模糊效果。可以根据实际需求调整模糊程度和其他参数,以达到想要的效果。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值