60 lines
No EOL
2.9 KiB
HTML
60 lines
No EOL
2.9 KiB
HTML
<!DOCTYPE html>
|
|
<html lang="en">
|
|
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<title>something silly - voxels</title>
|
|
<link rel="stylesheet" href="/style.css">
|
|
<link rel="icon" type="image/x-icon" href="/cretin.png">
|
|
</head>
|
|
|
|
<body>
|
|
<main>
|
|
<h1 id="voxel-engine-in-godot-3-with-rust">Voxel engine in Godot 3 with Rust</h1>
|
|
<p>
|
|
<code>2022-05-05</code><br>
|
|
I made a voxel engine in rust to learn rust and godot-rust as well as explore voxel systems. It has (practically) infinite terrain generation, lets you place and remove voxels and supports transparent voxel types. The main point was to develop an optimised meshing algorithm.<br>
|
|
</p>
|
|
<p>
|
|
<video src="./voxel_media/demo.mp4" controls></video>
|
|
Demo of fast terrain generation<br>
|
|
<video src="./voxel_media/demo2.mp4" controls></video>
|
|
Optimised mesh visualisation<br>
|
|
</p>
|
|
<h2 id="optimisedgreedy-mesh-algorithm">Optimised/greedy mesh algorithm</h2>
|
|
<p>
|
|
editor's note: This writeup was never finished :D<br>
|
|
</p>
|
|
<p>
|
|
The algorithm I'm using is one I made myself, inspired by a few others. I could not find an easy to understand explanation of how to do it but <a href="https://vercidium.com/blog/voxel-world-optimisations/">this artice</a> and <a href="https://0fps.net/2012/06/30/meshing-in-a-minecraft-game/">this article</a> gave me somewhere to start.<br>
|
|
</p>
|
|
<p>
|
|
In this explanation I will assume basic knowledge of how meshes work and how to do the simplest form of culling for voxel meshes.<br>
|
|
<img src="./voxel_media/fig1.png" alt=""><br>
|
|
fig. 1: example set of voxels, with the simplest form of mesh generation applied.<br>
|
|
</p>
|
|
<p>
|
|
To start off, we can break down the problem to 2 dimensions by recognising that each direction along the axis as well as each layer along those directions is independent. We then only have to process a single 2D slice of the voxel domain at once.<br>
|
|
</p>
|
|
<p>
|
|
<img src="./voxel_media/fig2.png" alt=""><br>
|
|
fig. 2: The algorithm only needs to consider one layer and direction at a time, highlighted in green<br>
|
|
</p>
|
|
<p>
|
|
The first step is to generate "strips", essentially create long quads that cover connected voxels. We can loop through the plane and keep track of at most one active strip. The active strip is the last one started and we grow it as more voxels under it are traversed. In the inner loop we check the voxel at that position as well as the one above. With this we can determine if we need to stop the current strip, start a new one or do nothing. If there is not currently an active strip, a new one should be created when the voxel below is filled and the one above is empty (an exposed surface).<br>
|
|
</p>
|
|
<p>
|
|
<img src="./voxel_media/fig3.png" alt=""><br>
|
|
fig.3: Long strips of adjacent voxels can be merged into fewer, long quads.<br>
|
|
</p>
|
|
<p>
|
|
.<br>
|
|
</p>
|
|
<p>
|
|
this was incomprehensible, take me <a href="/">home</a><br>
|
|
|
|
</main>
|
|
</body>
|
|
|
|
</html> |