Home » Community » Forums » » Box Filtering Height Maps for Smooth Rolling Hills
  Intel sponsors gamedev.net search:   
[Control Panel] [Register] [Bookmarks] [Who's Online] [Active Topics] [Stats] [FAQ] [Search]

Add Forum to Favorites |  Send Topic To a Friend | View Forum FAQ | Track this topic


 Last Thread Next Thread 
 Box Filtering Height Maps for Smooth Rolling Hills
Post Reply 
This is my first GDNet submission, and I hope that it is well received. Please let me know what you all think about it! I am contemplating the idea of a whole column on designing a powerful terrain engine, so we'll see how that goes.

~Graham

----
Graham Wihlidal, MCSD.NET
Senior Programmer
Graphics & Art Tools
BioWare ULC | EA
--
Author of Game Engine Toolset Development
THE VIEWS OF MYSELF DO NOT NECESSARILY REPRESENT THE VIEWS OF BIOWARE OR EA. KEEP THIS IN MIND.

 User Rating: 1328   |  Rate This User  Send Private MessageView ProfileView Journal Report this Post to a Moderator | Link

Great Article, definitely has a lot of stuff in there worth reading.. I wish we could have an article a day as useful as this!

Keep it up

 User Rating: 1033   |  Rate This User  Send Private MessageView Profile Report this Post to a Moderator | Link

Thank you very much for the support :)

~Graham

----
Graham Wihlidal, MCSD.NET
Senior Programmer
Graphics & Art Tools
BioWare ULC | EA
--
Author of Game Engine Toolset Development
THE VIEWS OF MYSELF DO NOT NECESSARILY REPRESENT THE VIEWS OF BIOWARE OR EA. KEEP THIS IN MIND.

 User Rating: 1328   |  Rate This User  Send Private MessageView ProfileView Journal Report this Post to a Moderator | Link

Looks interesting. I will give it a try tommorow, and see how it looks like :-). I'm still i nthe early stages of my terrain renderer, and always lookin for new things and ideas to try. :)

 User Rating: 1068   |  Rate This User  Send Private MessageView Profile Report this Post to a Moderator | Link

Did it quickly before going away from home :)
Here's my result:



Without any smoothing



This is using my own idea once:

HeightMap[y][x] = (float)(HeightMap[y][x-1] * 0.11f) + (HeightMap[y][x+1] * 0.11f) + (HeightMap[y-1][x] * 0.11f) + (HeightMap[y+1][x] * 0.11f) + (HeightMap[y][x] * 0.11f) + (HeightMap[y-1][x-1] * 0.11f) + (HeightMap[y+1][x+1] * 0.11f) + (HeightMap[y+1][x-1] * 0.11f) + (HeightMap[y-1][x+1] * 0.11f);



With box filtering. Between the last two there is not that much difference, but looking at the background, it looks your one is smoother :).

Ofcourse, this was quick test, the terrain isn't very well visible at the moment :).

btw, can I ask you how you get your detail? splatting? or something else :)

 User Rating: 1068   |  Rate This User  Send Private MessageView Profile Report this Post to a Moderator | Link

I'm glad you got it working ;) Made quite a bit of difference!

I did the detail in my terrain using detail texture splatting. Bit of optimization in there. Each polygon I check for splatting layers that hide layers underneath and remove occluded polygons. Then I regenerate the static vertex buffers. Works pretty well, and removes the polygons you can't see.

----
Graham Wihlidal, MCSD.NET
Senior Programmer
Graphics & Art Tools
BioWare ULC | EA
--
Author of Game Engine Toolset Development
THE VIEWS OF MYSELF DO NOT NECESSARILY REPRESENT THE VIEWS OF BIOWARE OR EA. KEEP THIS IN MIND.

 User Rating: 1328   |  Rate This User  Send Private MessageView ProfileView Journal Report this Post to a Moderator | Link

Awsome tutorial, I have to use this on my terrain rendering code... will post some pics once i do

Keep up the good work Graham ;D


</ Positronic Dreams / Colibri 3D Engine / My Journal >
* What the hell is an aluminum falcon?


 User Rating: 1469   |  Rate This User  Send Private MessageView ProfileView Journal Report this Post to a Moderator | Link

