How to achieve a high FPS rate for a terrain?

Hi all,

I’ve got a scene with a terrain of 1024x1024 cells, i.e. 2 million triangles in one big mesh using a displacement map. My problem: The fps rate is slowly dropping as soon as I add more and more features to my shaders.

Example: I added six texture samplers to my material and suddenly the fps rate dropped from 59 to 25.

How do I achieve a good framerate? What are the key factors that I need to keep in mind in order to keep the fps high? What are the bottlenecks in current OpenGL hardware (e.g. the Radeon Pro 570 on my iMac, or the slower Intel HD Graphics 5000 on my Macbook Air)?

Should I invest in…

  • subdividing the terrain into tiles so that frustum culling might kick in…
  • reducing the number of triangles in the terrain (i.e. find an algorithm to replace several almost coplanar triangles by fewer ones)
  • do some LOD tricks (I’ve got no idea about this…)
  • or what else could I do?

What do you think is the best way to render a terrain quickly? And: How do I measure time on the GPU to find out what the time-consuming part of my shader really is?

Really puzzled.

Have you seen dynamic terrain?

1 Like

Yes, I’ve seen it. It may work well when the camera is close to the ground. However, in my case, I need high frame rates even when flying high above the terrain so that all the cells are visible at once.

That’s a big terrain you have there. Have you tried using the Octree? Optimize Your Scene with Octrees - Babylon.js Documentation . I have worked with some fairly big terrains myself and octrees have helped me gain some FPS.

This seems a good idea. however, this works when the camera is focused only on some part of the terrain.

In my knowledge this is not an easy task. Here no octree or LOD can help as everything is in your camera view. What can be done here would be some kind of trick by replacing the terrain with a plane with a texture which would be a screenshot of the terrain. If far enough the distance would not be noticeable. Not sure if this applies your case to be honest but there are several software which handle it this way.

Hi @Null, thanks for the hints!

For the moment, I did two things:

  1. I reduced the number of terrain cells to 512x512 (0.5 million triangles now instead of 2 million).
  2. I compensated for the loss of detail by generating a normal map for the terrain. Now, the terrain has real surface normals instead of interpolated vertex normals.

The frame rate went back to 60 fps (at least on the fast machine) for now. And the terrain looks better than ever because of the good surface normals!

The lesson I learned today:

  • Let the terrain geometry do the coarse grained work (i.e. the contours of the terrain), but…
  • let a normal map do the fine grained stuff (i.e. the shadows and little valleys that make the terrain look realistic).
  • Do not try to use too many terrain cells in order to achieve both at the same time.

I’m eager to discover more.