Version: 2019.4
ライトマップ - 技術的な情報
Lightmap UVs

Lightmapping and the Shader Meta Pass

A Meta Pass is a Shader pass that provides albedo and emission values to the Progressive Lightmapper or Enlighten (deprecated), so that they can correctly compute indirect lighting from that GameObject. For a GameObject to work with lightmapping, or with Realtime Global Illumination (deprecated), the GameObject must use a Material that has a Meta Pass in its Shader.

The Meta Pass provides albedo and emission values in texture space. These values are separate from those used in real-time rendering, meaning that you can use the Meta Pass to control how a GameObject looks from the point of view of the lighting baking system without affecting its appearance at runtime. An example of when this would be useful is if you wanted the green moss on a cliff to generate exaggerated green indirect light in your lightmaps, but you didn’t want to recolor the terrain in the real-time pass of shader.

All of Unity’s built-in Materials have a Meta Pass, and the Standard Shader contains a Meta pass. If you are using these, you do not need to do anything to enable the Meta Pass. If you are using a custom Shader, you can add your own Meta Pass.

メタパスを使ったシェーダー例

The Shader below allows you to specify an albedo color and albedo Texture that are used only by the lighting baking system, without affecting the appearance of the Material at runtime. In this example, emission is taken from the UVs; but any value could be used to control it.

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
        {
            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
        // 体裁のよいライティングを得るためにシェーダーモデル 3.0 target を使用。
        #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"
}

Technical information

In all of Unity’s default Meta Passes, the lighting baking system uses the Meta Pass to handle albedo for both diffuse and metallic surfaces. The lightmapper handles diffuse transport and uses surface albedo on each bounce. Metallic surfaces with black (or almost black) albedo do not bounce any light. The Meta Shader pass that renders albedo biases albedo towards a brighter color with the hue of the metal. Dielectric materials (wood, plastic, plastic, stone, concrete, leather, skin) have white specular reflectance. Metals have spectral specular reflectance. If you want a different behaviour, you can create a custom meta pass.

Note: If you are using Enlighten, the Meta pass in the Player is not as fast as DynamicGI.SetEmissive, but it is more flexible because you are not limited to a single color.

ライトマップ - 技術的な情報
Lightmap UVs