Jump to content

Dynamic or infinite terrain experiment


jerome
 Share

Recommended Posts

This is the goal : to try to reach something close to the speed of the GPU-side Nasimi's project and to have almost the same features than the (too slow for him) CPU-side Dal's one like the LOD in the distance.

If I can achieve this one (I'm pretty confident now, I'm close to the end of the pure geometry issues), it should have the following feautres :

- dynamically built on any dataset : at least a height map, but this could be a set of 3D coordinates (imposed format and constrained though, this will be documented), with added color and uvs data

- possible LOD : you can dynamically add or remove LOD thresolds  and values to reduce the terrain number of vertices used to depict things in the distance or to expand the terrain size in the same time

- autoLOD with camera elevation : when the camera elevates the terrain auto adapts to both extends and reduce the current LOD

- the terrain automatically moves with the camera : all the magics (marketing word for f...ck complex computations of terrain index/position according to both the current camera and map data positions) lives here : a single mesh is dynamically morphed from the logical map system and positioned in the World space, so no vertex creation/deletion, no memory allocation/release, etc. All is focused only on the maths to update as fast as possible and only when required this single mesh.

- camera horizontal movement tolerance possible : the user can choose to trigger the terrain recomputation only beyond some camera distance of moving from the current location. Example : the camera can fly over 10 terrain cells in any direction before the terrain starts to udpate

- the terrain is by default infinite : if the camera reaches the map edge, the terrain goes on sliding from the opposite map edge as the map were infinetly tiled.

- possible custom behavior : a user function is called on terrain update on each terrain vertex so the user can add its own logic. Imagine a simple flat terrain on a simple flat map, the user can add moving waves in function of the time and other own parameters (wind, etc) and he immediatly gets a living ocean :-)

 

I wish I can show a decent final working geometry by the end of this week...

Link to comment
Share on other sites

Well, I thought that I couldn't achieve it after some sharp headache at dealing with all the indexes... but finally : http://www.babylonjs-playground.com/#1MR44S#1

What do you get here ?

a 100 x 100 terrain (not that big mesh)

it's given an initial LOD setting like this :

this._LODLimits = [3, 2, 2];       // array of LOD limits

what means that the LOD factor is 1 (default) everywhere, except for the 3 first cells (on x and z) where it's default+1

well, as they then are other values in the array, just re-apply the same rule : we've told it was default+1 for 3 first, but it's default+2 for the first two

oops, another last "2" in the array ? ok, let's increment again so default+3 for the first two

Actually, the rule is : the LOD factor is incremented for 1 for each cell thresold, expressed from the terrain edge in the descending order.

This little picture should help to understand LOD = [6, 4]. This means there 6 cells before default lod factor at default+1... and on these 6, there are 4 cells more at default+2

terrainLOD.thumb.png.6f3d116986f5b0a7e9d82143398fdde8.png

 

Imagine that the camera is always on the center of the terrain. Actually, the terrain is hook to the camera on its center and it's morphed according to the data of the map flought over by the terrain. So the relief in the distance (from the center) is drawn with less, but bigger, cells than the things close to the camera. Ok ?

Note that you can change on demand those settings at any time !

The Dynamic Terrain provides an extra feature : it automatically computes new LOD values when the camera elevates. Use the keyboard cursor arrows and you'll notice that the terrain expands, the cells become bigger and the details less visible.

You can set your own behavior with this custom function :

/**
 * Custom function called each frame and passed the terrain camera reference.
 * This should return a positive integer or zero.
 */
DynamicTerrain.prototype.updateCameraLOD = function(terrainCamera) {
    // LOD value increases with camera altitude
    var camLOD = (terrainCamera.position.y / 10.0)|0;
    return camLOD;
};

 

Not complete ...  the uvs and colors now :-p

 

[EDIT] Pilot with your mouse (keep clicked) and beware when it's getting red ;-) http://www.babylonjs-playground.com/#1MR44S#2

 

Link to comment
Share on other sites

The same with a little (final ?) fix to support high camera speeds : http://www.babylonjs-playground.com/#1MR44S#7

plain : http://www.babylonjs-playground.com/#1MR44S#8

I suppose we can consider that the terrain renewal speed challenge is met ;-)

Get elevation with the keyboard cursos key (even when stopped with the UI) to see the LOD in action.

Link to comment
Share on other sites

Woo! This looks really nice. The speed seems really good although I'd like to see how this looks with a high detail terrain with texturing and far view distance - thats where my implementation started to show it was slow.

Link to comment
Share on other sites

Looking forward to read the docs :).

I'm assuming this should work for what I'm trying to do: Have a multiplayer game in which the server defines the map (somehow, maybe multiple heightmap images?) and then when players connect, they "download/stream" chunks of the map as they move? This way I would be able to build a massive world in which players can move around. I still have to see how I can handle the collisions and so on but we'll cross that bridge when we come to it... 

This whole thing looks really good, I just hope I'm not too dumb and I can understand enough bits of it so I can make use of it...

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.

Guest
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.

Loading...
 Share

  • Recently Browsing   0 members

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