Wang Tiles For Image and Texture Generation
Wang Tiles For Image and Texture Generation
Abstract means to overcome this problem is to create (or capture) a small ex-
ample of complexity and then reuse this example many times. Un-
We present a simple stochastic system for non-periodically tiling the fortunately, when the same example is used many times in a periodic
plane with a small set of Wang Tiles. The tiles may be filled with fashion, the repetition is often apparent and distracting.
texture, patterns, or geometry that when assembled create a contin- We present a new stochastic algorithm to non-periodically tile the
uous representation. The primary advantage of using Wang Tiles is plane with a small set of Wang Tiles [Wang 1961; Wang 1965]. This
that once the tiles are filled, large expanses of non-periodic texture allows Wang Tiles to share the efficiency of reusing example tiles
(or patterns or geometry) can be created as needed very efficiently to create large expanses of complex texture, patterns, or pre-lighted
at runtime. geometry at runtime, while avoiding the obvious visual artifacts of
Wang Tiles are squares in which each edge is assigned a color. periodicity.
A valid tiling requires all shared edges between tiles to have Wang Tiles are a set of squares in which each edge of each tile is
matching colors. We present a new stochastic algorithm to non- colored. Matching colored edges are aligned to tile the plane. We
periodically tile the plane with a small set of Wang Tiles at runtime. demonstrate that as few as eight tiles are needed to non-periodically
Furthermore, we present new methods to fill the tiles with 2D tex- cover the plane. We present new methods to fill the tiles with 2D tex-
ture, 2D Poisson distributions, or 3D geometry to efficiently create ture, 2D Poisson distributions, or 3D geometry to efficiently create
at runtime as much non-periodic texture (or distributions, or geom- at runtime as much non-periodic texture (or distributions, or geom-
etry) as needed. We leverage previous texture synthesis work and etry) as needed. We apply these results to modeling and rendering
adapt it to fill Wang Tiles. We demonstrate how to fill individual problems.
tiles with Poisson distributions that maintain their statistical proper- Wang Tiles only define matching edge constraints. This is insuf-
ties when combined. These are used to generate a large arrangement ficient to maintain coherent features that cross more than one edge
of plants or other objects on a terrain. We show how such envi- (i.e., corners). To accommodate such features, we extend the notion
ronments can be rendered efficiently by pre-lighting the individual of Wang Tiles to include corner constraints in the spirit of [Neyret
Wang Tiles containing the geometry. and Cani 1999]. The increase in degrees of freedom also allows us
We also extend the definition of Wang Tiles to include a coding to modulate the texture by mixing two source textures.
of the tile corners to allow discrete objects to overlap more than one
edge. The larger set of tiles provides increased degrees of freedom.
1.1 Relation to Previous Work
CR Categories: I.3.3 [Computer Graphics]: Picture/Image Gen-
eration - Viewing Algorithms— [I.3.6]: Computer Graphics— There are a variety of methods where small samples are used to gen-
Methodology and Techniques erate more complex patterns. Much of the research involved in these
methods strive to avoid visual artifacts arising from repeatedly using
Keywords: non-periodic tiling, Poisson distributions, texture syn- the same sample data. Related work can be divided into two groups:
thesis, Wang Tiles 2D- and 3D-texturing methods, and geometry creation for com-
plex outdoor scenes and related level-of-detail methods. We also
touch on the relation of Wang Tiles to the broader literature on tiling.
1 Introduction
Texture Synthesis: Stam was the first to consider the use of
Modeling and rendering scenes that capture the complexity of the square Wang Tiles for texture synthesis [Stam 1997]. Based on a
real world is a difficult and time consuming task. A now well-known deterministic algorithm that uses a set of 16 tiles with colored edges
[Grünbaum and Shephard 1987] he created large non-repetitive tex-
tures, water surfaces and caustics by defining texture samples on
the tiles following the border constraints introduced by the shared
edges. In his paper, he describes the construction of a limited set of
patterns. A general algorithm for filling the tiles and quickly assem-
bling a tiling is not given. We extend his work in these directions.
Recent work in texture synthesis provides a means to avoid repe-
tition in two dimensions by using a small texture tile as an example
that is then used to create a larger amount of non-repetitive texture
that has the same visual properties.
Wei and Levoy [Wei and Levoy 2000] use a statistical model that
selects a pixel of the given texture by analyzing the local neighbor-
(a) (b) (c) (d)
Figure 1: a) Eight Wang Tiles that can stochastically tile the plane; b) A small portion of the plane with a valid tiling. c) 12 Wang Tiles
constructed from two horizontal and three vertical colors; d) 18 Wang Tiles constructed from three horizontal and vertical colors.
hood of the pixel in the so far synthesized texture. Efros and Free- 2 Wang Tiles
man [Efros and Freeman 2001] randomly select square regions from
the sample image and fit (or quilt those parts to the already created A Wang Tile set consists of square tiles with color-coded edges. The
large texture. One of the challenges in this work is to maintain the squares cannot be rotated. A valid tiling of the infinite plane con-
visual appearance of large coherent regions. The work cited above sists of any number of copies from the set laid down such that all
achieves these goals at a computational and storage cost. We lever- contiguous edges have matching colors. This tiling is named after
age these results to fill a small set of Wang Tiles, such that the re- Hao Wang who conjectured in 1961 that any set of tiles that can
sultant tiling maintains the ability to include large coherent features. produce a valid tiling of the plane must also be able to produce a pe-
The tiling itself mitigates the computational and memory require- riodic tiling of the plane [Grünbaum and Shephard 1987]. This was
ments when creating large textures. later refuted in a series of papers that eventually led to a set of only
13 tiles discovered by Culik that could be shown to be strictly ape-
Several algorithms have been proposed to extend the methods riodic1 [Berger 1966; Culik II 1996; Kari 1996]. Theoreticians have
to arbitrary surfaces [Turk 2001; Wei and Levoy 2000; Tong et al. taken an interest in aperiodic sets, using them to simulate the proper-
2002], but these create large textures to cover the entire geometry. ties of proposed DNA computers, and have shown they can simulate
The work presented here is most closely related to the non-periodic any Turing machine. They have even been featured in a leading role
texture mapping method based on triangles presented by Neyret et in a science fiction story, “Wang’s Carpets” by Greg Egan. We will
al [Neyret and Cani 1999]. Using this kind of mapping, they are not draw on these more theoretical aspects of Wang Tiles, but rather
able to texture a variety of objects. Because the triangles are rotated on their simplicity; specifically, that they are square and that a small
to achieve a mapping, triangles are not well suited for textures set can lead to a non-periodic tiling of the plane.
with directional content such as strokes or oriented patterns. Wang
Tiles avoid these problems since they are square and cannot be
rotated, but the tilings are restricted to surfaces that map to a plane.
The triangle rotation also requires the edges to have an orientation
effectively doubling the number of colors. Beyond these differences,
we focus in this paper primarily on new methods to construct the
tile interiors themselves.
If the set contains at least two tiles for each NW combination (i.e.,
2 × K 2 ), then there are always at least two choices at each step. If
this choice is made with uniform probability, the plane will always
be tiled non-periodically because each step reduces to an indepen-
dent random process (i.e., a coin flip). One such set of 8 tiles with
2 colors is shown in Figure 1(a). Note that there are, in practical
terms, only two colors since the red and green used for the NS edges Figure 3: Two interactively designed eight tile sets to the left of
could be replaced with the blue and yellow of the EW edges with no resulting tilings.
change in the set.
In Figure 1(a) tiles a through d contain all NW combinations as
do tiles e through h. The SE edge combinations are also each rep-
resented twice thus tilings can proceed from south to north as well. 3.2 Automatic Tile Design for Texture Synthesis
Many other sets are possible with all required properties. A valid To create a continuous texture from a sample, textures must be found
tiling of a small portion of the plane may look like Figure 1(b). for each tile that fit together across the boundaries with matching
This simple algorithm results in tilings that have a random ap- colors. In our variant of the algorithm we generate such textures.
pearance as can be seen in Figure 2(a)-(d). In Figure 2(a) a tiling A tile is created by combining diamond shaped (squares rotated by
constructed from the tile set of Figure 1(a) is shown. Each tile was 45 degrees) sample portions of the source image, one for each edge
given its own color to make them distinguishable from one another. color of horizontal and vertical edges. Therefore, for a set of eight
In Figure 2(b) a deterministic aperiodic tiling [Grünbaum and Shep- tiles we need four sample images, and for the set of 18 tiles six
hard 1987] of 16 tiles can be seen to still contain some repetitive sample images.
appearance. Figures 2(c) and (d) show larger parts of stochastic and
deterministic tiling.
Often larger sets of tiles are needed to fully avoid artifacts. Us-
ing three horizontal colors results in 12 tiles (Figure 1(c)) and using
three horizontal and three vertical colors results in 18 tiles (Figure
1(d)). The main advantage of a larger set is that it can substan-
tially reduce repetition artifacts as in Figure 6(d). Another advan-
tage is that using such a set we are able to introduce larger patterns
to the tiling of the plane. We will further address these issues in Sec-
tion 3.5 by introducing inhomogeneity into the tiling patterns. But (a) (b)
first we continue by describing our methods for creating valid tile
sets for two dimensional applications such as textured surfaces or Figure 4: a) Four subimages are combined to form each Wang Tile;
non-repetitive drawings. b) construction of an eight tile set.
2 The orientable triangles in Neyrets work [Neyret and Cani 1999] would The set of Wang Tiles can also be generated automatically. Our
require (2K)2 /3, K is effectively doubled by the orientation, but reduced method is derived from work by Efros and Freeman [Efros and Free-
by a factor of 3 since each triangle has 3 edge pair possibilities. man 2001]. In their method a large texture is created from small
(a) (b) (c) (d)
Figure 6: a) Source image; b) texture generated using image quilting; c) 18 Wang Tiles automatically generated based on set in Figure 1(d);
d) resulting part of infinite texture (8×6 tiles) with some tile instances highlighted.
monds that correspond to the edge colors of the tile. In this case
we have to find four cutting paths to combine the four samples to
form the tile (cf. Figure 4(a)). This is done using the optimiza-
tion algorithm given in [Efros and Freeman 2001]. Next, the four
combined samples that together have a diamond shape are cut along
their diagonals. This forms the final tile slightly smaller than the
sample diamonds due to the samples’ overlap. Because the same
image sample is used for all tiles that share the edge color the tiles
will always fit together. If the north edge of a tile is colored red, the
lower diagonal part of the “red” diamond is used for synthesizing
the upper part of tile, and vice versa for a red south edge. Figure 4
illustrates this process and its use on a set of eight tiles. Figure 5
shows a pseudo-colored result of a tiling with these eight tiles.
Some visible artifacts may remain (see Figure 8) for two reasons:
(1) because so few sample patches of the original texture are used,
Figure 5: A 32×32 pseudocolored tiling where each diamond shape and (2) due to artifacts introduces by the Efros’ quilting algorithm.
color represents the label of the sample chosen, or equivalently, one The first reason can be overcome, albeit at some cost, by increasing
of four edge colors. This shows the non-periodicity achieved with the number of tiles. Often one can effectively reduce the artifacts,
only four subimages. without increasing the number of tiles, by minimizing the quilting
errors. To do this, we iterate over sets of samples. For each set, its
overall quilting error is the sum of the pixel color errors that occur
along all cutting paths (e.g., 32 paths for the eight tile set). If the
square sample images obtained randomly from the source image. error is too high, four new sample images are selected, the paths are
The sample is fitted to the already created image by optimizing a calculated and the overall error is computed. This is repeated until
cutting path in an overlapping region. If the color differences of the a small overall error is obtained or a preset number of iterations is
pixels along the cutting path are below a given threshold, the sample completed.
image is added to the texture. In our trials, a set of eight tiles requires about 3 seconds of opti-
Each tile is now constructed by combining the four sample dia- mization to produce good fitting tiles. An 18 tile set takes 15 sec-
Poisson disc distributions: To represent distributions, the tiles
each contain a set of point positions. The goal is find a set of point
distributions on each tile, that when combined will result in an over-
all distribution with desired properties. Purely random distributions
are trivial to create by simply placing random positions on the tiles.
When combined, the overall distribution remains random since there
are no dependencies between points.
However, in many cases purely random distributions are not the
best choice. In a crowd each person might position themselves to
leave a certain distance from any other person. Biological and en-
vironmental forces also do not lead to random placements of plants.
In both cases the distribution can often be described by a so called
Poisson disc distribution that avoids crowding. In such a distribu-
tion, a small disc around each object defines a region in which no
other object of the distribution is found.
Figure 8: An example of a synthesized texture where the diamond Using Wang Tiles, the challenge is to find positions on each tile
shaped artifacts are apparent. that generate a Poisson disc distribution across all possible tilings.
This presents a challenge since points placed near the border of a
tile have influence on the placement of points in any other tile with
onds on a standard PC with 2 GHz. Once the set of samples is found, a matching opposite edge.
the generation of large textures is very fast. This is a major advan- Often, dart throwing is used to generate Poisson disc distribu-
tage of tiling or pattern based methods over other texture synthesis tions: a series of random positions is created one at a time (the
techniques where the creation of texture is dependent on the overall darts). Each position is added to the already generated point set if
amount of texture required [Wei and Levoy 2000; Efros and Free- it does not overlap with any of the discs of points already inserted.
man 2001]. This works fine (given infinite time) for an infinite plane but is
Figure 6 shows some results. A small image showing some not sufficient in the case of Wang Tiles. If a dart falls near a tile
daisies in a meadow is selected (a). In (b) a texture created by the boundary, one has to check all the discs of all points that possibly
original image quilting algorithms is shown. The tiles of an eighteen lie on the opposite tile with the same edge. In essence, for a point
tile set are given in (c). (d) shows the result if 8×6 tiles are com- near a border, part of its disc is repeated in all possible neighboring
bined. Figure 7 shows some other examples of images generated by tiles. Thus, the total area in all tiles that cannot accept a new dart
eighteen Wang Tiles. due to this point is larger than one disc. This causes less points to
be inserted near the border (see Figure 9) distorting the distribution
in the overall tilings.
3.3 Automatic Tile Design for Object Distributions
Figure 11: The corner problem: a) A Wang tile with all combinations of marked corners. b) Tiling from the expanded tile set that shows various
combinations of marked/unmarked tile corners. Constructing an inhomogeneous tiling: c) two source images; d) tiling that contains density
information. e) a tiled plane (12x12) constructed from a tile set with inhomogeneities.
Lloyd’s method: An alternative for creating Poisson disc distri- paragraph, the solution also offers the possibility to generate tilings
butions is to use Lloyd’s method to optimize an initial set of point that contain inhomogeneities.
positions [Deussen et al. 2000; Hausner 2001; McCool and Fiume A solution is found by coding the corners of a tile as an addi-
1992]. Lloyd’s method has the advantage over dart throwing in that tional bit of information, essentially coloring the corners as well as
points can interact with each other. the edges3 . For a single tile, 24 = 16 possibilities of corner codings
A starting Poisson distribution point set is created independently can occur (cf. Figure 11(a)). A set of tiles with two colored edges in
in each tile. Then, one tile is selected and surrounded by 8 tiles from this case is expanded to 16×8=128 tiles. The number can be reduced
the set. A Voronoi diagram is constructed across the nine tile set, to 64 tiles and still maintain the stochastic selection since there are
and the points within the selected center tile are relaxed to satisfy only three corners that must match as each tile is inserted. In the ex-
the Poisson disc constraints across the tile boundaries. The local panded set for each of these two possibilities all corner combinations
tilings and relaxation steps are repeated several times for all tiles in the tile have to be stored. In Figure 11(b) a tiling with marked and
until the distribution stabilizes. This results in consistent appearing unmarked corners in arbitrary combinations is shown.
point distributions, such as one shown in Figure 10 for a set of eight
Wang Tiles. Details and a numerical evaluation of this optimization
process can be found in Hiller et al. [Hiller et al. 2001] and as an 3.5 Introducing Inhomogeneity
application to sampling in Deussen [Deussen et al. 2000]. Figures So far the generated textures and distributions are quite homoge-
12 and 13(e) show this process applied to positioning sunflowers in neous. The selection process for textures and object positions en-
a simulated sunflower field. ables us to avoid visible patterns, but the generated textures appear
uniform. To improve the appearance it would be helpful to allow the
3.4 The Corner Problem tiling process to locally change the texture content.
The corner marked tile sets can help here. To create an inhomoge-
Edge coloring and the texture synthesis process ensures that the tiles neous tiling, the texture synthesis process takes two source images
always fit together. But a problem arises if an object or a visible instead of one. The tiles are generated by choosing one source im-
artifact of the texture is placed across a corner of a tile. In this case age for creating all those parts of a tile with marked corners and the
the vertical edge color constraint enforces all tiles with same col- other one for the rest (cf. Figures 4(b) and 11(c)). Of course, the
ored opposite vertical edges to include the remainder of this object two images must potentially fit together via the quilting algorithm to
to ensure the fitting condition. As the same object is also on the achieve natural textures.
horizontal edge, all tiles that contain the corresponding horizontal This enables us to create tilings with two different density levels
edges have to be adapted similarly. In total, in a two colored set of as shown in Figure 11(c). Here, the marked corners are shown as re-
eight tiles six tiles have to be adapted, in a three colored set (18 tiles) gions of different density. In Figure 11(e) a result can be seen using
twelve tiles. This results in visible repetitive patterns.
We are able to create a tile set that avoids such corner problems, 3 It should be noted that the triangular tiles in [Neyret and Cani 1999]
albeit at the cost of adding more tiles to the set. As shown in the next already take into account the corners as part of their coding as well.
two images of daisies, one with a high daisy density and the other
one with low density. The texture quilting optimization process in
this case lasts longer (about 1 minute on a 2 GHz PC). But, once this
is run, generating large amounts of textures at runtime is relatively
free both in texture memory and time.
(a) (b)
(c) (d)