- Home /
lightmap transitions?
I am trying to create two lightmap sets for two times of day in the scene. The plan is to be able to transition from one to another. Using new lightmapping techniques does not seem to support that. I tried to write a shader to blend second lightmap previously generated but I realized that I do not have access to the uv set generated via Beast tool, I tried using secondary uv set but it is not the one generated while baking lightmap on an object. Is there a way within Unity I can achieve what I want? Only solution I currently see is to use external package to bake lightmaps and generate second UV set, then import them in Unity and write a shader that blends the two textures. I am hoping though that there is a way within Unity to do it. Any ideas? Thanks!
Answer by Andy Korth · Mar 24, 2011 at 09:38 PM
I've modified the mesh.uv2 before to access the beast generated light map set. Can you quick check to see if that's what you want?
I've used it to apply a generated lightmap to a new set of meshes- because we wanted to share a lightmap with a cloned world.
Edit: http://unity3d.com/support/documentation/ScriptReference/Mesh-uv2.html
Make sure "Generate UV coordinates" is checked in your mesh importer? Probably not the problem you had though...
Good luck- I do remember it was a bit finicky, but I think that was me just not understanding what was happening under the hood- unity doesn't give you too many hints.
MeshFilter meshFilter = r.GetComponent(typeof(MeshFilter)) as MeshFilter; Mesh mesh = meshFilter.mesh; Vector2[] uvs = mesh.uv2; int uvsLength = uvs.Length; Vector4 lightmapTilingOffset = r.lightmapTilingOffset; Vector2 scale = new Vector2(lightmapTilingOffset.x, lightmapTilingOffset.y); Vector2 offset = new Vector2(lightmapTilingOffset.z, lightmapTilingOffset.w);
for (int i=0; i < uvsLength; i++) {
uvs[i] = offset + new Vector2(scale.x * uvs[i].x, scale.y * uvs[i].y);
}
mesh.uv2 = uvs;
yeah, that might be the way to do it. How did you access beast's generated lightmap uv set to modify that code? thanks!
I edited my answer with some code where we change the uv2s.
Your answer
![](https://koobas.hobune.stream/wayback/20220613114710im_/https://answers.unity.com/themes/thub/images/avi.jpg)