A useful article, though I'm a little suprised most people didn't already implement it.
It's also a very useful technique in image manipulation, and is one example of using a matrix to manipulate an 'image'. By changing the weightings in the matrix you can sharpen/blur/detect edges, which makes a useful object-orientated approach most easy. I think the matrix is technically called a 'kernel' in image manipulation - Photoshop uses this technique for some of it's effects I believe.

Good work.

 User Rating: 1295   |  Rate This User  Send Private MessageView Profile Report this Post to a Moderator | Link

yup, matrix approarch is very flexible and does allow all kind of different effects, not only smooth & blur. (on both highmaps and textures, and also all sorts of different data)

(... now a bit off topic, it's more about texture/picture filtering, than about heighmap ...)

but the "box" method is somewhat special, because it can be optimized heavily. If you thing about it, you can calculate sum of first box in upperleft corner, and than to get sum of next box, you need only to subtract left column of box, and add right column of box. Column sums can be again cached and updated by simple -upper element +new lower element when you move to next row.

This allows you to use this filter in realtime with different size of box with almost same computational complexity.

I did this to blur (with variable "blur degree") whole software rendering result in our old PC demo called "WHY". (http://7gods.org/files/why_11.zip)
The difference between no filter (1x1), 2x2, 3x3 and 4x4 is very visible, but with box size of 10x10 and more you get just blured vision, so this is definitely not very flexible filter in terms of finetuning the result. But it's fast and you can do it on the fly for almost constant CPU time.
I think it can be even done at your GPU with some pixel shader maybe.

With different matrix filters you will have to recalculate whole matrix everytime, which is making other filters to cost as much, as what size you choose for your matrix. Thus they are not as suitable for real-time, as this "box" blur.

Ped/7Gods

 User Rating: 1015    Report this Post to a Moderator | Link

Yeah, I have quite some problems finding the logic behind Texture splatting. I'll probably leave it for a while now, and work on the water. Then it's time for some game logic.

Anyway, this matrix type of filter is also great for pregenerated lightmaps/shadowmaps (for example using the fast lightmap calculation article here on GD). Blurring out the corners of the shadows make it look more real :)

Just an idea for people who haven't tried this yet. :)

 User Rating: 1068   |  Rate This User  Send Private MessageView Profile Report this Post to a Moderator | Link

Yes, the matrix described above is in fact technically referred to as the convolution kernel. By providing varying kernels, different effects can be achieved; including sharpen, blur, smart blur, etc..

Edge detection is a method to allow for finetuning your blur algorithms. Specifically speaking of heightmaps, it will allow your terrain to maintain its sharp cliffs while still applying smoothing and noise removal.

~Graham

----
Graham Wihlidal, MCSD.NET
Senior Programmer
Graphics & Art Tools
BioWare ULC | EA
--
Author of Game Engine Toolset Development
THE VIEWS OF MYSELF DO NOT NECESSARILY REPRESENT THE VIEWS OF BIOWARE OR EA. KEEP THIS IN MIND.

 User Rating: 1328   |  Rate This User  Send Private MessageView ProfileView Journal Report this Post to a Moderator | Link

Is it just me, but some hills and mountains require sharp edges,
and if you want a mix, why not create your heighmaps correctly in the first place?

Ok I skimmed the article, but i just don't see the point

mikie

 User Rating: 1019   |  Rate This User  Send Private MessageView Profile Report this Post to a Moderator | Link

I agree. Why don't you blur (blurring := box filtering) the terrain with the terrain editor (often you can edit the terrain files with a regular paint program such as the Gimp, and use its blur function). That would allow for really sharp edges when I need them. I can add teletubby style soft edges myself.

If you need blurring go for a lower resolution terrain map.

Having said that the article is okay and explains box filtering quite well (as stated before it's applicable to other areas too such as image manipulation).

[Edited by - Kurioes on October 26, 2004 3:18:33 PM]


Kurioes' Dump | KBL

 User Rating: 1100   |  Rate This User  Send Private MessageView Profile Report this Post to a Moderator | Link

mikiex: In my article, I do state that in order to preserve sharp edges you would implement a different type of convolution filter know of as "smart blur". It uses a form of edge detection and a threshold factor to remove noise, yet preserve cliffs and edges.

Kurioes: Blurring in Photoshop is box filtering. It's the same technique, except this method:

a) Doesn't require photoshop
b) Can be called at runtime
c) Serve other dynamic purposes (soft shadows, etc..)

