Mesh Generation System

All mesh generation tasks are running asynchronous using burst compiled jobs, and will never block the main thread. This also means that there can be a slight delay by a few frames when the mesh generation job takes longer than expected (e.g. when the procedural noise sampling job is using very expensive settings).

Quadtree Scheduling System

All mesh generation jobs are scheduled from the ‘QuadtreeSchedulingSystem’. Each node element with the tag ‘NeedsGeneratedGridTag’ will have a new mesh generation job scheduled. The references to all currently running jobs are stored inside the system, and it checks if a job is finished every frame.

When a mesh has been generated, and the lod level of the generated mesh is equal to the collision lod level, another follow up job is scheduled to generate a collision mesh and add a collider to the node’s entity.

All generated meshes are stored inside the system. The Quadtree Rendering System picks up these stored meshes to render them each frame. When a node is split up into multiple child nodes (increasing the LOD level) or is being merged again (decreasing LOD level), the mesh will not be stored anymore, as only the lowest lod levels are being rendered.

Mesh Generation Job

The mesh generation job is the most important core part of Orbis. This is where new meshes for quadtree nodes are being generated and updated. It utilized Unity’s new MeshData API, and is fully burst compiled. It outputs the vertices and triangles of new meshes, and also calculates the bounds and vertex data of the mesh.

The job starts by generating a grid of vertices, and offsets them by the height sampled at the vertex positions. To calculate vertex normals, 4 nearby positions are being sampled (up/down, and left/right), which are then used to calculate the normals for each vertex. This eliminates normal artifacts between chunk borders, as the normals are calculated independant of the mesh borders.

Biome data is also baked into the mesh using vertex colors, making it easy to use the biome data that is sampled from either biome maps or procedurally in the terrain material/shader.

When skirts are enabled for the quadtree, the job also generates a skirt around the edges of the mesh. This can eliminate cracks between the terrain nodes, which can appear when height differences between two neighboring nodes are large and they are not the same lod level. Generating the skirts does is not very complex and is performed very fast, but it results in an increase of the vertex count. The normals of the skirt vertices are set to the same value as the edge vertices of the mesh above it, eliminating lighting artifacts.

When heightmaps are sampled, the values for each vertex position are sampled bilinear, resulting in smooth terrains even when using low-resolution height maps with a higher-resolution terrain.