Seamlessly tiling Terra

Discussion area about developing with Ogre-Next (2.1, 2.2 and beyond)


Nucleartree
Kobold
Posts: 37
Joined: Tue Apr 04, 2017 9:10 pm
Location: Cardiff, UK
x 19

Seamlessly tiling Terra

Post by Nucleartree »

Hi everyone.

I've recently been experimenting with terra (It's great by the way!) in my project. I'm trying to build a large, streamable world, including terrain. In order to achieve this I'm splitting the world into 'chunks', and tiling them together. My problem is that when I try and tile terrain together, I get noticable gaps between the terrains.

Image

It seems to me that the terrain isn't stretching all the way.
To illustrate this I placed a cube mesh at where I expect the starting corner of the terrain to be.

Image

The red box shows where I expect the terrain to reach to, but for whatever reason it seems to miss this by a tiny margin. The top left corner of the terrain lies exactly on the mesh, but the bottom right corner doesn't stretch far enough.

Each terrain is a single instance of terra, which I create upfront in a pool and recycle as the player moves around. In the example above each terrain is 100x100 in size, and I tile them based on this (so 00 is placed at 0, 0 and 10 is 100,0). The origin of the terrain is the middle of the chunk.

I've tried:
  • Using different resolution for the terrains (256, 1024 verticies). Often times a higher resolution terrain will shrink the gap a bit, but not remove it.
  • Using different world sizes for the chunks, including prime numbers.
  • Reading and altering parts of the terra vertex shader to try and understand where the issue is coming from. I didn't get very far with that.
To me it seems like a floating point issue, and I've been able to reproduce it in a number of samples, both inside and outside my game engine.

I create my terrain like this:

Code: Select all

const Ogre::Real terrainSize = 1024.0f;
const Ogre::Real halfSize = terrainSize / 2;
mTerra->load( "flat.png", Ogre::Vector3( halfSize, 0, halfSize ), Ogre::Vector3( terrainSize, terrainSize, terrainSize ) );
Assume terrainSize is also the size of a chunk. It's later attached to a scene node which is positioned according to the chunk position.

This is ogre 2.1, linux, OpenGL.

I'd be really greatful if someone could provide some insight into what this might be.
I don't have that much experience with terrain, so if I've gone completely the wrong way around doing seamless terrain please let me know :D
Thanks!
User avatar
dark_sylinc
OGRE Team Member
OGRE Team Member
Posts: 5509
Joined: Sat Jul 21, 2007 4:55 pm
Location: Buenos Aires, Argentina
x 1378

Re: Seamlessly tiling Terra

Post by dark_sylinc »

This looks like an off-by-one error.

There is no getter for Terra::m_xzRelativeSize. Add one, and try offsetting your position by this amount.

i.e. tilePos = (x, y) * (terra->m_xzDimensions - terra->m_xzRelativeSize);
Nucleartree
Kobold
Posts: 37
Joined: Tue Apr 04, 2017 9:10 pm
Location: Cardiff, UK
x 19

Re: Seamlessly tiling Terra

Post by Nucleartree »

Finally got time to look into this.

Thanks for your response Dark Sylinc. It seems like it was a one off error in the end.

After some experimenting I found a solution by applying the m_xzRelativeSize to both the position and the scale.

Code: Select all

const Ogre::Real rel = (float)slotSize / (float)img.getWidth(); //The same as m_xzRelativeSize. I have to calculate it earlier so I can apply it to the terrain creation.
const Ogre::Real pos = slotSize / 2 + rel / 2; //The terrain is placed in the middle of the slot, with an offset to balance out the relative size.

mTerra->load( img, Ogre::Vector3(nPos.x + pos, 0, nPos.z + pos), Ogre::Vector3(slotSize + rel, slotSize, slotSize + rel)); //Scale the terrain here.
Now the terrain is nice and pretty! Thanks!