$ show jgayfer/bevy_light_2d
bevy_light_2d is a Rust library providing 2D lighting functionality for the Bevy game engine. It implements point lights, spot lights, light occlusion (shadows), and ambient lighting through a multi-pass rendering system using signed distance fields (SDF) and ray marching. The architecture follows Bevy's ECS pattern with a plugin that integrates into the render graph, separating extraction, preparation, and rendering phases. The library demonstrates solid software engineering practices with clear separation of concerns and implements non-obvious graphics techniques for efficient shadow calculation.
The LLM identified 2 files worth highlighting for reuse:
Implements a signed distance function for 2D rectangles used in occlusion testing. This self-contained function calculates the distance from a point to a rectangle, enabling efficient shadow determination through ray marching. Demonstrates knowledge of computer graphics techniques for real-time occlusion.
Contains two key reusable functions: 1) A physically-based light attenuation function that implements an inverse square variation with falloff control, and 2) A spotlight masking function that creates smooth conical light beams using inner/outer angles and smoothstep interpolation. Both are self-contained and demonstrate research into lighting models.