Create a Minecraft-like Voxel Engine Using Procedural Generation
In this repository, I created a voxel engine similar to Minecraft. The terrain is created randomly using procedural generation using Perline noise, and an infite number of maps can be generated.
Procedural generation
Procedural generation is a technique used in animation, visual effects, game development, and many other fields to create digital content algorithmically instead of manually designing it. It would be too dedious for designers to create huge terrains by hand, so we use the power of algorithms to create natural terrains. Perline noise is famous as the method of procedural generation. Please check my article if you want to know how to create 3D terrain by using Perline noise.
How to create an infinite map
If we use procedural generation for creating random terrain, how can we continue to create maps infinitely? I came up with the following algorithm and will introduce it to you.
1. Check camera position
We check the camera position every frame. If camera moves to far away from the center of the current map(Blue area in the image below), we create the new map.
2. Create a new map
We create a new map by using Perline noise. I used the code I previously made with python to implement Perline noise.
3. Update the map
We update from old map to new map. In the below image, the area surrounded by red square is the new map.
How to play
You can play with infinite maps by cloning this code and running following commands.
export LD_LIBRARY_PATH=LD_LIBRARY_PATH:glfw/build/src
export LIBGL_ALWAYS_INDIRECT=0
cd srcs
make
./ft_vox
You can move around by doing the following.
- Forward ->
w
- Backward ->
s
- Right ->
d
- Left ->
a
- Up ->
e
- Down ->
q
- Camera view & scaling ->
mouse
Enjoy it!