Another problem with terrain borders...

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Post Reply
JDA
Posts: 6
Joined: Tue Jun 16, 2009 1:57 pm

Another problem with terrain borders...

Post by JDA »

Hello,

I am working on generating multiple patches of terrain (3x3 or 2x2 matrices) which should be seamlessly aligned to each other. I am using a set of nine 257x257 bmp greyscale images to create my meshes. I load the needed data for LOD, Terrain size etc. directly from an xml file.

The problem is, that i will get very ugly borders even when using simple heightmaps.

to illustrate the problem i made some screens:

The simple Heightmap (which i cut into 9 parts using ps):
Image

Overview:
Image

Strange borders, #1, holes:
Image

Strange borders, #2, sawtooth:
Image

I already built the 1.5 - release from the svn, not getting the thing fixed by doing so. I use the standard terrain scene nodes for terrain generation.

Has anyone an idea what i might do to fix this? Is it a problem with the engine itself? i read some things in the forums about heightmap border clipping but nothing specific about the problem i have here.

Thanks,
JDA
Lonesome Ducky
Competition winner
Posts: 1123
Joined: Sun Jun 10, 2007 11:14 pm

Post by Lonesome Ducky »

Your heightmap size needs to be 2^n+1, eg. 129x129, 257x257, 513x513
JDA
Posts: 6
Joined: Tue Jun 16, 2009 1:57 pm

Post by JDA »

I am using a set of nine 257x257 bmp greyscale images to create my meshes.
As I wrote, I already use 257x257 heightmaps. That doesn't seem to fix the thing. At the moment, I load the map like this:

Code: Select all

scene::ITerrainSceneNode* terrain = smgr->addTerrainSceneNode(
                "heightmap.bmp" 
If i load from the file system directly, e.g. by using loadHeightMap() or loadHeightMapRAW(), might this work?
hybrid
Admin
Posts: 14144
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

Try to use 129x129 to see if it's a problem with 32bit indices.
JDA
Posts: 6
Joined: Tue Jun 16, 2009 1:57 pm

Post by JDA »

Tried it with 129x129 maps, still the same strange results.

The code building my terrain scene nodes looks like this (need much much improvement - but i am still at beginner level :) ):

Code: Select all

				if(TileCount == 9) //9 tiles 3x3 - currently maximum
				{
					//init working temp variable.
					iTileTmpCounter	= 1; //-> Set Counter to 1. Count up to 9.

					while( iTileTmpCounter < 10) //build from 0-8 so we have 9 tiles absolute.
					{
						//create needed tiles

						//Build Heightmap var
						THCompName[iTileTmpCounter] = HTexHDir+TName+"0"+itoa(iTileTmpCounter-1,buffer,10)+HMExt;
						//Build Diffuse Texturemap var - remove later when switching to shaders
						TTCompName[iTileTmpCounter] = TName+"0"+itoa(iTileTmpCounter-1,buffer,10)+"D"+sTexExt;
						//build conv holder
						HMapConv = THCompName[iTileTmpCounter].c_str(); //works, HMapConv is temp holder for array	

						//build tile matrix 3x3
						
						//row one
						//first tile (0-Tile) clean without offset
						if (iTileTmpCounter == 1)
						{
							//no offset
							fTmpOffsetX = 0.0f;
							fTmpOffsetY = 0.0f;

							//build seg and use data stored before for it
							BuildSegment(device,
											driver,
											smgr,
											TSplitter_01,
											HMapConv,
											0,
											iTileTmpCounter,
											vector3df(fTmpOffsetX,0.0f,fTmpOffsetY),
											TPXYScale,
											TPZScale,
											SColor(TARGB[0],TARGB[1],TARGB[2],TARGB[3]),
											TPLOD, 
											ETPSize,
											TSmooth,
											TLighting,
											TTCompName[iTileTmpCounter],
											TDet,
											TDebug);	

						}
						//build up with offset right now
						if (iTileTmpCounter == 2)
						{
							//X-Offset 1 tile
							fTmpOffsetX = TPOffset;
							fTmpOffsetY = 0.0f;
                      ...
						}
and so on up to

Code: Select all

						if (iTileTmpCounter == 9)
						{
							...
						}
						//matrix looks like:
						// 00 | 01 | 02
						// 03 | 04 | 05
						// 06 | 07 | 08	

						//as last action add 1 to the counter until it matches.
						iTileTmpCounter = iTileTmpCounter + 1;
					}
					
				}

so it loops until the counter iTileTmpCounter is hit.

The (very basic) function BuildSegment() looks like:

Code: Select all

