lightListTexel function

Vector4 lightListTexel(
  1. ShaderBindings bindings,
  2. int row,
  3. int column
)

One texel of the light list, at row row and column column.

Nearest and unfiltered, by the sampler the renderer binds. These are not colours: a position halfway between two lights is not a light, so anything that interpolated them would invent one. The GLSL samples at texel centres for the same reason, and this indexes the row directly, which is that arithmetic with the rounding taken out.

Implementation

Vector4 lightListTexel(ShaderBindings bindings, int row, int column) {
  final texture = bindings.textures['light_list_texture'];
  if (texture == null) return Vector4.zero();
  final width = texture.texture.width;
  final height = texture.texture.height;
  if (row < 0 || row >= height || column < 0 || column >= width) {
    return Vector4.zero();
  }
  final at = (row * width + column) * 4;
  final pixels = texture.texture.pixels;
  return Vector4(pixels[at], pixels[at + 1], pixels[at + 2], pixels[at + 3]);
}