README
======


Abstract
========

The program generates the Menger sponge, a 3D fractal first described by
Karl Menger. The Menger sponge is the three-dimensional generalization of
the Sierpinski carpet, whose first three levels are shown below:


XXXXXXXXXXXXXXXXXX        XXXXXXXXXXXXXXXXXX        XXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXX        XXXXXXXXXXXXXXXXXX        XX  XXXX  XXXX  XX
XXXXXXXXXXXXXXXXXX        XXXXXXXXXXXXXXXXXX        XXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXX        XXXXXX      XXXXXX        XXXXXX      XXXXXX
XXXXXXXXXXXXXXXXXX        XXXXXX      XXXXXX        XX  XX      XX  XX
XXXXXXXXXXXXXXXXXX        XXXXXX      XXXXXX        XXXXXX      XXXXXX
XXXXXXXXXXXXXXXXXX        XXXXXXXXXXXXXXXXXX        XXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXX        XXXXXXXXXXXXXXXXXX        XX  XXXX  XXXX  XX
XXXXXXXXXXXXXXXXXX        XXXXXXXXXXXXXXXXXX        XXXXXXXXXXXXXXXXXX


Sierpinski carpet         Sierpinski carpet         Sierpinski carpet
Level 0                   Level 1                   Level 2


The Menger sponge starts with a single cube. The first iteration divides
the cube into 27 smaller cubes and removes the center cube and its six
adjacent cubes. Each following iteration applies this recursion rule to
the cubes remaining from the previous iteration.


Levels
======

The program currently supports level 0 through 6. In the Vulkan
application, press a digit from 0 to 6 to change the level. In the legacy
application, you can also choose a level from the menu. Higher levels add
finer details that may require zooming in to see. Levels 5 and 6 can take
a long time to render, depending on your system.


Modes
=====

Both applications support “exact,” “fast,” “simple” and “stupid” modes.

The "stupid" algorithm recursively subdivides the initial cube and draws
a quad for every cube face, including faces hidden inside the object.
Each level contains twenty times as many cubes as the previous level, so
the number of quads grows by the same factor.

The "simple" algorithm also subdivides recursively, but skips quads
hidden where adjacent cubes meet.

In "exact" mode, levels above 2 are recursively built from level-2
sponges. The visible faces of a level-2 sponge were precomputed and have
been merged into larger quads. Exact mode uses quads that cover only
visible faces.

“Fast” mode reduces the quad count further by extending quads over areas
with no visible surface. However, the edges of these quads can sometimes
cause artifacts.


View
====

Drag with the left mouse button to rotate the object. Use the middle
button to zoom or rotate around the z-axis, and the right button to move
the object.


Further documentation
=====================

In 1988 I saw the Menger sponge in [1] for the first time. The Menger
sponge is also mentioned in Mandelbrot's book [2], a standard reference
on fractals. There is also a German translation [3].

[1] Franke, Herbert W., Mandelbrot und Apfelmaennchen
    in: Das neue Universum, Bd. 104, S. 328ff
    Suedwest Verlag Muenchen, ISBN 3-517-01004-9
[2] Mandelbrot, Benoit B., The Fractal Geometry of Nature,
    Freeman, 1983
[3] Mandelbrot, Benoit B., Die fraktale Geometrie der Natur,
    Birkhaeuser Verlag, Basel, Boston, Berlin, ISBN 3-7643-2646-8
