Erosion 4

From DaveWiki

Jump to: navigation, search

For this example we'll change exactly how each point is eroded. In the previous example we simply reduced the height of the map at each point during the erosion cycle. This created very sharp and unnatural erosion features. We'll use a very simple blend process to create smoother erosion. From the previous source we'll change the ErodePoint() method again and introduce a few new constants:

#include "erosion3.h"
 
class CErosionSample4 : public CErosionSample3
{
public:
 
	float EROSION_BLEND1;
	float EROSION_BLEND2;
 
	/*
	 * Class Constructor
	 */
	CErosionSample4()
	{
		EROSION_DELTA  = 0.0002f;
		EROSION_BLEND1 = EROSION_DELTA / 2.0f;
		EROSION_BLEND2 = EROSION_DELTA / 4.0f;
	}
 
	/*
	 * Override to provide a new erosion type with a simple blend.
	 */
	virtual void ErodePoint (const int X, const int Y)
	{
		ErodePointSimpleBlend(m_HeightMap,  X, Y);
		ErodePointSimpleBlend(m_ErosionMap, X, Y);
	}
 
	/*
	 * Helper method to provide the simple erosion blend to a point in a height map.
	 */
	void ErodePointSimpleBlend (utils::NoiseMap& HeightMap, const int X, const int Y)
	{
		HeightMap.SetValue(X+0, Y+0, HeightMap.GetValue(X+0, Y+0) - EROSION_DELTA);
		HeightMap.SetValue(X+1, Y+0, HeightMap.GetValue(X+1, Y+0) - EROSION_BLEND1);
		HeightMap.SetValue(X-1, Y+0, HeightMap.GetValue(X-1, Y+0) - EROSION_BLEND1);
		HeightMap.SetValue(X+0, Y+1, HeightMap.GetValue(X+0, Y+1) - EROSION_BLEND1);
		HeightMap.SetValue(X+0, Y-1, HeightMap.GetValue(X+0, Y-1) - EROSION_BLEND1);
		HeightMap.SetValue(X+1, Y+1, HeightMap.GetValue(X+1, Y+1) - EROSION_BLEND2);
		HeightMap.SetValue(X-1, Y+1, HeightMap.GetValue(X-1, Y+1) - EROSION_BLEND2);
		HeightMap.SetValue(X+1, Y-1, HeightMap.GetValue(X+1, Y-1) - EROSION_BLEND2);
		HeightMap.SetValue(X-1, Y-1, HeightMap.GetValue(X-1, Y-1) - EROSION_BLEND2);
	}
 
};
 
int _tmain(int argc, _TCHAR* argv[])
{
	CErosionSample4 ErosionSample;
 
	ErosionSample.CreateBaseNoise();
	ErosionSample.ErodeAll();
 
	davelib::OutputHeightMapGrayScale("erosion4a.bmp", ErosionSample.m_HeightMap);
	davelib::OutputHeightMapGrayScale("erosion4b.bmp", ErosionSample.m_ErosionMap);
 
   	return 0;
}

Using this updated method for the erosion results in:
Image:Erosion4.jpg Image:Erosion4a.jpg

Personal tools