贴花通常被用于在运行时向材质添加细节(例如子弹的冲击力效果)。贴花在延迟渲染中尤其有用,因为贴花会在被照亮前改变 G 缓冲区,从而节省开销。
常规场景下,贴花应该在不透明对象之后渲染,并且不得是阴影投射物,如下方示例中的__ ShaderLab__Unity 用于定义着色器对象结构的语言。更多信息
See in Glossary“Tags”部分所示。
Shader "Example/Decal" {
Properties {
_MainTex ("Base (RGB)", 2D) = "white" {}
}
SubShader {
Tags { "RenderType"="Opaque" "Queue"="Geometry+1" "ForceNoShadowCasting"="True" }
LOD 200
Offset -1, -1
CGPROGRAM
#pragma surface surf Lambert decal:blend
sampler2D _MainTex;
struct Input {
float2 uv_MainTex;
};
void surf (Input IN, inout SurfaceOutput o) {
half4 c = tex2D (_MainTex, IN.uv_MainTex);
o.Albedo = c.rgb;
o.Alpha = c.a;
}
ENDCG
}
}