Real-time lightmap UVs
Learn how Unity computes real-time lightmap UVs.
阅读时间2 分钟最后更新于 1 个月前
Real-time lightmap UVs are per-Mesh Renderer: all instances of the same mesh share the same input data, but different Mesh Renderer instances can use different real-time lightmap UVs at runtime. Unity calculates the UVs for the Realtime Global Illumination system during the precompute stage. This calculation takes per-mesh UVs as input and produces per-Mesh Renderer UVs. Unity can generate the input per-mesh UVs when you import a model, or you can provide your own data.
This works as follows:
- Unity can use data in the Mesh.uv3 channel as input for the real-time lightmap UV calculations. maps to the TEXCOORD2 shader semantic and is commonly called UV2.
Mesh.uv3 - If there's no data in , but there's data in Mesh.uv2, Unity falls back to using the data in
Mesh.uv3as input for the real-time lightmap UV calculations. Unity usesMesh.uv2for baked lightmap UVs. It's common to use the baked lightmap UVs as input data for the real-time lightmap UVs.Mesh.uv2 - Unity stores the results of the calculations per-Mesh Renderer, in MeshRenderer.enlightenVertexStream. When you enable Realtime Global Illumination and a given Mesh Renderer contributes to global illumination and receives its global illumination from lightmaps, Unity automatically passes the data in to TEXCOORD2 in shaders, instead of the data in
MeshRenderer.enlightenVertexStream.Mesh.uv3
For more information, refer to Generating lightmap UVs.
How Unity calculates real-time lightmap UVs
This is what happens when Unity takes the per-mesh input UVs and processes them into per-Mesh Renderer output UVs.
Merging
Optionally, you can instruct Unity to merge UV charts where possible during this process. This reduces the size of the lightmaps and can improve runtime memory usage and performance.
Enable this optimization on any GameObject with a Mesh Renderer component. In the Mesh Renderer Inspector, navigate to the Lightmapping section and enable Optimize Realtime UVs.