Jump to content

Dynamic Terrain Maximum Draw Distance


Recommended Posts

Hi all, new to the forum but long time tinkerer of Babylon and cut my teeth on other engines going some 15 years back now.

I have been playing with dynamic terrain and had a question that I did not see documentation or other posts about. Dynamic Terrain does not seem to follow the standard max draw distance set by camera.maxZ or fog (if enabled) or any other standard max draw distance / optimization method that regular meshes do, at least not at large distances. MaxZ does control view distance to a point, but above 1000 units(ish) it seems to no longer have any effect. At large distances, the terrain's view distance seems to be governed by something else?

What mechanism is being used to control how much further "out" a terrain in drawn?

The screens shot is of a terrain that seems to stop rendering way before the Camera.maxZ distance is hit. There are a few meshes circled that sit much further away then the edge of that terrain, and they still render until maxZ but that terrain gets cut much closer to the camera.  I can move my camera toward those meshes and more terrain appears, but I font seem to understand what governs the dynamic terrains maximum render distance from camera. I noticed the same issue with the flight sim that @jerome - the god of dynamic terrain knowledge - posted, so its not just me. His terrain has a very hard cutoff much closer than it seems like it should. Any ideasof what that limiter / property is, and how / if it can be altered?


var createTerrain = function(mapData, mapSubX, mapSubZ) {
    var options = {
        terrainSub: 400,  // NTS H Res Tile 400, LR tile 20 
        mapData: mapData, // the generated data received
        mapSubX: mapSubX, mapSubZ: mapSubZ // the map number of points per dimension
    terrain = new BABYLON.DynamicTerrain("terrainblock1x1", options, scene);
    terrain.mesh.material = blueGridTestMat;

// NTS Todo - Stream in multi resolution tiles from DB
var hmURL = "../assets/flightAreaMerged.png";  // heightmap file URL
var hmOptions = {
        width: 5000, height: 5000,          // NTS Should be about right for the test height map 
        subX: 2000, subZ: 2000,              // HM samples
        minHeight: -256, maxHeight: 256,    // NTS in game "altitude Range". Todo Real Life AGL Altitude Scaling to Game Unit Conversion. 
        onReady: createTerrain              // callback function declaration

var mapData = new Float32Array(2000 * 2000 * 3); // the array that will store the generated data
var mapType = BABYLON.DynamicTerrain.CreateMapFromHeightMapToRef(hmURL, hmOptions, mapData, scene);



Link to comment
Share on other sites

@Calsa Welcome to the forum!

I'm not sure I exactly get your question but from my experience the render distance is the min of it's width/height and the cameras maxZ. Could you share a playground if possible repro'ing the issue?

I also found some more docs here which might help

Maybe @jerome knows more about this?

Link to comment
Share on other sites

The DynamicTerrain is just a mesh sliding in the space, hooked to the camera and morphing accordingly to the map data.

I'm not sure to really get what you need, but I think you would like to have something like a bigger terrain, stretched far away in the distance, wouldn't you ?

If yes, you have several possibilities, each being mixable with the other ones :

- change your map scale without changing the terrain size. The terrain will be then scaled as well. How to do this ? just multiply every x and z values in the map data array by the wanted scale factor. ex : multiplying all x and z by 2 will give a map twice bigger, so a terrain twice bigger without changing its dimensions (vertex number or subdivisions). This has no impact on the perfs but may reduce the terrain smoothness

- create a bigger terrain so more subdivisions... and more vertex to compute each update. Will decrease the perfs. 

- use the perimetric LOD : https://github.com/BabylonJS/Extensions/blob/master/DynamicTerrain/documentation/dynamicTerrainDocumentation.md#perimetric-lod

This feature allows you to enlarge the perimetric quads only on their width or length. In this example, the 4 quads around the terrain perimeter are twice wider or/and longer than the inside ones : https://www.babylonjs-playground.com/#FJNR5#170

This stretches the terrain on the distant parts from the camera only.

You can set many limits from the terrain center to its edge. Each time a limit is defined, the LOD increases by 1.

If you want a single limit, say 2 quads, but to increase the LOD by more than 1, then just set many times the same limit : [2, 2, 2]  => 3 times from the 2nd quads, so the perimetric LOD will increased by 1 + 1 + 1 = 3.

Just make some tests if this seems still obscure to you :D

This has no impact on the perfs.

Link to comment
Share on other sites

If your goal is not to expand the terrain but to limit the visibility of objects that aren't yet in the terrain, you can either set the camera maxZ property at the wanted value (say, half the real terrain size https://github.com/BabylonJS/Extensions/blob/master/DynamicTerrain/documentation/dynamicTerrainDocumentation.md#other-properties  ), you can either set your object as visible only when it's inside the terrain area with the function .contains() : https://github.com/BabylonJS/Extensions/blob/master/DynamicTerrain/documentation/dynamicTerrainDocumentation.md#useful-functions

object.isVisible = terrain.contains(object.position.x, object.position.z) );

or both ways together

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