Saturday, March 28, 2009

Mountains



It's surprising the variety of things you can do graphically, as far as tiles go, with just a few simple techniques. For example, I'm rather pleased with the way the mountain tiles have turned out, for such a simple technique. Pictured is a tilesheet for mountains. It's not the transition tiles. In the engine as so far implemented, terrains come in 2 tilesheets; one sheet for fully enclosed (non-transitional) terrain elements, and one sheet with the partially transparent border tiles. The fully-enclosed sheets are lain out in a 4x4 grid of slightly different alternatives to sort of help break up the pattern of repetition.

To generate the mountains, I began with a tiling cellular function. If you are unfamiliar with cellular functions, I recommend reading Texturing and Modeling: A Procedural Approach 3rd Edition. It's a good all-around book for anyone looking to do procedural graphics of any sort. Awesome book, one of the best in my library. Anyway....

I created a method for tiling cellular functions. It's an explicit method, rather than implicit as the cellular methods in the above book are. I begin with an array and I scatter a few random points around inside it. Then I set the value of each array point equal to the distance to the nearest point (F1 function). By making 9 copies of the seed point list, and arranging the copies in a 3x3 block pattern, then taking the array values from just the central block, I end up with a function that tiles with itself seamlessly on all 4 edges.

The value of the F1 function resembles a series of cusps with raised edges; by simply inverting the values I end up with a series of peak-like shapes.




Kind of looks like mountains, but far, far too smooth. But with the application of some turbulence, we're in business.



From here, it's a simple matter of creating a bump map and a colormap, and combining them. The color map is a simple elevation-indexed color scale ranging from a brown dirt color, through a bluish gray stone color, and to the white of snow at the peaks. The exact characteristics of the peaks can be tweaked by manipulating the color scale.

Variants of the tile can be produced by changing the seeds for the turbulence applied. I created a special procedure for generating the noise buffers used to apply turbulence. Two seamlessly tiling buffers are combined into one using a blending mask. By keeping the same seed for the buffer that results in the edges, and using different seeds for the buffer blended for the center, I can create patterns that are different in the centers but that match up with each other on the edges. If you look at the final mountain tile pictured above you can see that some of the individual mountains are similar, yet slightly different. Any of the tiles in the 4x4 block will seamlessly tile with all of the others.

Like I said, it's a simple technique, but the results, I think, are quite pleasing.

No comments: