Sign in to follow this  
MichaelDeCicco

Terrain management on iOS for iPads?

Recommended Posts

I've been looking around the internet for the past week on and off and can't find anything about what sort of terrain management system would be the best for specifically the iPads.

I wanted to implement ROAM but I can't seem to understand certain aspects of it for some reason and it's taken a massive amount of effort to not only have time to program recently but also understand the concept of the ROAM algorithm. So before I put the effort into it, would it be a lost cause due to the possible performance issues? What would be the best kind of algorithm to use on the iPad? Should most of the work go to the CPU or the GPU?

Share this post


Link to post
Share on other sites
This is the technique I'm planning to use:on iOS [url="http://www.gamasutra.com/view/feature/1754/binary_triangle_trees_for_terrain_.php"]http://www.gamasutra.com/view/feature/1754/binary_triangle_trees_for_terrain_.php[/url]. I don't really know ROAM, but at a glance I think this BTT solution is a little simpler to get your head around.

In terms of performance on iOS, your main concern should probably be to minimise draw call count.

Share this post


Link to post
Share on other sites
The best for iOS devices is GeoMipmaps.
GeoClipmaps is the best overall, but requires vertex-shader texture reads.
GeoMipmaps is the next overall best and is fully compliant with the capabilities of iOS devices, as it requires no vertex-shader texture reads. Unity 3D proves that GeoMipmaps are viable and fast on iOS devices.


L. Spiro

Share this post


Link to post
Share on other sites
So I'm having a hugely difficult time visualizing some aspects of this in my head, which is a big part of the way I program things. There's that and some other things I can't seem to understand about terrain lod, specifically geomipmapping. I am starting to get a handle on it, but no matter how many threads or pages I read I just can't seem to get a clear view of what I'm programming.

So let me get this straight:
[list=1]
[*]With geomipmapping you start with a quadtree.
[*]That quadtree is subdivided enough times to give you the number of patches you want along the sides of the terrain.
[*]Each leaf node has an index buffer for each level of detail, each connected to a single vertex buffer (assuming the main vertex buffer is below 5MB)
[*]Magic stitching happens that I still don't have a clue about that fixes gaps between patches with differing lod values
[/list]

Is this even near the ballpark?

Share this post


Link to post
Share on other sites
GeoMipmapping does not use quad-trees (although it can). It typically uses grid-based tiles that are subdivided. You are describing progressive GeoMipmapping which is more advanced than you probably need.
GeoMipmapping can be very simple to implement in its most basic form. It is just a grid of terrain chunks that decrease in resolution by half the further away they are from the camera. You can decide which LOD to apply to any check using metrics as simple as this or optionally more complicated such that you account for view angle over the chunk etc.

You can also worry about the gaps later. Get the basic implementation down first and then you will start to understand the rest.


L. Spiro Edited by L. Spiro

Share this post


Link to post
Share on other sites
I only use the quadtree for culling purposes, the leaves of the quadtree hold the geomipmapping grid and the leave spaces are defined as the bounding box of the vertices used by that terrain patch. The branches are defined as a bounding box that contains all of its children. That way I can cull it all. That's not important though.

So here's what I have:
Terrain patches have MaxLOD number of index buffers which reference a vertex buffer for that patch, I realize that using vertex buffers for each patch isn't efficient enough, but it's just to get it working first.

At initialization the vertex buffers are created and then each lod level is created like this:
[source lang="cpp"]void GeoPatch::GenerateBuffers(const Vector2f &TopLeft,i32 Size,UHeightMap *HeightMap)
{
Vertices.Clear();
Vertices.SetRenderPrimitives(GL_TRIANGLES);
Vertices.ToggleVertexTexCoords();
Vertices.SetMaterial(UMaterial::GetBasicTextureMaterial());
Vertices.GetMaterial()->SetTexture(0,HeightMap->Map);

Vector2f TexScale = Vector2f(1.0f / HeightMap->Map->GetTexDimensions().x,1.0f / HeightMap->Map->GetTexDimensions().y);

for(u16 y = 0;y <= Size;y++)
{
for(u16 x = 0;x <= Size;x++)
{
u16 cx = TopLeft.x + x;
u16 cy = (HeightMap->Map->GetTexDimensions().y - TopLeft.y) + y;
Vector2f c(cx,cy);

Vertices += HeightMap->GetVertexAtPos(c);
Vertices.SetTexCoord(c * TexScale);
}
}

#define Idx(x,y) (((y) * (Size + 1)) + (x))
u16 Sy = TopLeft.y + Size >= HeightMap->Map->GetTexDimensions().y ? Size - 1 : Size;
u16 Sx = TopLeft.x + Size >= HeightMap->Map->GetTexDimensions().x ? Size - 1 : Size;

Indices[0].Clear();
Indices[0].Vertices = &Vertices;
for(u16 y = 0;y < Sy;y++)
{
for(u16 x = 0;x < Sx;x++)
{
Indices[0] += Idx(x + 0,y + 0);
Indices[0] += Idx(x + 0,y + 1);
Indices[0] += Idx(x + 1,y + 1);

Indices[0] += Idx(x + 0,y + 0);
Indices[0] += Idx(x + 1,y + 1);
Indices[0] += Idx(x + 1,y + 0);
}
}

for(u8 Lod = 1;Lod < Parent->MaxLOD;Lod++)
{
Indices[Lod].Clear();
Indices[Lod].Vertices = &Vertices;
u8 Skip = Lod * Lod;

for(u16 y = 0;y < Sy;y += Skip)
{
for(u16 x = 0;x < Sx;x += Skip)
{
Indices[Lod] += Idx(x + 0 ,y + 0 );
Indices[Lod] += Idx(x + 0 ,y + Skip);
Indices[Lod] += Idx(x + Skip,y + Skip);

Indices[Lod] += Idx(x + 0 ,y + 0 );
Indices[Lod] += Idx(x + Skip,y + Skip);
Indices[Lod] += Idx(x + Skip,y + 0 );
}
}
}
#undef Index
}[/source]

The code is pretty straightforward, Size = size of terrain patch, TopLeft = top left of terrain patch, Heightmap = the heightmap..

That's not important either. Just know that it sort of works even though it presents some graphical errors probably from not using power of two + 1 size heightmaps or whatever has to happen there. I'm sort of fuzzy on that and haven't found anything around the internet that clearly defines it.

I haven't implemented anything to choose LOD yet

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this