Terrain scene node has incorrect size

You are an experienced programmer and have a problem with the engine, shaders, or advanced effects? Here you'll get answers.
No questions about C++ programming or topics which are answered in the tutorials!
Post Reply
ison
Posts: 42
Joined: Sun Mar 24, 2013 9:09 pm

Terrain scene node has incorrect size

Post by ison »

Hello. I read somewhere that Irrlicht terrain scene node has exactly the same size in units as height map texture used to generate the terrain. However, it's not true in my case.
I'm using code from this example: http://irrlicht.sourceforge.net/docu/example012.html
And I changed terrain scale to 1,1,1 and printed terrain size.

My terrain creation code looks like this:

Code: Select all

// add terrain scene node
    scene::ITerrainSceneNode* terrain = smgr->addTerrainSceneNode(
        "../../media/terrain-heightmap.bmp",
        0,                  // parent node
        -1,                 // node id
        core::vector3df(0.f, 0.f, 0.f),     // position
        core::vector3df(0.f, 0.f, 0.f),     // rotation
        core::vector3df(1.f, 1.4f, 1.f),    // scale
        video::SColor ( 255, 255, 255, 255 ),   // vertexColor
        5,                  // maxLOD
        scene::ETPS_17,             // patchSize
        4                   // smoothFactor
        );
 
 
    terrain->updateAbsolutePosition();
    irr::core::aabbox3d <irr::f32> box = terrain->getBoundingBox();
    irr::core::vector3df minEdge = box.MinEdge;
    irr::core::vector3df maxEdge = box.MaxEdge;
    printf("%.2f %.2f %.2f %.2f\n", minEdge.X, minEdge.Z, maxEdge.X, maxEdge.Z);
I'm getting the following output:

Code: Select all

Generated terrain data (256x256) in 0.0600 seconds
0.00 0.00 240.00 240.00
As you can see, terrain's size is not 256x256 units.
Is there any solution to this? I can't scale terrain by factor like 1.05 (so terrain will actually be exactly 256x256), because then, height map texture pixels won't correspond to actual height map height at given position (for example, pixel at 125x125 won't be the same as terrain height at 125x125 pos, it will have a little offset).
ralian
Posts: 28
Joined: Tue Nov 11, 2014 1:00 am

Re: Terrain scene node has incorrect size

Post by ralian »

I don't see the problem with scaling the node to the size that you want. It should transform every point on the node to the proper heightmap position :)
I'll test this on my system and edit the results in shortly

EDIT:
That is in fact very strange. I reproduced the results on my system, and most bitmaps created a heightmap of around .9 times the size of the image, but the exact ratio was arbritrary. It does seem to generate only signed int qualified heightmaps though.
ralian
Posts: 28
Joined: Tue Nov 11, 2014 1:00 am

Re: Terrain scene node has incorrect size

Post by ralian »

Aha! I found your problem.
Try compiling with a smoothing factor of 0 ;)

Also, we should either put in the doc that smoothing causes size reduction, as I am considering this a bug.
ralian
Posts: 28
Joined: Tue Nov 11, 2014 1:00 am

Re: Terrain scene node has incorrect size

Post by ralian »

Oh, quick note, your LOD is 1 too high for that ETPS. I would change it to 4, since the engine just silently uses 4 in that case.
chronologicaldot
Competition winner
Posts: 699
Joined: Mon Sep 10, 2012 8:51 am

Re: Terrain scene node has incorrect size

Post by chronologicaldot »

Yeah, it's probably a bug. Notably, there is also a scaling bug in the terrain creator, so it's probably there too. Oy
ralian
Posts: 28
Joined: Tue Nov 11, 2014 1:00 am

Re: Terrain scene node has incorrect size

Post by ralian »

It's a bug I'll gladly fix, if I can find the time. Or we could just add to the documentation that smoothing reduces size.
ison
Posts: 42
Joined: Sun Mar 24, 2013 9:09 pm

Re: Terrain scene node has incorrect size

Post by ison »

Ok. Thanks for answers.

I'd really like to keep the smoothing factor, since I need this in my project too. Otherwise terrain is too bumpy.

@ralian I'd also be very happy if you could fix this bug.
The problem seems trivial, but in my case it's very problematic. As I said before, I can't scale the terrain by a magic factor of like 1.05 to keep terrain size the same as height map size, because then, height map pixels at x,y do not correspond to terrain's height at x,y. This is clearly visible if someone tries to make a 1000x1000 terrain with 1000x1000 water node with custom water shader, to which I send height map texture. If you then, for example, mark all pixels where terrain's height > 100.0 using red color, then you'll see that it will have an offset from actual terrain hills. So the solution is not to SCALE the whole terrain, but to fill missing gap at the end of the terrain.
My several terrain nodes are connected (tiled), so, currently, if I add terrain nodes with size 1000x1000, and water node with size 1000x1000, without scaling the terrain by 1.05, then I have gaps between terrain nodes, but hills are marked correctly on the water scene node. A simple workaround is to somehow fill the terrain gap with a plane, or something.
Post Reply