How to add a Meta Pass to a custom shader to Emit light using enlighten

I’m using custom cg shaders in my game and I want one of them to emit light. It should be baked into the lightmap.

A little research showed that this has to be done using a Meta pass, but how exactly that needs to look was nowhere to be found.

In the buildin Shaders zip file I found an example though, but that does not seem to be working.

here is the Meta pass I’m currently using, as found in the
(“Legacy Shaders/Self-Illumin/VertexLit”)

        Name "META" 
        Tags { "LightMode" = "Meta" }
        Lighting on
        #pragma vertex vert
        #pragma fragment frag
        #include "UnityCG.cginc"
        #include "UnityMetaPass.cginc"

        struct v2f
            float4 pos : SV_POSITION;
            float2 uvMain : TEXCOORD0;
            float2 uvIllum : TEXCOORD1;

        float4 _MainTex_ST;
        float4 _Illum_ST;

        v2f vert (appdata_full v)
            v2f o;
            o.pos = UnityMetaVertexPosition(v.vertex, v.texcoord1.xy, v.texcoord2.xy, unity_LightmapST, unity_DynamicLightmapST);
            o.uvMain = TRANSFORM_TEX(v.texcoord, _MainTex);
            o.uvIllum = TRANSFORM_TEX(v.texcoord, _Illum);
            return o;

        sampler2D _MainTex;
        sampler2D _Illum;
        fixed4 _Color;

        half4 frag (v2f i) : SV_Target
            UnityMetaInput metaIN;
            UNITY_INITIALIZE_OUTPUT(UnityMetaInput, metaIN);

            fixed4 tex = tex2D(_MainTex, i.uvMain);
            fixed4 c = tex * _Color;
            metaIN.Albedo = c.rgb;
            metaIN.Emission = c.rgb * tex2D(_Illum, i.uvIllum).a;
            return UnityMetaFragment(metaIN);

The whole thing seems a little wonky anyway, sometime it works with the legacy self illu shader, sometimes it does not, or only after restarting.
I don’t know enough about how the system works to have an Idea what goes wrong here.
does anyone have an idea how to get this working?


Check here:

Another Simon here with the same question :smiley:
Did you find a solution?