

Now we need to find the height (y-coordinate) of the terrain surface at the particular x- and z-coordinates.Released in stages (tech preview and beta) to a participating community, Terragen 2 was released to pre-purchasers on 2 April 2009. A*-*B // | /| // |/ | // C*-*D float A = mHeightmap float B = mHeightmap float C = mHeightmap float D = mHeightmap Īt this point we know the cell we are in and we know the heights of the four vertices of that cell. Grab the heights of the cell we are in.
#Terragen heightmap code#
(Note: We assume the coordinates x and z are relative to the local space of the terrain.) The following code does this: To begin to solve this, our first goal is to figure out which cell the x- and z-coordinates lie in. Because the terrain is approximated by a triangle mesh, it makes sense to use linear interpolation so that our height function agrees with the underlying terrain mesh geometry. Therefore, we have to do interpolation to form a continuous surface y = h(x, z) representing the terrain given the discrete heightmap sampling. However, we need the heights of the terrain between vertices. The heightmap gives us the height of a terrain vertex at the grid points. This is useful for placing objects on the surface of the terrain, or for placing the camera slighting above the terrain surface to simulate the player walking on the terrain. Terrain Height (Math-y)Ī common task is to get the height of the terrain surface given the x- and z-coordinates. float4 texColor = c0 texColor = lerp ( texColor, c1, t. Tex ) // Blend the layers on top of each other. TiledTex, 4.0f )) // Sample the blend map. TiledTex, 3.0f )) float4 c4 = gLayerMapArray. TiledTex, 2.0f )) float4 c3 = gLayerMapArray. TiledTex, 1.0f )) float4 c2 = gLayerMapArray. TiledTex, 0.0f )) float4 c1 = gLayerMapArray. The following terrain pixel shader code shows how our texture blending is implemented: Instead, we take a multitexturing approach that works like transparency alpha blending. But this would lead us back to the resolution problemóthe terrain geometry is so large, we would require an impractically large texture to have enough color samples to get a decent resolution. You might suggest creating one large texture that contains the sand, grass, dirt, etc., and stretch it over the terrain. We would like to create terrains depicting sand, grass, dirt, rock, and snow, all at the same time. Loading a RAW fileīecause a RAW file is nothing more than a contiguous block of bytes (where each byte is a heightmap entry), we can easily read in the block of memory with one std::ifstream::read call, as is done in this next method: Double-click Mesh.h which should have a skeleton structure already in the file with the method prototypes already in place including getter/setter methods and a copy constructor. Terragen, Byrce and Dark Tree allow you to create height maps procedurally. To generate RAW files you can use Adobe Photoshop and Corel PaintShop to simply draw your height maps. If a 16-bit RAW file is used we can then represent 65536 ranges. An 8-bit RAW file can hold 256 possible ranges of heights. The RAW format is being used due to the ease of loading RAW data into our program. In this lab we will use a RAW image type although you can use any image format available to you. The grays represent varying heights inbetween. Black (RGB:0,0,0) represent the lowest areas on a terrain map, while white areas(RGB:1,1,1) represent the highest points of elevation. Heightmaps are graphically represented by a grayscale image. A heightmap is a matrix of values with each value representing the individual height of a vertex in a grid of verticies in our application. Heightmaps are used to illustrate the differences in elevation of our terrain. Navigate into the CS470_Lab13 directory and double-click on CS470_Lab13.sln.
#Terragen heightmap archive#
Getting Startedĭownload CS470_Lab13.zip, saving it into the labs directory.ĭouble-click on CS470_Lab13.zip and extract the contents of the archive into a subdirectory called CS470_Lab13 Babcock said, surprise surprise, it really is not that interesting. This technique creates bumpy, hilly landscapes or objects as seen in some of the previous labs with the mountains.
