Jump to content
  • Advertisement
Sign in to follow this  
xDarkShadowKnightx

Terrain smoothing algorithm

This topic is 1362 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello! I'm creating a terrain/heightmap editor and am wondering what the typical "Smooth Terrain" tools algorithm would be. I'm currently using the Box Filter algorithm (take the surrounding heightmap pixels and average them together to get a final height). But this doesn't produce satisfying results, nor does it look like what Unity3d's terrain smoothing tool produces (Unity3d being an example of what I'm looking for). Does anyone have any ideas as to what Unity or other terrain editors use for there smoothing tool? Thank you!

Share this post


Link to post
Share on other sites
Advertisement

Increase the size of the box?  Sorry I don't know unity, but I'm pretty sure if you set each heightpoint to the height of the average in a large box instead of the average neighbour's height, then you should see a more dramatic effect?

Share this post


Link to post
Share on other sites


the heighmap is just a grey-colored image
HOW DARE YOU

 

:P

 

More seriously, Ashaman is right. What you can further take from his statement is that a heightmap can be treated like any single channel image, thus you can use whatever image filter you want on it (blurs, distortions, noise, low pass, high pass, etc).

Share this post


Link to post
Share on other sites

Here the code I use to smooth a part of the terrain or the whole heightmap when I import from an image :

float CTerrain::Average( const Int32 i, const Int32 j ) const
{
  float avg = 0.0f;
  float num = 0.0f;
  for( Int32 m = i - 1; m <= i + 1; ++m )
  {
    for( Int32 n = j - 1; n <= j + 1; ++n )
    {
      if( InBounds( m, n ) )
      {
        avg += m_Heightmap[ ( m * m_InitInfo.Width ) + n ];
        ++num;
      }
    }
  }
  return avg / num;
}

Is it really better to use a gaussian filter ?

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!