void BuildSegment(	IrrlichtDevice* device,
							IVideoDriver* driver,
							ISceneManager* smgr,
							ITerrainSceneNode* TSplitter,
							const c8* Heightmap, 
							ISceneNode* Parent = 0, 
							s32 id = -1, 
							vector3df& Position = vector3df(0.0f,0.0f,0.0f),
							float ScaleXZ = 50.0f,
							float ScaleY = 10.0f,
							SColor VTXCol = SColor(255,255,255,255),
							s32 maxLOD = 5,
							E_TERRAIN_PATCH_SIZE TPatch = ETPS_17,
							s32 TSmoothing = 4,
							bool Lighting = false,
							stringc TTexture = "",
							stringc TDetail = "",
							bool Debug = false
							)
		{

			//build a file
			IReadFile* HMFile = device->getFileSystem()->createAndOpenFile(Heightmap);

			// add terrain scene node
			TSplitter = smgr->addTerrainSceneNode(
						HMFile,									//heightmap
						Parent,                                 // parent node
						id,                                     // node id
						Position,								// position
						vector3df(0.f, 0.f, 0.f),				// rotation
						vector3df(ScaleXZ, ScaleY, ScaleXZ),	// scale
						VTXCol,									// vertexColor
						maxLOD,                                 // maxLOD
						TPatch,									// patchSize
						TSmoothing                              // smoothFactor
						);

			
			//set lighting on or off
			if (Lighting == false)
			{
				TSplitter->setMaterialFlag(EMF_LIGHTING, false);
			}
			else
			{
				TSplitter->setMaterialFlag(EMF_LIGHTING, true);
			}
			

			TSplitter->setMaterialTexture(0,driver->getTexture(sTexTDir+TTexture));
			TSplitter->setMaterialTexture(1,driver->getTexture(sTexTDir+TDetail));
		        
			TSplitter->setMaterialType(EMT_DETAIL_MAP);

			TSplitter->scaleTexture(1.0f, 25.0f);
			
			//Turn on Debug info or off
			if (Debug == true)
			{
				TSplitter->setDebugDataVisible ( true );
			}
			else
			{
				TSplitter->setDebugDataVisible ( false );
			}
		}
Since I don't work on the vertices or do any other mesh modification stuff to the terrain, i don't have a clue why the terrain borders don't match... I first thought the resampling in photoshop when i scaled the bmps might have done harm to the poor image, but i put the maps together and didnt find any problem here.

I calculate the TPOffset (tile offset) like this (scaling 50.0 x and y, 10.0 z):

Code: Select all

float TPOffset	= 0.0f;	
TPOffset = 129*TPXYScale+6350; //for ETPS_129, 
TPOffset = TPOffset*-1; //because of the mirroring...
BlindSide
Admin
Posts: 2821
Joined: Thu Dec 08, 2005 9:09 am
Location: NZ!

Post by BlindSide »

It's due to the smoothing of course.
ShadowMapping for Irrlicht!: Get it here
Need help? Come on the IRC!: #irrlicht on irc://irc.freenode.net
hybrid
Admin
Posts: 14144
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

IIRC the smoothing shouldn't affect the border points - exactly to avoid the problems with tiling.
coder543
Posts: 17
Joined: Sun May 31, 2009 4:40 pm

Post by coder543 »

Have you run the Example 12, terrain rendering? If it doesn't do the same funky stuff, then perhaps you could try using the heightmap that was demonstrated with example 12 in your own program to test for funkyness.
JDA
Posts: 6
Joined: Tue Jun 16, 2009 1:57 pm

Post by JDA »

Yes, i did example 12, which i based my stuff on. I tried the example heightmap which also gives strange results since it is 256x256. After rescaling it to 257x257 to avoid the borders being cut off, getting the same strange effects.
I will try different bit depths (already tried greyscale indexed, 24bit rgb, will try 32bit and 16bit now also...) probably that might help... after that i am going to rebuild the engine again :-/
BlindSide
Admin
Posts: 2821
Joined: Thu Dec 08, 2005 9:09 am
Location: NZ!

Post by BlindSide »

Did you try disabling terrain smoothing?
ShadowMapping for Irrlicht!: Get it here
Need help? Come on the IRC!: #irrlicht on irc://irc.freenode.net
JDA
Posts: 6
Joined: Tue Jun 16, 2009 1:57 pm

Post by JDA »

Tested the thing without smoothing, this is what i got:

Image

Image

As you can see, the holes still exist. The open seams by the way don't exist in the flat parts of the heightmap with no angled polygons.
Strong99
Admin
Posts: 687
Joined: Fri Mar 31, 2006 7:06 pm
Location: Netherlands
Contact:

Post by Strong99 »

Every pixel resembles a vertex, so are the last pixel lines the same in the hieghtmaps?

like top pixel row of 04 the same as bottom pixel row of 01 heightmap?

00 | 01 | 02
03 | 04 | 05
06 | 07 | 08
JDA
Posts: 6
Joined: Tue Jun 16, 2009 1:57 pm

Post by JDA »

Now this seems to work! The borders are still ugly, but the holes are filled. Thanks a lot, this could be a step forward :)
Post Reply