Access to directional lightmaps from CG

Is there any way to make a shader in CG that plays well with Directional Lightmaps?

I’m using the “Specular” shader and thought I’d try and translate it to CG, since it offers more functionality than I want (I don’t want to use any realtime lights) I thought I’d try and get a simpler, better performing version.

I’ve looked around for quite a while, knowing that access to lightmaps in unity in general is a bit mysterious (most of it is undocumented, you can get an idea from the UnityCG.cginc file (the DecodeLightmap is in there), but I don’t even know where knowledge of unity_Lightmap and unity_LightmapST comes from).

So is there any info out there? Anything I can read? Is it stored in unity_LightmapInd? Is there a list of all these keywords somewhere? The docs seem awfully incomplete. I haven’t found anything so far and I don’t even know where to start.

Here is the method I use, seems to work:

Declare these with the other variables about your vertex shader

sampler2D unity_Lightmap;
half4 unity_LightmapST;

Make sure your vertex output structure contains a way to hold the lightmap UV

float2 lightMapTex : TEXCOORD6;

In the vertex shader

vOut.lightMapTex = vIn.texcoord1.xy * unity_LightmapST.xy + unity_LightmapST.zw;
// vIn.texcoord1 is taken from appdata_full structure

I then sample this in the fragment shader using those UVs

float3 lightMap = DecodeLightmap(tex2D(unity_Lightmap, fIn.lightMapTex.xy));