Smoothing Terrains???

Blitz3D Forums/Blitz3D Programming/Smoothing Terrains???

Hi All,

Kinda' need some help here with trying to find a function or a piece of code fragment that will help me smooth out my terrains. I need this for my terrain editor im' designing right now and any help will be greatly appreciated!

Thanks Guys...

A blur on the terrain heightmap (or data) should do it. Have a look in the code archive for Blur or Gaussian.

Check out this tutorial...

basic blur algo off the top of my head and psudeo-code ish:

blur=1
for xpos=0 to size
for ypos=0 to size

total#=0
for x=-blur to blur
for y=-blur to blur

total=total + [result from xpos+x,ypos+y]

next
next

put total/(((blur*2)+1)*((blur*2)+1)) into a new image or array or whatever at xpos,ypos. This total divided by the total blur size squared, so if blur is 1 then it's a 3x3 block = 9. blur=2 will be a 5x5 block = 25

next
next

Then copy the new image or array you're using over the top of the old one. Hey presto blurry heaven!

If you're looking to do localized smoothing, just take a 3x3 sampling around the location you're trying to smooth ... add the values together, divide by 9 and replace that location with that value.

This is what I did for UnrealEd's terrain editor.

Epic, you don't want to replace the value, you need to add it to a new array/image first otherwise you'll be averaging average numbers and it will not work correctly.

once you've created your new image you then replace the values.

Yep. I was talking about averaging a single location. If you need to do more than one, yeah, store them in a temporary work area and then replace them all at the end.

Hey Guys...

This is a code sample that I got from the CSP Terrain editor
But when I use it... It just flattens my terrains as soon as I press the corresponding key that activates this code?!

Here's the code:

Dim feld#(140,140)
weich#=100.0


If KeyDown(31)=True
If smtogg=0
 For j=0 To 128
  For i=0 To 128
 w#=0
  wold#=feld#(i,j)
   For j2=0 To 2
    For i2=0 To 2
     w#=w#+feld#(i+i2,j+j2)
    Next
   Next
   w#=((wold#*weich#)+w#)/(weich#+9)
   ModifyTerrain terrain,(i),(j),w#
   feld#(i,j)=w#
  Next
 Next
 smtogg=1
Else
 For j=128 To 2 Step -1
  For i=128 To 2 Step -1
  w#=0
  wold#=feld#(i,j)
   For j2=2 To 0 Step -1
    For i2=2 To 0 Step -1
     w#=w#+feld#(i-i2,j-j2)
    Next
   Next
   w#=((wold#*weich#)+w#)/(weich#+9)
   ModifyTerrain terrain,(i),(j),w#
   feld#(i,j)=w#
  Next
 Next
 smtogg=0
EndIf
EndIf


Still trying to work with this to get it to work.. But any suggestions on the proper direction I should go would be greatly appreciated very much so!

Thank's Guys in advance!

So does anybody have any suggestions concerning this code fragment above here???

Id' greatly appreciate any suggestions on this and hopfully I might be able to use this or something else for smoothing of my terrains...

Thanks a bunch!!