Original Post
ive implemented the the thermal erosion described in the article: http://www.oddlabs.com/download/terrain_generation.pdf however ive changed it a bit... im doing something i call materialbased erosion... where i generate another perlinnoise map which represents the hardness of the materials... white represent soft material which can be moved and black is hard rock which cant be eroded... and anything betwen depends on the brightness..this way i can keep the small details whihc erosion normally would remove.. this is waht it looks like... I use the Von Neuman neighborhood and here is the results after 50 timesteps... http://img117.imageshack.us/img117/7338/erosion6lo.jpg
// Calculate the heightdifference of the surrounding vertices
// 0 = (x, y+1), 1 = (x-1, y), 2 = (x+1, y), 3 = (x, y-1)
void CTERRAIN::CalculateSlope()
{
for (int y = 1; y < m_size; y++)
{
for (int x = 1; x < m_size; x++)
{
SlopeMap[x][y][0] = 0;
SlopeMap[x][y][1] = 0;
SlopeMap[x][y][2] = 0;
SlopeMap[x][y][3] = 0;
if (HeightMap1[x][y] > HeightMap1[x][y+1])
{
SlopeMap[x][y][0] = HeightMap1[x][y] - HeightMap1[x][y+1];
}
if (HeightMap1[x][y] > HeightMap1[x-1][y])
{
SlopeMap[x][y][1] = HeightMap1[x][y] - HeightMap1[x-1][y];
}
if (HeightMap1[x][y] > HeightMap1[x+1][y])
{
SlopeMap[x][y][2] = HeightMap1[x][y] - HeightMap1[x+1][y];
}
if (HeightMap1[x][y] > HeightMap1[x][y-1])
{
SlopeMap[x][y][3] = HeightMap1[x][y] - HeightMap1[x][y-1];
}
}
}
}
//Run thermalerosion
// MaterialMap is generated using perlinnoise
void CTERRAIN::ThermalErosion()
{
float slopetotal;
float slopemax;
for (int m = 0; m < duration; m++)
{
CalculateSlope();
for (int y = 1; y < m_size-1; ++y)
{
for (int x = 1; x < m_size-1; ++x)
{
slopetotal = 0.0f;
slopemax = T;
for (int n = 0; n < 4; n++)
{
if (SlopeMap[x][y][n] > T)
{
slopetotal += SlopeMap[x][y][n];
if (SlopeMap[x][y][n] > slopemax)
{
slopemax = SlopeMap[x][y][n];
}
}
}
if (slopetotal != 0) // If there is slope than move material
{
HeightMap1[x][y+1] = HeightMap1[x][y+1] + MaterialMap[x][y] * c * ( slopemax - T ) * (SlopeMap[x][y][0] / slopetotal); // Add material to lower points
MaterialMap[x][y+1] += MaterialMap[x][y] * ((c * ( slopemax - T ) * (SlopeMap[x][y][0] / slopetotal))/thickness); //Add material to the materialmap, lower values of thickness will cause more material to be move each timestep
HeightMap1[x-1][y] = HeightMap1[x-1][y] + MaterialMap[x][y] * c * ( slopemax - T ) * (SlopeMap[x][y][1] / slopetotal);
MaterialMap[x-1][y] += MaterialMap[x][y] * ((c * ( slopemax - T ) * (SlopeMap[x][y][1] / slopetotal))/thickness);
HeightMap1[x+1][y] = HeightMap1[x+1][y] + MaterialMap[x][y] * c * ( slopemax - T ) * (SlopeMap[x][y][2] / slopetotal);
MaterialMap[x+1][y] += MaterialMap[x][y] * ((c * ( slopemax - T ) * (SlopeMap[x][y][2] / slopetotal))/thickness);
HeightMap1[x][y-1] = HeightMap1[x][y-1] + MaterialMap[x][y] * c * ( slopemax - T ) * (SlopeMap[x][y][3] / slopetotal);
MaterialMap[x][y-1] += MaterialMap[x][y] * ((c * ( slopemax - T ) * (SlopeMap[x][y][3] / slopetotal))/thickness);
HeightMap1[x][y] -= MaterialMap[x][y] * c * ( slopemax - T ); // remove material from the currentpoint
MaterialMap[x][y] -= MaterialMap[x][y] * ((c * ( slopemax - T ))/thickness); // remove material from the materialmap
//Make sure we dont get to hight or to low values in materialmap
if (MaterialMap[x][y+1] > 1)
{
MaterialMap[x][y+1] = 1;
}
if (MaterialMap[x-1][y] > 1)
{
MaterialMap[x-1][y] = 1;
}
if (MaterialMap[x+1][y] > 1)
{
MaterialMap[x+1][y] = 1;
}
if (MaterialMap[x][y-1] > 1)
{
MaterialMap[x][y-1] = 1;
}
if (MaterialMap[x][y-1] < 0)
{
MaterialMap[x][y] = 0;
}
}
}
}
}
}