lightCount function

int lightCount(
  1. ShaderBindings bindings,
  2. Vector3 world
)

LightCount(): the count lives in frame_params.y, not in a member of its own. Reading a member that does not exist is silent, which is how the first version of this file drew an unlit scene.

Implementation

int lightCount(ShaderBindings bindings, Vector3 world) {
  final params = bindings.vec4('FragInfo', 'frame_params', Vector4.zero());
  final list = bindings.vec4('LightListInfo', 'list', Vector4.zero());
  // `L6`: the tail is the cell's, when the draw reads one.
  // A draw with no list texture has `list.y` at nought and no cell to read,
  // which keeps the ordinary draw at the one lookup it always made.
  final tail = list.y > 0.0 && clustered(bindings)
      ? clusterAt(bindings, world).count
      : list.x;
  return (params.y + 0.5).floor().clamp(0, kMaxLights) +
      (tail + 0.5).floor().clamp(0, kExtraLights);
}