Why is there no example for “MeshRenderer.enlightenVertexStream”?
What is required for this enlightenVertexStream to be valid and only override lightmap uvs at runtime?
I can find almost nothing about this online and the documentation is almost useless here. By default enlightenVertexStream is null, which means I have to create a new Mesh BUT I only want to override lightmap uvs not the entire mesh data. Is this even possible in Unity?
Even ChatGPT is totally confused on what is required to get this object working.
enlightenVertexStream is specifically for Enlighten Realtime GI, not for regular baked lightmaps. Are you trying to affect Realtime GI, or just regular lightmaps?
Specifically I was looking to swap out lightmaps at runtime. Currently this works if all objects in scene are the same. However if any object is added or removed the lightmap UVs change and not just their offsets.
My other option is to use additive scene loading to swap out the same scene with different times of day. But I was hoping to just add support for this add/remove objects between bakes in a tool I’ve had around for a while.
The project I’m testing this in is located here: GitHub - zezba9000/UnityLightingManager: Quickly test in Editor and change at runtime: lightmaps, lightprobes and other scene objects.
It sounds like you are just talking about regular baked lightmaps then? To reiterate, unless you have Enlighten Realtime GI enabled, the enlightenVertexStream property is completely irrelevant. I’ll assume you are not using Realtime GI, let me know if that is wrong.
However if any object is added or removed the lightmap UVs change and not just their offsets.
This doesn’t sound right. Lightmap UVs are per-mesh (not per scene object), and are calculated or imported by the mesh importer. They should never change due to changes in a scene. A scene objects final location in the lightmap is determined by its lightmap UVs, and by its scale and offset (MeshRenderer.lightmapScaleOffset). The scale and offset is calculated automatically during a packing step, which groups objects together into lightmaps.
Indeed, if you add or remove objects from a scene, the resulting packing will change, and the remaining objects may end up in a different location in the lightmap, or a different lightmap entirely. We currently don’t provide any control over packing - you cannot specify your own lightmap layout to use for baking. It’s a pain point and something we have on our roadmap to address in the future, but for now, if you want to swap out different sets of baked lightmaps, my best advice is to ensure that the lightmaps are baked from scenes with identical scene objects. Alternatively you can store the scale and offset and lightmap index of every scene object alongside your sets of lightmaps, and swap these out as well when you swap the lightmap textures.
Let me know if any of that helps, or if you still have questions
Ok so what I was doing was correct then. I was restoring lightmap index and offset but for some reason it doesn’t work even though I can see everything is restored correctly here.
Wonder if there is some Apply like method that needs to be called after changing the lightmap index/offset.
Are you using static batching? If so, try turning it off in your Project Settings