Erosion 6

From DaveWiki

Jump to: navigation, search

There is one potentially significant issue with the erosion process so far. When we perform an erosion cycle, starting at a high point, we will always end at a local minimum. This creates "rivers" but these rivers will not be continuous from the highest points to the lowest points in the height map. In reality water flows downhill, collecting at local minimum and continuing on to the oceans. This creates a continuous river system which our current method cannot generate.

Whether this is an issue or depends on how the height map is to be used. If we're just generating rough landscape for worlds to be viewed at a distance it probably doesn't matter. If, however, we're generating land to be used in a first person RPG creating roughly realistic river systems would be good.

The first step is to simply define a "sea level" in our height map by making the following additions to the CErosionSample class:

#include "erosion5.h"
 
class CErosionSample6 : public CErosionSample5
{
public:
 
	float	m_SeaLevel;
 
	/*
	 * Class Constructor
	 */
	CErosionSample6()
	{
		m_SeaLevel = -1;
	}
 
	/*
	 * Sets all heights less than the specified SeaLevel height to that level.
	 * Iterates over all pixels in the map so land-locked areas lower than sea
	 * level will also be filled in.
	 */
	void FillSeaLevel (const float SeaLevel)
	{
		int X, Y;
		davelib::CProfileTime Profile(_T("FillSeaLevel()"));
 
		m_SeaLevel = SeaLevel;
 
		for (Y = 0; Y < m_HeightMap.GetHeight(); ++Y)
		{
			for (X = 0; X < m_HeightMap.GetWidth(); ++X)
			{
				if (m_HeightMap.GetValue(X,Y) < m_SeaLevel) m_HeightMap.SetValue(X, Y, m_SeaLevel);
			}
		}
 
	}
 
};
 
int _tmain(int argc, _TCHAR* argv[])
{
	CErosionSample6 ErosionSample;
 
	ErosionSample.CreateBaseNoise();
	davelib::OutputHeightMapGrayScale("erosion6a.bmp", ErosionSample.m_HeightMap);
 
	ErosionSample.FillSeaLevel(0.2f);
	davelib::OutputHeightMapGrayScale("erosion6b.bmp", ErosionSample.m_HeightMap);
 
   	return 0;
}

The FillSeaLevel() method simply sets the height of all land lower than sea level. Note that this will also set any land-locked areas lower than sea level. This outputs (color adjusted to more clearly show the ocean):
Image:Erosion6.jpg

Personal tools