Drawing voxels seems easy at a glance, they're just cubes after all!
However, there's actually an infinite amount of ways to render voxels, depending on the way they should look like, the underlying storage, performance and resource considerations, general method used, etc. etc. ...
It all depends on what you ultimately want to do.
Graphics Programming APIs
When writing a program that renders something to the screen, you will usually want to make your code work across many platforms. For that, there are two main API's you might use:
- To get started as fast as possible, with no regard as to how modern graphics co-processors work, use OpenGL.
- To be future-proof and get as much performance as possible out of your graphics co-processor, use Vulkan.
There are also rendering abstraction libraries, depending on the language you are using, built on top of these API's:
Some of these libraries have bindings for other languages, so check their documentation before rejecting any!
General Rendering Methods
Converting voxels into meshes, then using a hardware-accelerated rasterizer to render a whole lot of triangles.
Converting voxels into tightly-fitting screen-aligned quadliterals, rasterizing them, then performing a Ray-AABB intersection test in the fragment shader to get cubes.
Send rays out of a camera into a volume of voxels, marching along them until voxels are hit, calculating a color based on the hit voxels and additional rays sent out from there.
This method makes it possible to achieve a high degree of photorealism and/or complex lighting effects, that are otherwise extremely hard to produce with other methods.
General Lighting Methods
TODO: Create article just for lighting?
- Global Illumination?
- Ambient Occlusion
- Flood-Fill Lighting
General Culling Methods
Depending on the method you choose to render voxels, you may have to cull your geometry, so as to not overload your GPU with drawcalls & geometry.