What is a LightmapGI "slice index"?

Godot Version

4.8

Question

LightmapGIData has a “slice index” (LightmapGIData — Godot Engine (stable) documentation in English).

I’m unsure what this refers to.

Some of my current guesses:

  • LightmapGIData can have multiple lightmap_textures. It could be an index into that array.
  • Each entry in lightmap_textures is actually a TextureLayered. It could be a layer index.
  • It could be both! E.g. assume that you have textures with 2, 3 and 4 layers, slice 3 might mean the second layer of the second texture.
  • Or it could be neither!

I’ve been hunting around the engine source and I can’t quite seem to find it.

It’s a layer index into the lightmap atlas (TextureLayered / Texture2DArray).

During bake, meshes get packed onto atlas pages. Each baked user stores:

uv_scale → where on that page
slice_index → which page/layer
That comes from lightmapper->get_bake_mesh_texture_slice() and is what gets passed into instance_geometry_set_lightmap().

So not an index into the lightmap_textures array itself. Those array entries are mostly for storage (atlases get split if they’re too tall); on load Godot merges the layers into one combined TextureLayered, and slice_index is the layer in that combined atlas.

Your 2nd guess is the right idea. The “both” guess isn’t how it’s addressed at runtime.

Thank you for clarifying this!