Article
All Hail the Superformula
Published 3 years ago
500
0
Creating procedural flowers
My name is Owen Bell, and this is the story about my experiences with a very special little piece of math, and how it helped shape the procedural flowers of my game Mendel.

The superformula is a pretty amazing equation. With just a few variables it can produce a whole host of different shapes. Originally discovered by a Belgian geneticist named Johan Gieles in 2003, he named it the superformula both because of the earlier equation it was named after, the superellipse, but also after his astonishment at the sheer range of shapes that his formula could produce. Describing his discovery to Nature he said, “It seemed too good to be true - I spent two years thinking ‘What did I do wrong?’ and ‘How come no one else has discovered it?’”
I first came across the superformula because of its use in No Man’s Sky. Being such a prominent game centered around procedural generation, No Man’s Sky has been a constant source of both inspiration and technical guidance for my work on Mendel. In their case, Hello Games is using the equation to help them build their landscapes. It pushes up mountain ranges, carves out valleys, and shapes craggy hollows across the quadrillions of alien worlds. With this kind of endorsement, I decided to experiment with using the superformula myself.

Originally, my plan was to simply use the formula as a starting point to help me develop my skills with procedural models and give me a quick way to create a prototype. My first pass at the superformula was a little toy that let you play with each of the 6 “genes” that controlled the shape of the formula, the variables a, b, m, n1, n2, and n3. By adjusting sliders the players could create the wide variety of different shapes that the superformula offered.
Since Mendel is a game about breeding new creations, though, I wanted to make a prototype that actually let players use those skills. My next experiment with the superformula, then, was to use it to create actual objects that the player could pickup and move around. By pointing the object they held at a another object, the player could mixing the two shapes together to create a child that was the average of its two parents, with some mutation thrown in.

This very simple system proved far more effective than I expected. The basic play of mixing two things together to see what they produced was extremely satisfying, and players began cultivating specific kinds of creations in this prototype. One group of players competed to see who could create the largest possible shape while another player instead made a garden of tiny bowties.

During my time developing these prototypes, I made a realization about the shapes that the superformula was producing. In their many different permutations, whether multi-lobed or smooth, spikey or curved, symmetrical or widely off-kilter, the shapes the superformula was producing looked strikingly like flowers. Their huge spins and sharp petals looked like they could be the flowers in an alien rainforest, perfect for the distant world of Mendel, so I set out to begin adapting the formula to produce my flowers.
Originally, I was thinking that I could create the meshes by only taking half of the shape created by the formula. This would yield a nicely rounded and petaled shape that I could then fix to the edge of the branches. Implementing this turned out to be more complex than I thought, though. Lots of ugly calculations to make the shape come together cleanly in the back and it was just turning out to be more trouble than it was worth. That’s when I hit on another idea.
Rather than creating the entire flower in three dimensions, I could instead create the flower more simply in two dimensions, and then translate that flat shape into three. I started with a mesh made up of a series of expanding rings, each ring modeled using the same values for the superformula variables. Once that was done, I then pulled each ring up along the y-axis using a sine wave, while the center vertex was left in place. Even applied to a mesh made up of only 3 or 4 rings, this gave a nice, organic-looking curve to the shape.
The results were compelling straight away. Even this basic system that made untextured black and white models was producing shapes that looked recognizably like flowers.

Using this very simple base, I began expanding what the system could do. I added variance to the height and radius of the flowers and expanded the bending of the sine wave so petals could curve back on themselves. Using vertex colors to apply separate colors to each of the triangles gave the flowers vibrance and complexity. With these basic additions, the system has proved so flexible that I am continuing to use it almost unchanged months later to create the flowers in Mendel.

If you are at all interested, I highly recommend playing with the superformula to see what it can do. You can find a simulation of it here, but building your own implementation to mess around with is not difficult at all.
Other Projects