Endless recurring or textures using mosaic Wang

With textures are always some problems! At the junction of the textures appear stitches or repeating patterns that spoil the illusion.

You can make the texture larger. Then repeat
layers will be farther apart. You can even make it quite huge, a couple of hundred of thousands of pixels, so that it covers the entire scene is entirely without seams and repetitions. Such a technique is called MegaTexture. But MegaTexture and close to them virtual texture complicate the work of memory to work with them requires special tools, and in general it is still a young technology.

There is one trick - aperiodic mosaics. They are deprived of the problems of repeatability and simple enough to implement. One of these mosaics invented Chinese mathematician Wang Hao in 1961. Elements of the puzzle can be represented as rectangles with red faces. But in order to understand how it works, we must first understand the classical method of filling space textures.

A classical method is as follows: take the picture you like, spread it to test a small area and immediately see all the bad border areas. Thereafter remake the image so that the right side is coincident with the left and bottom to top. Finish texture can be used.

It is necessary to ensure that the horizontal and vertical edges of adjacent textures smoothly into one another. It turns a container for images that fits well alongside other containers.

Internal filling of containers can be anything. You can make some many different variants of the same texture and spread area of random tiles from the set. But anyway, even with this approach remains a recurring net from the faces of the tiles. Therefore, we need to find a way to mix the faces.

In fact, the right and left side of a tile does not necessarily have to be combined with each other, as long as they were combined with neighboring tiles. You can make some choices with different texture edges and pack them in the atlas. Then, during the laying of textures, just take a random tile from the edge, which is coming to an adjacent laid tiles.

Unfortunately, the size of the atlas for a complete set of tiles is growing rapidly with the number of variations of faces. Calculation is carried out according to the following formula: N2 * M2, where N - number of horizontal facets, M - the number of vertical edges. For example, for the two options on the horizontal and vertical leaves sixteen different tiles. If you just need a guaranteed opportunity to continue the mosaic, the formula will be simpler: 2 * N * M.

Tiles made of satin can be arbitrarily large pave space. Taken one random tile, side to it is applied to a suitable second edge, the second tile - the third, and so on until the end of the series. When choosing tile in the second row additionally accounted neighbors from the first row. In the picture above on the left depicts the atlas, and the right mosaic.

How to create an atlas of the tiles? You can take one big picture and put it on top of a grid of colored faces. Then select the appropriate stitch for each color and multiply it on the grid. Or to reverse: first make a grid, and then fill in the blanks.

The illustration at the top left - a mere repetition of the atlas created, right - mosaic Wang collected from it. In the resulting mosaic is no noticeable repetition, it looks random and fluid.

Of course, mosaic Wang is not perfect, it has a problem with the corners of tiles. Mosaic solves the problem of horizontals and verticals, but there is still a diagonal because of which at the junction of four tiles may appear artifacts. But this mosaic is easy and can be used not only for texturing, but also for procedural generation of floor plans or dungeons.

Simple C # code for Unity3d to work with mosaic Wan, you can look at it from the link below.

Unity Web Player | Windows | Linux | Mac | GitHub

Space - a new random texture, 1, 2, 3 - the choice of the atlas, Esc - exit.
For users of Linux: Make the file executable with WangTiles «chmod + x WangTiles» and run.


All data posted on the site represents accessible information that can be browsed and downloaded for free from the web.



User replies

No replies yet