Using the Lightmap UV texcoords in a Unity 5 Surface Shader?

This seems like a really simple thing to do, but is apparently not as easy as I thought.

I wish to use a surface shader which uses the “Standard” lighting model (to get access to U5’s new PBR lighting, etc, etc.). I want to use a surface shader so that I get lighting, lightmap sampling, etc. all for ‘free’ and don’t have to implement them. Basically, this shader should be indistinguishable from things already shaded using “Standard”.

I would like to use the static lightmap UV texture coordinates in my surface shader. I want to use them to sample an unrelated texture, and depending on the result of that sample, modify the surface color or other properties.

I have found that I can texture sample unity_Lightmap (using say, the main UVs) and it will show the lightmap texture for the object. However, all attempts to get access to the Lightmap UVs have failed.

I tried directly accessing the unity_LightmapST uniform, and while it compiles, it seems to have a value of 0 for all pixels.

The documentation says that for the Surface Shader Input structure, “Texture coordinates must be named “uv” followed by texture name (or start it with “uv2” to use second texture coordinate set).”. However, attempts to get this to sample the lightmap uvs (and not the 2nd uv set of the models) have failed.

I tried using the TEXCOORD1 semantic in the Input structure, but this appears to be ignored.

Shader Sourcecode Here. I am applying this to a mesh which has “Lightmap Static” checked, and has lightmaps generated for that mesh. The lightmap UVs for this mesh can be seen here, and you can see how it does not interpolate the color based on the X position of the lightmap UVs.

Thanks!

Up ! I have the same issue thanks…