- Home /
Re-use lightmap for different mesh with same lightmap uvs
Hello,
I have recently started looking into Unity light baking, and the SRP (Unity 2019.3.8f1). I have followed catlikecoding's series on the SRP to create a renderpipeline from scratch, which also supports lightmaps. So far so good.
Currently, I am working on geometry that needs to be created at runtime, even though I can create a version of the exact same geometry in the editor. This object can be static, and since it is quite high on polycount, I would like to include it in the lightmap.
And this is my problem: how to have a static, lightmapped mesh, that gets created at runtime through a new Mesh(), where the GameObject is static and the Mesh has appropriate lightmap uvs.
I have tried the following: - Instantiate the Mesh in the editor, with lightmap uvs, and made static. - Bake the lightmap - Delete the temporary Mesh GameObject - Run the game and create the mesh at runtime on a new static GameObject
This goes fine until I try to run the game. The lightmap actually includes the map for the Mesh, but when I run the game, the Mesh simply does not have the lightmap applied. I am not sure if this is possible or what I need to change in the MeshRenderer/Material/Renderpipeline to make the Mesh use the lightmap. It is ready, static, and with lightmap uvs, but somehow it does not get them assigned.
In the editor, the temporary mesh shows up in the lightmap as a wireframe (in the "Baked Lightmaps" preview), but when I run the game, all other baked geometry shows up as wireframe, but not the created mesh.
And yes, it is important that the mesh be created at runtime. I will not go into details, but I cannot simply keep the Mesh that I instantiated in the editor. I really need to re-create it at runtime. But I CAN ensure that the lightmap uvs are the same.
If anyone can point me in the right direction, it would be greatly appreciated :)