Jump to content

Quadtree LOD terrain


Recommended Posts

Ok, time to share a preview of something I have been working on for a couple of months now: A quadtree LOD terrain for Babylon.

So far I have:
- Chunking system with infinite paging
- Distance based LOD
- Custom meshing
- Basic UVs and texturing
- Bakes to Babylon GroundMesh objects so all the usual functions, physics etc works.
- Perlin based height data generation.

The bad news is, its currently slower with the LOD than without it, mainly due to memory and garbage collection pressure. I need to make it more efficient at caching the unchanged data between updates and massively reduce the number of new objects created.
I'm also duplicating vertices at the moment, I need to fix that.
And of course... the infamous seams. At the moment there are cracks between the LOD which need to be handled with seam generation.


If anyone has interest in helping, let me know.. I am going slightly crazy developing this :D


Link to comment
Share on other sites

4 minutes ago, jerome said:

Impressive !

Do you have any public repo somewhere so we could check the code (and maybe help) ?

Not yet... I am just doing some major refactoring first... I have had another idea of something to try.
After that I will post it in a repo :D

Link to comment
Share on other sites

1 hour ago, Deltakosh said:

What is your question?

More than a question really... I need someone to take a look at the code and figure out what the hell can be done to speed it up :P

The code basically works, I think its probably just a case of optimizing the amount of data that is being passed around but I don't understand the low level stuff enough and it's not really documented AFAIK :(

Link to comment
Share on other sites

1 hour ago, Deltakosh said:

Unfortunately I'm pretty busy this times...But one first question: are you using an updatable vertex buffer?

I'm setting the positions like this in the constructor:

  this.mesh.setVerticesData(VertexBuffer.PositionKind, positions, false);

I figured that is the correct thing to do because the positions are only set once. It works by calculating ALL the possible verts for the terrain, and then uses the indices to pick which ones are part of the mesh. Maybe that's not a good way to work in Babylon though, I don't know enough about the low-level stuff :S

Link to comment
Share on other sites

@Deltakosh I've managed to get a bit further on it... it's getting close to being usable now, but I need to improve the distance function. After that I can try to get it to run in the playground or at least some kind of online demo.

There are definitely still a lot of stupid performance-affecting issues in the code right now though, I hope the core team and the community here will be able to help squish them. :D

Link to comment
Share on other sites

Thanks Dal for this promising feature. Do not worry too much about performance, you already had a good idea which can be improved :)
I wish I could help you but I don't have enough skill/time so far :X

Good luck !

Link to comment
Share on other sites

58 minutes ago, Temechon said:

Wooooow it's beautiful ! What about performance ? Is a demo available ? 

Performance is great. As long as you have an i7 CPU :D
I have a few ideas for optimizations, then i will release something so all you smart guys can find MORE speed from it (I am pretty sure there will be some big optimizations that could be done with a few lines of code by someone who understands the low-level stuff better than I do).


Link to comment
Share on other sites

OK guys, I think its just about usable now. The biggest problem is that it slows down big time whenever it loads new chunks in... I tried to solve it with threading but so far it broke more than it solved so I'm going to park that for now.
You should be able to check out https://git.loudened.com/babylon/terrain.git now with your git client.

@Temechon @jerome (or anyone else for that matter) It would be really cool if you can find some way to improve the speed of it :D



Link to comment
Share on other sites

Not sure I understand all your code. What is the main principle behind the hood ?

Do you create new chunkq of terrain on the fly ? how do you dispose the useless ones ? or do you re-use them ?


I would have used a different approach :

- to have a huge logical terrain, whatever its source : heightmap, perlin noise computation, etc... well something too big to be rendered with vertices but easily defined by a set of vertices (x, y, z), well like ribbon paths or arrays

- to have an updatable renderable mesh designed by a pool of different LOD stripes : imagine, say, three concentric squares (BJS grounds), the farthest with the lowest LOD, the closest with the highest LOD

- to shift the mesh vertex values along the logical terrain array according to the camera position in the World : the farthest square would be defined for example with 1 logical coordinate set every 100 ones, the middle one with 1 on 20, the closest with all logical coordinates (not pertinent values)

Just to say that each stripe picks its part of logical coordinates but not with the same density.


This would be some kind of "moving mesh" in the logical array, although immobile in the World, according to the cam moves and the mesh would be updated by the current logical coordinates.

So only a pre-defined updatable mesh, no allocation, no destruction, just vertex position updates (maybe uvs also) what is really fast


not sure I'm very clear

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Create New...