Jump to content

  • Log In with Google      Sign In   
  • Create Account


Member Since 18 Nov 2011
Offline Last Active Jan 16 2013 11:07 AM

Posts I've Made

In Topic: Terrain management on iOS for iPads?

10 December 2012 - 08:01 PM

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©; 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

In Topic: Terrain management on iOS for iPads?

09 December 2012 - 01:36 AM

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:
  • 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

Is this even near the ballpark?

In Topic: Terrain management on iOS for iPads?

03 December 2012 - 09:22 AM

Thanks for the link and the advice, I'll report back how it goes when I finish.

In Topic: Is rendering to a texture faster than rendering to the screen?

05 July 2012 - 08:12 PM

My question wasn't really GUI related. Actually, the GUI thing was completely unrelated. I just thought it would make what I was asking more clear by showing what inspired the thought.

There is no such thing as rendering to the screen. You render to your backbuffer (which is a texture) however you want as fast as the hardware can manage, and then you present the finished frame which pushes it to your display

That's what I meant by rendering to the screen, but I didn't hint to that at all so there's no way anybody could have known, hah.

Thank you everybody for your answers, you've enlightened me and I have nothing left to ask!

In Topic: Matrix problems

22 April 2012 - 09:56 AM

Thank you, I learned that I should be a little more patient and more analytical before asking questions. As it turns out, my math was right but I forgot to divide gl_Position by gl_Position.w in the vertex shader!

How annoying.