lighting
Volumetric BFS Lighting Engine for Pyrite.
Implements a highly optimized Breadth-First Search (BFS) flood-fill algorithm for propagating sunlight and block light (glowstone) across the chunk grid. Utilizes Numba and 64-bit integer bit-packing to achieve near-native C++ speeds lock-free across background CPU threads.
- lighting.get_voxel_fast(world_x, world_y, world_z, world_voxels, chunk_positions)[source]
Numba-optimized helper to quickly retrieve a voxel ID from the global world arrays using absolute world coordinates. Returns a solid block (1) if the queried chunk is unloaded or out of bounds.
- lighting.get_light_fast(world_x, world_y, world_z, world_lightmaps, chunk_positions)[source]
Numba-optimized helper to rapidly read the packed light level (Sunlight and Blocklight) for a specific absolute world coordinate. Returns completely dark (0) if out of bounds.
- lighting.set_light_fast(world_x, world_y, world_z, val, world_lightmaps, chunk_positions)[source]
Numba-optimized helper to directly write a packed light value into the global lightmap arrays at the specified absolute world coordinate.
- lighting.propagate_light_queue(queue, tail, is_sun, world_voxels, world_lightmaps, chunk_positions)[source]
Numba-optimized Breadth-First Search (BFS) light propagation algorithm. Consumes a queue of light nodes and spreads their brightness outward into adjacent transparent blocks (air, water, glass) while respecting bounds and diminishing intensity.
- lighting.init_chunk_lighting(chunk_x, chunk_y, chunk_z, world_voxels, world_lightmaps, chunk_positions)[source]
Scans a newly loaded/generated chunk for sunlight blocks (level 15) and light-emitting blocks (glowstone). Adds these blocks to a queue and triggers their initial internal BFS propagation to light up the chunk.
- lighting.stitch_chunk_lighting(chunk_x, chunk_y, chunk_z, world_voxels, world_lightmaps, chunk_positions)[source]
Cross-chunk boundary light bleeding. Evaluates the outer borders of a given chunk against its neighboring chunks to allow light to properly spill in or out seamlessly.
- lighting.remove_light_node(world_x, world_y, world_z, light_level, is_sun, world_lightmaps, chunk_positions, refill_queue, tail_refill, queue)[source]
Strips out lighting dynamically when a light source (or opening) is blocked/destroyed. Removes any light dependent on the broken node, but captures any overlapping brighter light nodes into a refill_queue so the space can be re-illuminated by surviving light sources.
- lighting.update_light_place_block(world_x, world_y, world_z, world_voxels, world_lightmaps, chunk_positions)[source]
Executed when a player places a solid block. Strips existing light from the space and propogates a refill sequence for neighbouring light source to compensate.
- lighting.update_light_remove_block(world_x, world_y, world_z, world_voxels, world_lightmaps, chunk_positions)[source]
Executed when a player destroys a block. Allows surrounding light to flood into the newly opened space. Implements an O(1) verticle linear raycast optimization if the block broken was covering directly top-down sunlight.