Skip to content

djmgit/voxel_space

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

28 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Voxel Space

This is an attempt at implementing voxel space from scratch using Raylib. The player or the camera can move forward, rotate, lift up and down, tilt left, right, front and back. I have also tried to add fog effect using two different methods. The rendered worlds look something like this:

voxel_imov_2.mp4

What is Voxel space?

Voxel space is an old, extremely popular, first of its kind algorithm which was used for rendering pseudo 3D terrains. It was created by Novalogic developer Kyle Freeman, who also patented it, and was used to create their signature game Comanche. I wont go into the details of voxel space here since there are plenty of articles and tutorials online. In short voxel space renders graphics pixel by pixel on screen while casting rays from the camera location. Two things which are pre-requisite for voxel space is a color map which defines the color of each pixel in the terrain and a height map which defines how high on screen each pixel is.

How to build and run

If you are running on linux, build and install raylib library for your distribution following the official documentation. If you are on linux you can use the provided raylib library and header files in lib folder. I have also provided raygui.h in this repository itself.

For building and running you can do the following:

  • Clone this repo and open it in terminal.
  • Run make
  • Run make run for running the project.

You should be presented with raylib window.

Controls:

Up arraow - Move front

Down arrow - Move down

W - Tilt camera up

S - Title camera down

Q - Lift camera up

E - Bring camera down

A - Tilt camera on left

D - Tilt camera on right

Adding fog

I gave a shot at adding fog to the scene. Fog is a useful tool to hide clipping of the graphics at the far end of the z axis. I tried to implement two different fog implementations :

  • Linear fog: Which takes into consideration where the fog starts and ends.
  • Exponential fog: Which applies a damping factor on the original color of the pixel as the z distance from camera increases.

You can see how both fog implementations look by switching between them on the GUI and playing with the tuning parameters.

References

Releases

No releases published

Packages

No packages published