Pattern genetics

July 2024

Since genetics don't determine each individual spot and shape on a koi, siblings can look very different depending on the dice rolls of the randomizer. If pigment cells have a certain chance of turning red, it's possible that no cells turn red, or that almost all of them do. I figured out this could be a major issue for the game, since selective breeding only works if players can spot differences in genetics between siblings by looking at the patterns.

Siblings
Siblings

To make siblings look similar enough, the pigment simulation can't have too much "butterfly effects", where small initial changes have an outsized impact on the final result. At the same time, DNA shouldn't determine too much about a pattern, because that would make a school of siblings not diverse enough, and it would also require much more DNA to store all the details.

The four siblings in the image have exactly the same DNA; their differences are determined by random chance. They are still clearly the same breed, the body shapes are very similar and the amount of red pigment is roughly equal for all siblings.

Pigments
A cropped simulation

Patterns are "grown" in a rectangular space which is converted to a pattern texture. To improve performance and to prevent groups of pigments from being pushed out of the simulation, I've bounded the simulation within the range of the texture that was used. Due to the shape of koi models, between 50% and 80% of the texture is used to store pigments, and some unused space is left in the corners. This unused space may come in handy later though, since the koi still need eyes!

The animation shows a pattern simulation to a koi that looks similar to one of the four siblings shown earlier. Pigments don't ever fall outside the koi, which means I can control the proportion of colored cells well.

During the simulation, pigment cells are pushed against the borders. When a pigment spot touches the border, this can lead to a very clean spot border compared to the otherwise more organic looking shapes. To prevent this, I cull all pigment cells that touch the simulation border at the end of the simulation, which brings back some of the randomness I want to see in the spots.

Different pigment can now also exist on different layers. In koi farm 1, every color existed on its own layer only, independent of other layers of spots.

Layers
Layers

The image on the right shows a few koi with different spot patterns on separate layers that can overlap each other. It's also possible for multiple pigments to exist on the same layer, which means they interact, push each other away (or attract each other), and never overlap.

I've experimented with transparent layers as well, real koi like the Showa variant have pigments layered on top of each other with some degree of transparency. In my first experiments, this did not look good, but that may be due to the fact that pigment materials haven't been implemented yet; they're just blobs of colors without other properties or scales. This is something I may revisit later.