Jump to content

  • Log In with Google      Sign In   
  • Create Account

Banner advertising on our site currently available from just $5!


1. Learn about the promo. 2. Sign up for GDNet+. 3. Set up your advert!


Terrain smoothing algorithm


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
5 replies to this topic

#1 xDarkShadowKnightx   Members   -  Reputation: 547

Like
0Likes
Like

Posted 24 August 2014 - 08:08 PM

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!



Sponsor:

#2 xbattlestation   Members   -  Reputation: 431

Like
0Likes
Like

Posted 24 August 2014 - 09:06 PM

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?


Storm Clouds over the Western Front - 2D aerial combat WIP | DarklightXNA on Twitter | 2DFlightSim on Youtube

#3 Ashaman73   Crossbones+   -  Reputation: 11452

Like
3Likes
Like

Posted 24 August 2014 - 10:44 PM

Use gaussian blur (the heighmap is just a grey-colored greyscale image).


Edited by Ashaman73, 24 August 2014 - 11:56 PM.

Ashaman

 

Gnoblins: Website - Facebook - Twitter - Youtube - Steam Greenlit - IndieDB - Gamedev Log


#4 TheChubu   Crossbones+   -  Reputation: 6617

Like
0Likes
Like

Posted 24 August 2014 - 11:52 PM


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).


"I AM ZE EMPRAH OPENGL 3.3 THE CORE, I DEMAND FROM THEE ZE SHADERZ AND MATRIXEZ"

 

My journals: dustArtemis ECS framework and Making a Terrain Generator


#5 xDarkShadowKnightx   Members   -  Reputation: 547

Like
0Likes
Like

Posted 25 August 2014 - 10:47 AM

Alright I'll go ahead and will try both increasing the box size and the new filter. Thanks guys! I'll make sure to get back to you as soon as the changes have been done.



#6 Alundra   Members   -  Reputation: 1145

Like
0Likes
Like

Posted 30 August 2014 - 02:42 PM

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 ?






Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS