How can i output emission value to lightmap in vert/frag shader?

I can output emission value to baked lightmap with a surface shader. But how can i do it in vert/fragment shader.

I try to add a meta pass like this. Suppose to get red emission on the light map but nothing. Or did i miss something. Thanks.:slight_smile:

// ------------------------------------------------------------------
    // Extracts information for lightmapping, GI (emission, albedo, ...)
    // This pass it not used during regular rendering.
        Pass
        {
            Name "META"
            Tags {"LightMode"="Meta"}
            Cull Off
            CGPROGRAM
            #include"UnityStandardMeta.cginc"
            float4 frag_meta2 (v2f_meta i): SV_Target
            {
                // we're interested in diffuse & specular colors,
                // and surface roughness to produce final albedo.
            
                FragmentCommonData data = UNITY_SETUP_BRDF_INPUT (i.uv);
                UnityMetaInput o;
                UNITY_INITIALIZE_OUTPUT(UnityMetaInput, o);
                o.Albedo = fixed3(1,0,0);
                o.Emission = fixed3(1,0,0);
                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
        }

I have working out the code. For those whose interesting to add a emission to their shader, here is the minimal setup.

Pass
{
    Name "META"
    Tags {"LightMode"="Meta"}
    Cull Off
    CGPROGRAM
                
    #include "UnityStandardMeta.cginc"
    #pragma vertex vert_meta
    #pragma fragment frag_meta_custom

    fixed4 frag_meta_custom (v2f i) : SV_Target
    {
        // Colors               
        fixed4 col = fixed(1,0,0); // The emission color

        // Calculate emission
        UnityMetaInput metaIN;
          UNITY_INITIALIZE_OUTPUT(UnityMetaInput, metaIN);
          metaIN.Albedo = col.rgb;
          metaIN.Emission = col.rgb;
          return UnityMetaFragment(metaIN);

        return col;
    }

    ENDCG
}
1 Like