Animation
April 2024

To animate koi properly, a number of bones had to be added to the original model. The koi now don't just have a spine, they also have an array of vertical bones for the dorsal fin on their back, and two bones per pectoral fin. The pectoral fins seem very important for precise motion; they fold along the body when a fish is swimming fast, but fan out when slowing down. They're also used for making sharp turns, vertical motion and other small adjustments.
The skeletons were initially animated on the CPU side, which is fine when there are fewer than about 1000 koi in view, but the workload is very repetitive. Most koi have a very similar skeleton, and they're updated using the same algorithm, although different parameters specific to the koi properties and body are used by it. To allow for larger scenes with more koi, and to save battery life on slower devices, I've moved all animation code to the GPU. While the CPU updates koi positions, velocities and behaviors, the GPU interprets those parameters and calculates a fitting animation. This doesn't just run much faster, it also feels more logical to do things this way. There's no need for the CPU to know how a koi skeleton is oriented precisely; this is just a visual thing, so the animation algorithms and data can exist solely on the GPU.
Since this method makes updating animations much faster, I can now extend the koi skeletons with more bones. The tail fin is currently oversimplified, and should contain more bones to look good, especially since some koi variants have long veil-like tails. The pectoral and ventral fins can also use a few more bones to make them bend nicely when a fish swings its tail or turns quickly.