Meta Pass 是一个着色器通道 (Shader Pass),可为渐进光照贴图 (Progressive Lightmapper) 或 Enlighten(已弃用)提供反照率值和发光值,以便它们可以正确地从该游戏对象计算间接光照。要使某个游戏对象能够使用光照贴图或实时全局光照(已弃用),该游戏对象必须使用一个在着色器中包含 Meta Pass 的材质。
Meta Pass 提供纹理空间中的反照率值和发光值。这些值与实时渲染中使用的值是分开的,这意味着您可以使用 Meta Pass 来控制游戏对象从光照烘焙系统的角度观察的外观,而不会影响游戏对象在运行时的外观。这方面的一个很有用的例子是,您希望让悬崖上的绿色苔藓在光照贴图中生成夸张的绿色间接光,但又不想在着色器的实时通道中为地形重新着色。
Unity 的所有内置材质都具有 Meta Pass,并且标准着色器也包含 Meta Pass。如果使用了它们,则无需执行任何操作便会启用 Meta Pass。如果使用的是自定义着色器,您可以添加自己的 Meta Pass。
通过下面的着色器,可以指定仅由光照烘焙系统使用的反照率颜色和反照率纹理,而不会影响运行时的材质外观。在这个例子中,发光是从 UV 中获取的;但是可以使用任何值来控制发光。
Shader "Custom/metaPassShader"{
Properties {
_Color ("Color", Color)=(1,1,1,1)
_MainTex ("Albedo (RGB)",2D)="white"{}
_Glossiness ("Smoothness", Range(0,1))=0.5
_Metallic ("Metallic", Range(0,1))=0.0
_GIAlbedoColor ("Color Albedo (GI)", Color)=(1,1,1,1)
_GIAlbedoTex ("Albedo (GI)",2D)="white"{}
}
SubShader {
// ------------------------------------------------------------------
// 提取光照贴图、GI(发光、反照率...)的信息
// 在常规渲染期间不使用此 pass。
Pass
{
Name "META"
Tags {"LightMode"="Meta"}
Cull Off
CGPROGRAM
#include"UnityStandardMeta.cginc"
sampler2D _GIAlbedoTex;
fixed4 _GIAlbedoColor;
float4 frag_meta2 (v2f_meta i): SV_Target
{
// 我们对产生最终反照率的漫射和镜面反射
// 以及表面粗糙度颜色感兴趣。
FragmentCommonData data = UNITY_SETUP_BRDF_INPUT (i.uv);
UnityMetaInput o;
UNITY_INITIALIZE_OUTPUT(UnityMetaInput, o);
fixed4 c = tex2D (_GIAlbedoTex, i.uv);
o.Albedo = fixed3(c.rgb * _GIAlbedoColor.rgb);
o.Emission = Emission(i.uv.xy);
return UnityMetaFragment(o);
}
#pragma vertex vert_meta
#pragma fragment frag_meta2
#pragma shader_feature _EMISSION
#pragma shader_feature _METALLICGLOSSMAP
#pragma shader_feature ___ _DETAIL_MULX2
ENDCG
}
Tags {"RenderType"="Opaque"}
LOD 200
CGPROGRAM
// 这是基于物理的标准光照模型,并对所有光照类型启用阴影
#pragma surface surf Standard fullforwardshadows nometa
// 使用 Shader Model 3.0 目标以获得更美观的光照
#pragma target 3.0
sampler2D _MainTex;
struct Input {
float2 uv_MainTex;
};
half _Glossiness;
half _Metallic;
fixed4 _Color;
void surf (Input IN,inout SurfaceOutputStandard o){
// Albedo 来自颜色着色的纹理
fixed4 c = tex2D (_MainTex, IN.uv_MainTex)* _Color;
o.Albedo = c.rgb;
// Metallic 和 Smoothness 来自滑动条变量
o.Metallic = _Metallic;
o.Smoothness = _Glossiness;
o.Alpha = c.a;
}
ENDCG
}
FallBack "Diffuse"
}
在 Unity 的所有默认 Meta Pass 中,光照烘焙系统均使用 Meta Pass 来处理漫射表面和金属性表面的反照率。光照贴图程序会处理漫射传输并在每次反弹时使用表面反照率。具有黑色(或几乎黑色)反照率的金属性表面不会反射任何光线。Meta 着色器 Pass 在渲染反照率时会让其偏向具有金属色调的更亮颜色。介电材质(木材、塑料、石材、混凝土、皮革、皮肤)具有白色镜面反射率。金属具有光谱镜面反射率。如果想要改变行为,则可以创建自定义的 Meta Pass。
注意:如果使用的是 Enlighten,则播放器中的 Meta Pass 不如 DynamicGI.SetEmissive 快,但更灵活,因为您可以使用多种颜色。
Did you find this page useful? Please give it a rating:
Thanks for rating this page!
What kind of problem would you like to report?
Thanks for letting us know! This page has been marked for review based on your feedback.
If you have time, you can provide more information to help us fix the problem faster.
Provide more information
You've told us this page needs code samples. If you'd like to help us further, you could provide a code sample, or tell us about what kind of code sample you'd like to see:
You've told us there are code samples on this page which don't work. If you know how to fix it, or have something better we could use instead, please let us know:
You've told us there is information missing from this page. Please tell us more about what's missing:
You've told us there is incorrect information on this page. If you know what we should change to make it correct, please tell us:
You've told us this page has unclear or confusing information. Please tell us more about what you found unclear or confusing, or let us know how we could make it clearer:
You've told us there is a spelling or grammar error on this page. Please tell us what's wrong:
You've told us this page has a problem. Please tell us more about what's wrong:
Thank you for helping to make the Unity documentation better!
Your feedback has been submitted as a ticket for our documentation team to review.
We are not able to reply to every ticket submitted.