[Dynamic Terrain ext] shifting visible part of terain to better fit camera FOV

Hey,

how can I adjust dynamic terrain to not render quads behind the camera?
I’m using arc rotate camera and natural point to adjust the visibility would be the center of rotation not the camera posiition as this better describes camera FOV.

Given how the extension works lots of computation budget goes to stuff behind camera which is not visible at all.

What adjustments I can make to render stuff in FOV? Or maybe if that’s not possible simply offset the rendered quads of terrain, so more of “forward” quads are renedered instead ones behind cam.

So I have find a way to do what I want.

Terrain generated by dynamic extension has “shiftFromCamera” property which has “x” and “z” coords.
You can adjust those like this with ArcRotateCamera.

119     // Camear update                                       
120     terrain.updateCameraLOD = function(terrainCamera) {    
121         // This shifts the terrain so right part of it is caught in the camera
122         let alpha = terrainCamera.alpha;                                      
123         let offset = terrainCamera.radius * Math.sin(terrainCamera.beta);
124         terrain.shiftFromCamera = {                                      
125           x: -offset * Math.cos(alpha),                              
126           z: -offset * Math.sin(alpha)                                        
127         }    

Now you’re rendering the part of the terrain that contains center of rotation for your ArcCamera not the cam position.

IDK if this is the way it is suppose to work but it does.

1 Like

Slighty different approach here with support for other cameras.

terrain.beforeUpdate = (): void => {
  // This shifts the terrain so right part of it is caught in the camera
  const _activeCamera = scene.activeCamera as UniversalCamera;
  if (!_activeCamera) throw new Error("No active camera");
  const offset = Vector3.Center(_activeCamera.position, _activeCamera.target);
  terrain.shiftFromCamera = {
    x: -offset._x,
    z: -offset._z
  }
}
2 Likes