The important thing is inside: about procedural generation of organs
(Translator disclaimer: just in case, I do not advise reading this article while eating.)
When I start to participate in gamejams, I enter the "maximum acceleration" mode, which usually ends with terrible Mondays at work after sleepless nights. The older I get, the harder it is for me to get enthusiastic to participate. Fortunately, PROCJAM is very relaxed, which is perfect for me. In addition, cheating is not prohibited there, so I could, for example, return my organ generator, which I worked on for Bestiarium a few months ago, from non-existence and create my prototype based on it.
While I am preparing a version for Vive, you can play De daemonici corporis fabrica on my page on itch.io. ')
Despite the fact that I have not touched him for quite a long time, there is an impressive array of ideas in my head in Bestiarium . But the game itself is based on a few “philosophical” points. I always saw her as a “roguelike from one room”, so the space for research inevitably moved “from outside” to “inside”, which is perfectly described by this poem by William Blake:
The sky is blue in flower, In a handful of dust, infinity; Hold the whole world in your hand To see eternity in every moment.
Such projects, in my opinion, are much more interesting if you interpret everything literally. Therefore, I decided to move in the direction of "viscera".
One of the main mechanics of the game involves the extraction of materials from creatures that you can call. You can go the standard way and pull out of them "rabbit legs" and "spider eyes", but our game is also about science. As in science, there are frequent trials and errors (and most of the time is occupied by hard work).
This was how one of the items in my design notes marked “probably won't work”: anatomizing creatures to extract organs from them. PROCJAM was obviously the perfect excuse for creating a prototype based on this idea and testing it.
De daemonici corporis fabrica (the demonic version of De humani corporis fabrica ) is trying to convey the sensations of ancient scholars who cut the corpse for the first time. Something like “I wonder why this lumpy, shriveled thing is needed?” But I was distracted. This post is about the technical side of the game. It all started with ... how the hell can you generate procedural organs in general?
It all started many months ago from the night of watching a video about an autopsy (most of the research on this topic reminded me of this article on Gamasutra). Of course, I could continue to generate corpses with previously created models of organs. But I just added a name generator on Markov's chains to the Invocation prototype, and it got me thinking: maybe it’s worth using them to generate organs that look more like “real”?
For Markov chains, we need several initial samples:
Yes, incredible 8 × 8 pixel patterns that, if you squint, are a bit like organs. First, I encoded black and white pixels as zeros and ones in the string, and then transferred it to the Markov chain — this, I was almost sure, would not work, but I wanted to take a step-by-step approach.
And you know what? Yes, I was right, glitch textures were created, because images need two-dimensional integrity. Therefore, the next step was to encode the image into groups of two-dimensional positions for all white pixels. So actually it turned out to generate some interesting results, quite convincing variations of the input information.
I decided that I needed MORE, so I increased the size of the samples to 16 × 16 pixels. It turned out that 8 × 8 is the optimal size, so I didn’t really look for ways to increase the resolution (and this was hardly the point).
Well, okay, we've got organ-like shapes, but they have low resolution and they are two-dimensional. How to add another dimension to them? The first thing that comes to mind is the use of metaspheres .
As a result, I just began to convert the image into a three-dimensional grid of 8x8x1 and transfer it to the algorithm of walking cubes (marching cubes algorithm). We got 3D, but too awkward.
I have a habit of greedy work on prototypes and gamejams. Therefore, instead of going back and bringing the metaspheres to mind, I decided to add a grid smoothing algorithm over the generated mesh.
I just threw this mesh filter from the Unity Wiki . This slightly improved the shape of the objects. But the organs were still completely flat. Then I added some random shifts along the Y axis for all vertices located on flat surfaces (i.e., the normals of which are directed exactly up or down).
And look at that. I am sure that I just have pareidolia , but I clearly see the spleen, lung, liver ... spleen ... and ... well, all sorts of organ-like forms.
When it was time to texturing, I decided to cut corners again and avoid creating UV scans of these pieces. I did some experiments with the 3D noise functions (you can take noise shaders ported by me from this repository in a convenient and hardly tested CGINC for Unity ). They looked pretty good (and I might be using them somewhere), but the cheap solution became very expensive when it took to create normal maps for textures.
As a result, a simple planar UV map (created by the location of the coordinates of the XZ vertices normalized in the UV space) turned out to be quite good. I was able to use painted textures (which not only made me disgusted when searching for photo sources, but were also retweeted by Polycount).
- What are your plans for Saturday night? - Well, you know, as usual, I will draw seamless textures of guts, and so on.
Mmm, sausages!
So, the organs are generated. But now how to shove them into the good old devil? Opening the chest is quite simple: you just need to add another key morphing phase to the demon model. But how to place the organs there?
At first, I thought that I would have to create a very complex algorithm for determining boundaries, which checks whether everything is “packed” correctly. As a result, it turned out that it is enough to add spawn points on the bones of the creature. But the problem still remains: they crawl out of the body, as seen in the areas circled in red.
Buffer template (stencil buffer) to the rescue! You can use the template buffer to create a “mask” of the chest area, and render organs only in this area.
The grid of the mask (green) is completely flat, and if you look closely, you can notice its boundaries. But even when moving, the overall effect is good enough.
Analyzing my work, I think that many of my decisions were redundant. And I could achieve a better result with the help of a good artist who would draw all these organs. But it was a fun experiment. In the end, it seems to me that the most important was the study of this uncharted territory. She is so strange and unusual that, probably, no one has wandered into it yet.