Rendering System
To render the terrain itself, Orbis using a custom rendering system, and does not rely on GameObjects or the Hybrid Renderer V2 to draw terrain tiles.
Drawing Meshes
Each node of the quadtree that is being rendered contains a unique mesh, with a material that is being shared across the Terrain. This means that there is a Graphics.DrawMesh for every terrain cell that is being rendered.
The systems uses the meshes generated and stored in the Quadtree Scheduling System, and the Materials that are defined in the OrbisInterface.
Sphere face culling
On spherical terrains, only terrain nodes that are actually visible to the main camera are being rendered, while nodes that are occluded by the terrain sphere itself will not be rendered. Note that this only affects the rendering itself, collision meshes are handled indepently.
To calculate the visible nodes, a visibility sphere around the camera is being constructed, based on the center of the terrain, and the min and max height of the surface. Any quadtree node where the bounds are outside of the visibility sphere will not be rendered. This drastically reduces both the amount of vertices and draw calls that are being rendered.
Render Layers
All terrains are rendered in a render layer that is defined by the ‘renderingLayer’ property of the OrbisInterface. This allows for custom rendering handling in the camera if needed. This defaults to 0, the ‘default’ camera render layer.
Shader Keywords
The rendering system adds a material property block to all draw calls, which can contain additional shader keywords that can be used in the terrain shaders. For spherical terrains, the center of the planet is added as shader keyword, allowing the shader to calculate the height of a vertex based on the planet’s center.
The property Id of the planet center is:
int Planetcenter = Shader.PropertyToID("_planetcenter");
LOD transitions
LOD transitions can be enabled in the OrbisInterface component, and allow the transitions between lod levels to be more smooth, making them harder to notice for the user. However, this requires a custom terrain shader that support lod dithering. Also, rendering transition meshes incurs a small performance penalty. When the lod level of a terrain part changes, the ‘old’ mesh is temporarily stored and still being rendered. This allows the old mesh to fade out, while the new mesh is fading in.
To control the lod fading, a shader keyword is being updated while the terrain is fading:
int DitherProg = Shader.PropertyToID("_DitherProgress");
The transition duration is fixed, so the transition meshes will only be rendered for a short time.
The lod transition speed can be modifed in the QuadtreeRenderingSystem.cs by changing the property:
public const float ditherDuration = 3f;