You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: blog/2025-05-07-nanite-at-home/index.md
+52-6Lines changed: 52 additions & 6 deletions
Original file line number
Diff line number
Diff line change
@@ -1,5 +1,5 @@
1
1
---
2
-
title: "Nanite at Home using Rust-GPU"
2
+
title: "Nanite at Home"
3
3
authors: ["firestar99"]
4
4
slug: nanite-at-home
5
5
tags: ["demo", "code", "performance"]
@@ -15,11 +15,13 @@ TODO Nanite at home meme?
15
15
16
16
<!-- truncate -->
17
17
18
-
18
+
TODO proper introduction, why Terrain gen before nanite?
19
19
20
20
## Triangles, Vertices, Meshes and Level of Detail
21
21
22
+
:::tip
22
23
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
+
:::
23
25
24
26
TODO pic of some low poly 3D model
25
27
@@ -33,15 +35,59 @@ For realtime applications you'd typically use a process called "rasterization" t
33
35
34
36
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.
35
37
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
37
39
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",
39
41
40
42
41
43
42
-
## Nanite
44
+
## Terrain in video games
45
+
46
+

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.
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
+

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
+

43
69
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.
0 commit comments