Skip to content

Commit 9b148f1

Browse files
committed
nanite: terrain gen, needs rework
1 parent aac3edd commit 9b148f1

File tree

7 files changed

+52
-6
lines changed

7 files changed

+52
-6
lines changed
Loading

blog/2025-05-07-nanite-at-home/index.md

Lines changed: 52 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
title: "Nanite at Home using Rust-GPU"
2+
title: "Nanite at Home"
33
authors: ["firestar99"]
44
slug: nanite-at-home
55
tags: ["demo", "code", "performance"]
@@ -15,11 +15,13 @@ TODO Nanite at home meme?
1515

1616
<!-- truncate -->
1717

18-
18+
TODO proper introduction, why Terrain gen before nanite?
1919

2020
## Triangles, Vertices, Meshes and Level of Detail
2121

22+
:::tip
2223
Feel free to skip this chapter if you already know all these concepts, but I suspect there will be plenty of rust programmers unfamiliar with computer graphics.
24+
:::
2325

2426
TODO pic of some low poly 3D model
2527

@@ -33,15 +35,59 @@ For realtime applications you'd typically use a process called "rasterization" t
3335

3436
The cost of rendering scales largely by the shaders that need to be run, or in other words: The amount of pixels on screen plus the amount of vertices of the model.
3537

36-
As we move a model further away from the camera, the mesh gets smaller and fewer fragment shader need to be evaluated. However, we would still need to call the vertex shader for every single vertex to know where it ends up on screen, even if the detail they describe would be too small to notice. To improve performance, it is common practice to not just have a single mesh, but to create multiple meshes at different Level of Detail (LOD) that can be swapped out, depending on the distance to the camera.
38+
TODO pic of some different LOD levels
3739

38-
## Terrain Generation
40+
As we move a model further away from the camera, the mesh gets smaller and fewer fragments need to be evaluated. However, we would still need to call the vertex shader for every single vertex to know where it ends up on screen, even if the detail they describe would be too small to notice. To improve performance, it is common practice to not just have a single mesh, but to create multiple meshes at different Level of Detail (LOD) that can be swapped out, depending on the distance to the camera. The process of reducing the amount of geometry of a mesh is called "mesh simplification",
3941

4042

4143

42-
## Nanite
44+
## Terrain in video games
45+
46+
![minecraft chunks](./minecraft_chunks.jpg)
47+
48+
You've all played or at least seen Minecraft with its infinite worlds made of blocks. We can't draw infinite amounts of geometry, so we need to segment the world into chunks and only load a small amount of them around the player. And as the player moves in some direction, we load new chunks there and unload the ones behind them.
49+
But that alone doesn't lend itself to far view distances, as chunks further from the camera as just as geometrically dense as the one the player is standing in.
50+
We need simplified chunks.
51+
52+
<figure>
53+
![terrain_mesh_lod.jpg](terrain_mesh_lod.jpg)
54+
<figcaption>[image source](https://www.researchgate.net/publication/342611763_General-Purpose_Real-Time_VR_Landscape_Visualization_with_Free_Software_and_Open_Data)</figcaption>
55+
</figure>
56+
57+
Above you can see a single chunk of a more typical non-blocky game. The white lines indicate the geometry for a 64x64 grid, with a square being represented by 2 triangles each. Compare that to the red geometry representing the same chunk, but with only an 8x8 grid with far fewer geometric detail. By simply using a smaller grid, thus lowering our sampling frequency, we can generate simpler geometry.
58+
59+
TODO rephrase
60+
61+
<figure>
62+
![cdlod_selection.jpg](./cdlod_selection.jpg)
63+
<figcaption>Source: Continuous Distance-Dependent Level of Detail for Rendering Heightmaps</figcaption>
64+
</figure>
65+
66+
A typical approach is to combine a 2x2 of chunks into a larger chunk. If we use a quarter of the vertex density representing four times as much area, every chunk, independent of its LOD, has the exact same amount of vertices and triangles. If we then repeat this process a bunch of times, we can create a chunk system like the one pictured above, with many very detailed chunks near the camera and larger, less detailed chunks the further away we get.
67+
68+
![](./tikz/terrain_tree.png)
4369

44-
The reducing vertices in a model can be automated and is called "mesh simplification".
70+
But as we are building up this data structure, we create a special kind of tree: a Quadtree. Ubiquitous in the computer graphics world, it's a binary tree but in 2 dimensions, where one node splits into four new nodes. For clarity, we will only be visualizing two children per node in our graphs.
71+
72+
73+
74+
## Terrain holes
75+
76+
![](./tikz/terrain_hole.png)
77+
78+
<figure>
79+
![terrain_mesh_lod.jpg](terrain_mesh_lod.jpg)
80+
<figcaption>[image source](https://www.researchgate.net/publication/342611763_General-Purpose_Real-Time_VR_Landscape_Visualization_with_Free_Software_and_Open_Data)</figcaption>
81+
</figure>
82+
83+
84+
<figure>
85+
![](./tree_locked_border.jpg)
86+
<figcaption>[image source](https://blog.traverseresearch.nl/creating-a-directed-acyclic-graph-from-a-mesh-1329e57286e5)</figcaption>
87+
</figure>
88+
89+
90+
## Nanite
4591

4692
## rust-gpu-bindless
4793

Loading
Loading
Loading
Loading
Loading

0 commit comments

Comments
 (0)