What do you think about this ?

Jeanbono

18-04-2009 20:07:23

Create heightmap from a an another bigger heightmap with ETM ?

I try to make a kind of paging solution from drawing only part I need.
On my terrain example, the heightmap data are loaded on with the player position in the little case .
I reload the map when I push direction key.



I use the ETM v2.3.1 sample for testing by adding some few lines:


Ogre::Image cropImage(const Ogre::Image& source, size_t offsetX, size_t offsetY, size_t width, size_t height)
{
if(offsetX + width > source.getWidth())
return source;
else if(offsetY + height > source.getHeight())
return source;

size_t bpp = Ogre::PixelUtil::getNumElemBytes(source.getFormat());

const unsigned char *srcData = source.getData();
unsigned char *dstData = new unsigned char[width * height * bpp];

size_t srcPitch = source.getRowSpan();
size_t dstPitch = width * bpp;

for(size_t row = 0; row < height; row++)
{
for(size_t col = 0; col < width * bpp; col++)
{
dstData[(row * dstPitch) + col] = srcData[((row + offsetY) * srcPitch) + (offsetX * bpp) + col];
}
}

Ogre::Image croppedImage;
croppedImage.loadDynamicImage(dstData, width, height, 1, source.getFormat(), true);

return croppedImage;
}

void loadTerrain()
{
// reload terrain...
mTerrainMgr->destroyTerrain();
Image image;
image.load("ETterrain.png", "ET");
Image img;
img=cropImage(image,pPos.x,pPos.z,129,129);

ET::TerrainInfo info;
ET::loadHeightmapFromImage(info, img);

info.setExtents(AxisAlignedBox(0, 0, 0, 1000, 800 , 1000));
mTerrainMgr->createTerrain(info);
mTerrainInfo = & mTerrainMgr->getTerrainInfo();

// now reload the splatting maps
Image cov;
Image tt;
for (uint i = 0; i < mSplatMgr->getNumMaps(); ++i)
{
cov.load("ETcoverage."+StringConverter::toString(i)+".png", "ET");
tt=cropImage(cov,pPos.x,pPos.z,128,128);
mSplatMgr->loadMapFromImage(i, tt);
}
}


With this concept, each etTerrain.png can be a big world like world1.png etc...
I don't put any objects at this time on the map, I prefer waiting some reply before ;)

CABAListic

18-04-2009 20:53:20

Updating terrain data is very costly. I honestly can't imagine that you could get any decent framerate out of this if you basically update the terrain at every step.

Jeanbono

19-04-2009 08:15:59



(~300 fps when I move the cam on a geforce 9800gt/E6750)

I think I can increase fps by changing:

setExtents(AxisAlignedBox(0, 0, 0, 1000, 800 , 1000));
setExtents(AxisAlignedBox(0, 0, 0, 128, 800 , 128));


and this is true, updating terrain every key pressed is not a good idea.
but terrain could be updated every x frames ? ;)

CABAListic

19-04-2009 11:16:58

That depends on how many vertices it has. Since you have to update the full terrain each time, your terrain size will be quite limited. I'd say 129x129 vertices at the max.

pra

20-04-2009 11:57:06

I think instead of updating the terrain regularly you should check if the character has moved far enough first.