Thank you for the comments, I do appreciate them.

~Graham

----
Graham Wihlidal, MCSD.NET
Senior Programmer
Graphics & Art Tools
BioWare ULC | EA
--
Author of Game Engine Toolset Development
THE VIEWS OF MYSELF DO NOT NECESSARILY REPRESENT THE VIEWS OF BIOWARE OR EA. KEEP THIS IN MIND.

 User Rating: 1328   |  Rate This User  Send Private MessageView ProfileView Journal Report this Post to a Moderator | Link

Quote:
Original post by Kurioes
I agree. Why don't you blur (blurring := box filtering) the terrain with the terrain editor (often you can edit the terrain files with a regular paint program such as the Gimp, and use its blur function). That would allow for really sharp edges when I need them. I can add teletubby style soft edges myself.


Programmers often want to do things themselves. You can blur the heightmap in another program, but how fun is that?
You can always download the SDK to Doom 3 (or UT) and write your game from there, but that isn't any fun either.





 User Rating: 1056   |  Rate This User  Send Private MessageView Profile Report this Post to a Moderator | Link

I still think photoshop (or any other decent painting program) is the way to go if all you care about is the final result; selectively blurring certain areas just gives you more flexibility and control over the final result.

I do, however, understand why you'd want to do this yourself (I can't say I didn't). It would come in handy when generating random heightmaps.

Suggestion for a follow-up: more kernels. For example:
unfiltered: (lame kernel :P)
0 0 0
0 1 0
0 0 0


blur:
1 1 1
1 2 1
1 1 1


sharpen:
-1 -1 -1
-1  9 -1
-1 -1 -1


edge detect: (divide by one, not zero)
-1 -1 -1
-1  8 -1
-1 -1 -1


emboss:
-1  0  0
-1  5 -1
 0  0 -1



You should generally divide the result of the convolution by the sum of the elements of the matrix. You could experiment with other kernels; the results are quite interesting.


Kurioes' Dump | KBL

 User Rating: 1100   |  Rate This User  Send Private MessageView Profile Report this Post to a Moderator | Link

A very nice article! :D It's very well written and everything seems obvious and simple. Good work. :)

Is it your cat, Kurioes? ;)

___
Quote:
Know where basis goes, know where rest goes.


 User Rating: 1089   |  Rate This User  Send Private MessageView Profile Report this Post to a Moderator | Link

Quote:
Original post by clapton
Is it your cat, Kurioes? ;)


Nope :) Just the first adequate picture I could find on my computer.

 User Rating: 1100   |  Rate This User  Send Private MessageView Profile Report this Post to a Moderator | Link

I find a combination of median filtering using a photo editor and your box filtering routine achieved better overall results. Median filtering will smooth out the little bumps on the ground and your box filtering routine will smooth out the curvature of the hills in my terrain. Anyways good job on this excellent article!

 User Rating: 1063   |  Rate This User  Send Private MessageView Profile Report this Post to a Moderator | Link

Thank you for your feedback Tybon!

~Graham

----
Graham Wihlidal, MCSD.NET
Senior Programmer
Graphics & Art Tools
BioWare ULC | EA
--
Author of Game Engine Toolset Development
THE VIEWS OF MYSELF DO NOT NECESSARILY REPRESENT THE VIEWS OF BIOWARE OR EA. KEEP THIS IN MIND.

 User Rating: 1328   |  Rate This User  Send Private MessageView ProfileView Journal Report this Post to a Moderator | Link

All times are ET (US)

Post Reply
 Last Thread Next Thread 
Forum Rules:
You may not post new threads
You may post replies
You may not edit your posts
You may not use HTML in your posts
Jump To:
Administrative Options: