Log inGet started
Package

Swarm.module

Newest version

README.md

Swarm

Draws the locusts — the player's cloud and one per rival — and the shadows they drag over the farm.

Each cloud is a single mesh and a single draw call. A compute shader (locustFlight) owns the mesh's vertex buffer and rewrites every locust each frame: six vertices and four triangles per insect, placed in a churning, lobed ellipsoid, turned onto the cloud's flight direction with a per-insect weave, rolled into the bank of the turn, wings beating several times a second. Luau hands it two dozen floats a frame — where the cloud is, how wide, which way it is heading, how hard it is rolling, where the camera is — and queues the dispatch. No per-locust work ever touches the CPU.

A locust is 7 cm long, which from a chase camera a hundred metres back is a fifth of a pixel. Rather than draw them oversized, the shader holds every body to a minimum screen size: it turns each insect's depth into metres-per-pixel and grows the body only far enough to keep about three and a half pixels. Close up they are exactly life-size; far away they stay resolvable. Because the camera pulls back as the swarm grows, distance and cloud radius rise together and cancel — so what the player sees getting thicker is the headcount.

Published on Locust.systems.swarm:

CallDoes
setCount(n)draw n locusts in the player's cloud (never below the floor)
count()how many are being drawn right now
setCloud(x, y, z, r)where the player's cloud is and how wide
setRivalCloud(i, x, y, z, r)the same for rival i
report()every cloud's population, geometry, bounds and dispatch health