Builtin Library
README.md
uv_rasterizer
UV-space scan-line triangle rasteriser for the lightmap bakers. Walks
every triangle of an entity's mesh, projects it into UV pixel space,
and for each covered texel writes the barycentric-interpolated
world-space position and normal. Output is two flat vec4-strided
float arrays ready for compute upload.
Exports
Rast.rasteriseEntity(entityId: string, resolution: number?) -> RasterizeResult— rasterise one entity into per-texel position + normal buffers.
Types:
FloatArray = { number }RasterizeResult = { positions: FloatArray, normals: FloatArray, texelCount: number, validCount: number }
Usage
local Rast = require("@builtin::systems.globalIllumination.uv_rasterizer")
local rast = Rast.rasteriseEntity(entityId, 64)
-- rast.positions: buffer, 64*64 texels x 4 f32 — (x, y, z, valid) per texel
-- rast.normals: buffer, 64*64 texels x 4 f32 — (nx, ny, nz, pad) per texel
Notes
- Texels with no triangle coverage have
positions[i*4+4] == 0. Bakers honour thiswflag to skip empty texels; the lightmap shader uses it as a bilinear-filter weight to mask seams. - Triangle coverage is determined via the standard edge-function test
with a
1e-6epsilon to keep adjacent triangles from leaving cracks along shared edges. - Default
resolutionis 64 when the caller passesnilor a value less than 1. - Output is in world space — vertex positions are transformed by the
entity's world matrix (
Baking.entityWorldMatrix) before being written; normals get the 3x3 portion of the same matrix.