Terrain Generation ImplementationAuthor: Justin Couch (email@example.com)
Since Ken Musgrave's 1989 paper on procedurally generated terrains, the fascination with artificially generated terrains has steadily grown. Not only does the basic terrain ideas work, but they can be applied to other areas, such as cloud textures. Fractal terrains, as they have become known as, is the basis of the very popular commercial product Bryce (and very recently, Ken's latest effort - MojoWorld).
Code OutlineAll terrain oriented code can be found in the package
ClassesFor generating fractal terrains, there is only one real class involved -
The terrain generator class is responsible for evaluating the fractal height
values and placing them in a grid. The grid is then shipped off to the
Figure 1: The static class structure for terrain generation
Generating Terrain ValuesTerrain values are created in a sub-division type manner. The code starts with a simple 2x2 grid of points set to some base height (typically zero). The grid square is divided into 4 squares by dividing each side in half. The new points have their basic height calculated as the average of the two corners and then have a random fluctation added (which may actually be negative).
Once all five new points have been processed, the four grids are now again subdivided and the same process takes place again in each individual grid. This time, the amount of random fluctuation is divided by the amount of roughness. Thus if roughness is set to 0.5 then the maximum amount of fluctuation that can be applied is half of the previous iteration.
The process continues subdividing the surface for the given number of iterations. Each iteration adds an exponentially larger number of points, so given a standard JVM setup, the practical maximum is 9 iterations.
Once the terrain heights are completed, the next step is to apply a sea level if needed. In this situation, the system will iterate through all the height values and if the height is less than the sea level height, the generator will change the height value to the sea level value. Finally, the heights are passed to the elevation grid generator for tesselation.
The code offers a basic seed terrain for you to use. The idea of this is to allow the user to create the basic forms of hills and valleys. Unfortunately the code currently does not offer you the ability to set the border values. Setting border values is useful when you want to blend two tiles of fractal terrain together and need the edges to exactly match. This feature needs to be added.
Generating texturesAnother use of fractal terrains is in generating cloud textures. These creators use the fractal terrain system to generate the height points but do not perform the 3D tesselation. Instead, height values are converted to colours based on the height data. Because fractal terrains lead to smooth height transitions, the output effect is a nice smooth colour transition that approximates a cloud or fire form.
To generate an image texture, the code starts with building a set of fractal
height values first. The user then supplies the
Because the caller may want different types of images, both greyscale and colour output is available. For efficiency, these generate the appropriate image type. A greyscale image will be created with just a one or two component image, while colour output will generate a full 32-bit image.
[ Home ]
[ License ]
[ javadoc ]
[ Online Examples ]
[ Download ]
[ j3d.org ] [ Aviatrix3D ] [ Code Repository ] [ Java3D ] [ OpenGL ] [ Books ] [ Contact Us ]
Last Updated: $Date: 2010-01-27 21:36:00 -0800 (Wed, 27 Jan 2010) $