0
\$\begingroup\$

I have created the map of a huge terrain (10,000 x 12,000) vertices, which results in about 240 million triangles. Loading all these is very heavy and slows down the scene significantly. To make it more efficient, I am thinking of using a fraction of the vertices when the camera is away (say one for every 10 vertices) and as the camera zooms in on the map, I would increase the number of vertices.

The problem is, even when the camera is zoomed in and a small fraction of the map is viewed at full resolution, the scene is still loading very slowly because of all the drawings that are happening outside the viewport.

My question is, how do I calculate which vertices are in the viewport so that I don't draw them. Or, alternatively, is there a better way of handling increasing the resolution as I zoom in (note that I am not using textures)

\$\endgroup\$
1
\$\begingroup\$

120M vertices is indeed a large load to run through your vertex shader, even just for OpenGL to cull them.

I assume you already have the terrain defined as VBOs that are loaded at launch, and not every frame?

It's best to divide up your terrain mesh in chunks, and do some culling on the CPU, and only draw (partially) visible chunks.

This is a process that is referred to as Frustum Culling. And this video is an excellent illustration of how it works.

Note that you could start off with a very quick win by not drawing anything that is behind the camera. This should give you a factor 2 win, if the camera is at the center of the mesh.

Just test each chunk's direction: take dot product with camera-forward vector. If the dot product is negative, don't draw it. You may need a little margin built in so that you don't cull the ground directly underneath the camera though.

To do a full cull process, you need to solve the intersection between the camera frustum and the terrain chunk's AABB.

\$\endgroup\$
  • \$\begingroup\$ Very nice suggestions, they sound very promising. It might take some time to actually test them. I'll mark it as accepted unless proved otherwise ;) \$\endgroup\$ – Arash Dec 31 '18 at 4:03

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.