API Reference · Lights

LightCollection

Namespace: Ava3D

public sealed class LightCollection

The lights in a scene, in the order they were added.

A list rather than a fixed set of slots, because the number of lights a renderer will draw is a property of the renderer and not of the scene — see LightCollection.Capacity for the number that is true everywhere, and RenderInfo.Features for what the one you got will do.

Properties

MemberDescription
int Count { get; }

Number of lights.

Light Item { get; }

The light at index.

Fields

MemberDescription
static int Capacity

A floor, not a limit. The fewest lights any renderer here has ever drawn, and therefore the number to write a scene against if it has to look identical on every device.

It is not what the renderer you got will do. Metal, Vulkan and the software renderer draw as many lights as they are given; only OpenGL has a ceiling, because its light loop has to be sized when the shader is compiled, and even there a current context builds for far more than this. The number that is actually true of the running renderer is RenderInfo.LightCapacity — read that one before deciding to throw a light away, because a scene that sorts its lights by distance and keeps sixteen is discarding lights three of the four backends would have drawn.

Nothing about this is a budget: a scene with two lights is not spending two-sixteenths of anything, it is drawing two lights.

Methods

MemberDescription
void Add(Light light)

Adds a light. Past LightCollection.Capacity it is drawn by some renderers and not others — see the notes on this type — and is otherwise ordinary.

void AddRange(IEnumerable<Light> lights)

Adds several lights, invalidating the scene once rather than per light.

void Clear()

Removes every light. The scene keeps its EnvironmentLight.

bool Contains(Light light)

Whether the scene holds this light.

List<Light> GetEnumerator()

A struct enumerator, so reading the lights allocates nothing.

int IndexOf(Light light)

Where light sits in the list, or −1 when it is not in the scene.

void Insert(int index, Light light)

Adds a light at index, shifting the rest along.

Position is not decoration here. The first DirectionalLight in this list is the scene's key light: it is what Scene.Light returns, the direction the night-side mask and the rim's sunward bias mean by "the light", and the only one whose ambient floor counts. Inserting at 0 is how a light becomes the key light without taking the others out and putting them back.

bool Remove(Light light)

Removes a light. Returns false when it was not in the scene.

void RemoveAt(int index)

Removes the light at index.

void Replace(int index, Light light)

Replaces the light at index.

See also