# Dynamic or infinite terrain experiment

## Recommended Posts

Hi Folks,

We have already spoken in this forum about infinite dynamically generated terrains. Nasimi completed a fantastic terrain generator with GeometryBuilder here :

and Dal started a great project here (maybe uncompleted) :

So, my turn to bring my two cents.

Well, it's just an experiment for now.

My idea is this one :

Imagine you have either a huge set of geographic data (3D coordinates), something too big to display at once or even toobig  to build a working mesh with because of the amount of data. Or imagine that you can get infinitely new data, either computed on demand, either downloaded by chunks to depict the new parts of the current terrain in what your camera is currently moving. In both cases, we have too many data to build and display a visible mesh.

So my idea is to decouple the rendering from the logical data. The data could be a very big or dynamically renewed array, whatever... it contains always more info than what is displayable. The terrain is then just an updatable mesh, updated from the camera local position and the current related data.

So there is a logical map containing the 3D data (computed, downloaded, or simply very big) and a terrain mesh "sliding" over the map data.

The mesh could be built by taken in account the LOD necessity, it is to say by having many tiny facets close to the camera location and bigger ones far from the camera.

In order to understand, I intentionally computed a random (simplex) map of data that can be displayed here : it's the red wireframed map, it's 1 million vertices. Normally, it could be far more bigger and wouldn't be displayed.

The camera would be moving in the center of the green disc. Actually, the green disc is the displayable terrain and it should move with the camera movements instead of moving independently. The camera should also be submerged in it at a lower altitude. I put the camera far higher and didn't attached the green terrain to it for the sake of understanding :

• Replies 64
• Created

#### Posted Images

@jerome this is what i do under geometry builder algorithm .you can use ( round ) function for keep your point in correct place that make terrain stable too

great job !like

##### Share on other sites

really nice advice... well, it's just a first attempt, this needs many improvements and refinements.

I want to do it CPU side because I can compute the feature needed for collisions/intersections (normal and terrain altitude at x, z) in the same call at no extra computational cost.

##### Share on other sites

other example : http://www.babylonjs-playground.com/#1SZASV#2

now the data map is not rendered but is bigger : 5000 * 5000 coordinate sets (don't try to render it : this will probably crash your browser)

the terrain mesh is also a bit bigger : 80 * 80 vertices

@NasimiAsl I really need to check how you did to maintain the stability when moving

##### Share on other sites

12 minutes ago, jerome said:

other example : http://www.babylonjs-playground.com/#1SZASV#2

now the data map is not rendered but is bigger : 5000 * 5000 coordinate sets (don't try to render it : this will probably crash your browser)

the terrain mesh is also a bit bigger : 80 * 80 vertices

@NasimiAsl I really need to check how you did to maintain the stability when moving

for example

do it for all coordinate x and y and z

fixedPlace = floor( placex / calibration ) * calibration ;

place 1 isnot correct in image  sorry

##### Share on other sites

ok thanks, I'll test this this afternoon :-D

##### Share on other sites

doesn't fix the issue ... I probably do something wrong somewhere

##### Share on other sites

11 minutes ago, jerome said:

doesn't fix the issue ... I probably do something wrong somewhere

here is afternoon so i can check it

##### Share on other sites

you don't use normal seprated (vertex ) object

plan2 ...

check it

##### Share on other sites

I couldn't check it this afternoon, too busy ... sorry

##### Share on other sites

actually, it seems there is still a little bug in my getHeightFromMap() function : http://www.babylonjs-playground.com/#1SZASV#8

I need to fix this first ...

##### Share on other sites

Ok, now I understand why the terrain is unstable : as the terrain is computed from the data map, I mean really computed : its vertex coordinates are interpolated from the map current data and current terrain position, the result of this computation leads to different terrain facet positions each frame. There's statically no chance that all the tiny terrains facets exactly match all the logical data "ones" (logical facet) each frame. So the hill edges, submits, etc, seem to wave sometimes.

Well, the only way to solve this seems to NOT compute interpolated values and to get only the real current data to morph the terrain,
what should be actually simpler to implement ...

##### Share on other sites

In order to have the terrain mesh exactly match the underlying data map, I had to revert back to a squared ribbon instead of a circular one. Thus, for now, there's no more LOD considerations (will be tested later) but just a sliding squared mesh above a logical map (displayed in this example) : http://www.babylonjs-playground.com/#21MVDH#2

You can elevate high in altitude to understand how the squared terrain fits the data map : I need to jump from a data map facet to the next one at some moments. The challenge is trigger this ugly jump whereas the terrain smoothly moves with the cam.

This method solves the terrain hill altitude computation issue : it's no no longer computed (so no more facet approximation leading to waving edges) but the discrete map data values are directly used instead.

[EDIT] : the same without the logical data map http://www.babylonjs-playground.com/#21MVDH#4

[EDIT2] : same in Free Camera mode walking on the hills : http://www.babylonjs-playground.com/#21MVDH#5

##### Share on other sites

like this mountains (no algo improvement, just another landscape) : http://www.babylonjs-playground.com/#21MVDH#10

##### Share on other sites

@jerome  : fascinating to watch one mesh crawl over another in the http://www.babylonjs-playground.com/#1SZASV#8 demo with lines 169 and 170 un-commented

More hypnotic stuff from you

cheers, gryff:)

thanks :-)

##### Share on other sites

unless I'm still wrong now the terrain is dynamic and infinite  ... well until the position float limit is reached

Yes, I know, there are the words "inifinite", "until" and "reached" in the same sentence... weird.

##### Share on other sites

first non-working attempt with a textured terrain : http://www.babylonjs-playground.com/#1AYPQV#3

I suppose that the texture seems to slide along the hills because the current uvs aren't linked to the map, but just offset ones from the terrain material.

##### Share on other sites

let's go on

First clean refactored PG : http://www.babylonjs-playground.com/#1IHUV1#1

Simple working LOD (no uvs, nor color for now) but more readable code, quite ready to be typescripted if needed ;-)

##### Share on other sites

This is looking really great. It is a must have for the framework

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

×   Pasted as rich text.   Paste as plain text instead

Only 75 emoji are allowed.

×   Your previous content has been restored.   Clear editor

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