Archived

This topic is now archived and is closed to further replies.

sofsenint

erosion-blur

Recommended Posts

I've been working on a terrain generator using Trent's book Focus on 3D Terrain Programming. Right now, I'm using the fault formation technique. After I create each fault, I blur the image using the erosion blur presented in the book. However, the heightmaps end up with huge drop offs, and don't look at all blurred. Here is a sample heightmap- http://www.angelfire.com/ia3/sofsenint/Image1.gif My code seems to be almost exactly like what I see in Trent's code. Here's the function that blurs an individual line-
void CTerrain::ErodeBand(float* pBand, int Stride, int Length, float Filter)
{
	float Previous = pBand[0];
	int Current = Stride;
	int i;
	for(i = 0; i < Length-1; i++)
	{
		pBand[Current] = Filter*Previous+(1-Filter)*pBand[Current];
		Previous = pBand[Current];
		Current+=Stride;
	}
}
And here's the code that loops through all lines-
void CTerrain::ErodeImage(float* pImage, float Filter)
{
	int i;
	for(i=0; i[edited by - sofsenint on October 4, 2003 11:20:57 PM]

[edited by - sofsenint on October 4, 2003 11:21:27 PM]     
[edited by - sofsenint on October 4, 2003 11:22:09 PM] [edited by - sofsenint on October 4, 2003 11:23:26 PM]

Share this post


Link to post
Share on other sites
I found my problem- I wasn't "normalizing" the terrain like Trent does in his code. But now I've discovered a new one. When I generate terrain, it renders just fine. However, if I save it, there is a chunk of the image that is misplaced. Example-
www.angelfire.com/ia3/sofsenint/image2.gif
If you look closely, you can see that those misplaced pixels on the left would match up if you dragged it to the other side of the pic. This error is not there when I first generate the heightmap and render it, but it is in the heightmap when saved and loaded. This is strange, because my saving routine just writes the whole thing as a chunk. Another strange thing about it is that this error only occurs in generated terrain- if I load a pre-made heightmap and then save it, the patch of misplaced pixels does not show up in the saved file. What in the world could be wrong?

-----------------------------
Weeks of programming can save you hours of planning.

There are 10 kinds of people in this world-- those who understand binary and those who don't.

[edited by - sofsenint on October 5, 2003 5:59:54 PM]

Share this post


Link to post
Share on other sites
Looks like you''re on win32 platform and have you write files in text mode, windows writes 0x0D 0x0A instead of 0x0A. It seems valid, because the shifting only occurs on the dark patch

Open your file in binary mode when saving you bitmaps.

Share this post


Link to post
Share on other sites