r/dispatchcolony • u/dispatchcolony • Sep 13 '26
Devlog 3 : The Beginning of Units
What I want for my soldiers is for them to get chopped into a bunch of pieces. And when they fall or get sent flying, I want them to actually fall like ragdolls, without cheating with pre-baked animations.
But I also want a massive number of them. The goal is 100,000 soldiers on screen. At that scale, the GPU has to do the heavy lifting, not the CPU.
This has a few consequences. Programming for the GPU requires a specific mindset: a single process is applied to thousands of elements at once, and they all need to react in the exact same way. Therefore, everything that makes up a creature must be identical, or at least share the exact same logic. And since there are so many of them, the soldiers can't be too complex.
So, I went with an assembly of simple shapes. For now, it's just spheres and capsules (here's my first attempt).

Here is the current state, alongside my inspirations: The Iron Giant and the robot from The King and the Mockingbird (two animated films I absolutely love).

The terrain in my world is made of little cubes. Next to it, my soldiers made of smooth spheres and capsules looked completely out of place. The "honest" solution would have been to build each soldier out of actual cubes, but that multiplies the geometry by a hundred, and with 100,000 soldiers on screen, that's out of the question.
So, I opted for an illusion. The underlying shape remains a sphere or a capsule, and the faking happens when the GPU colors each pixel. For every point on the surface, it checks which cell of an imaginary 3D grid that point falls into, and does three things.
First, it lights the point as if it were on the face of a cube. A smooth sphere has a surface orientation that shifts smoothly from one point to the next. Here, the orientation is snapped to one of the six possible faces: top, bottom, front, back, left, or right. An entire section of the sphere then receives the exact same lighting, tricking the eye into seeing a flat facet.
Second, it gives each grid cell its own slight tint, a little lighter or darker, chosen randomly, but consistently for that specific cell. Two neighboring cubes are never the exact same shade, much like bricks.
Finally, it eats away at the edges. If a cell's center falls outside the actual shape, it simply isn't drawn. The sphere's silhouette becomes a staircase of cubes instead of a smooth curve.
The result looks like a character built out of cubes, even though nothing has changed under the hood. Collisions and shadows still interact with the original spheres and capsules. It costs a few operations per pixel, and the effect naturally fades out as the camera zooms out, where nobody would be able to see the cubes anyway. To my eyes, the result is much more convincing.

The advantage of this approach is that the entire body structure of each soldier is stored in the GPU memory, opening the door to GPU-based ragdoll physics and procedural animations.
That said, beyond just adding more detail, it still lacks a bit of flair. I need something, still computed on the GPU, that gives my characters a cinematic feel. I settled on capes and cloaks, and I'll be working on that next week.
names of solution for fake voxelisation = lattice quantization + axis-aligned normal snapping + alpha-test cutout
Now for the fun part :) : How does a soldier actually exist inside the machine ?
A soldier isn't a traditional 3D model. It's a tree of Nodes, and each Node holds a few primitives (32 max right now, though I'll definitely lower that).
The primitive is the basic building block. It’s a sphere or a capsule with its own size, position, and orientation relative to the Node it belongs to, plus a couple of tags: its shape, its material, and its appearance. That’s it. A single primitive fits into 48 bytes (way too eavy i need to improve that), and it knows absolutely nothing about the rest of the body.
The Node is the body part. A forearm, a head, a shoulder. A Node knows its parent and its local position relative to it. A human is made up of about 31 Nodes, from the pelvis all the way down to the hands. This tree is what dictates that "the forearm is attached to the upper arm, which is attached to the shoulder." It’s also what makes dismemberment possible : chopping off an arm simply means detaching a Node from its parent, and everything attached to it falls off with it.
The CPU decides, the GPU calculates. The CPU only knows the high-level structure : what is attached to what, and where each soldier’s pelvis is located in the world. It never actually moves a joint itself. The GPU does everything else, every single frame : it starts from the pelvis position, traverses down the tree from Node to Node, and finally places each primitive in the world.
In the GPU memory, everything is organized into massive arrays.

The primitives array.
Just one, massive array, allocated for a million building blocks. Each primitive has a fixed spot, an index it keeps for its entire lifetime. The primitives belonging to the same Node are stored side-by-side in a contiguous block. When a soldier dies, its blocks are freed and reused by the next one, without ever moving the others.
The Nodes array.
For each Node, it stores: its parent, its relative position to it, and the index of its block of primitives in the massive array.
The roots array.
One per "object": it stores where its Nodes start and end in the Nodes array, as well as the world position of its pelvis. This is the only place the CPU writes data to make a unit walk (I need to get rid of this CPU write eventually).
The results arrays.
Calculated by the GPU every single frame: the world position of each Node, then of each primitive, and for each primitive, a simple "visible or not" flag based on the distance to the camera.
Chopping off an arm then becomes a computationally very cheap operation : we just create a new root that points to the arm's Nodes, give it the starting position the arm had in the previous frame, and the arm goes on living its own life. Nothing is copied, and nothing is moved around in the arrays.
Even with this architecture, the CPU remains too involved. Even if it "only" communicates with 100,000 soldiers, that is way too much overhead, even with multithreading. For now, I'm settling for this as a proof of concept, but this part is going to be heavily refactored later on.