I recently learned about an interesting technique for rendering 3D images, known as raymarching distance fields. This technique became popular in the demoscene for its power and simplicity. It is capable of generating complexly detailed 3D images in real time with remarkably few lines of code. An excellent explanation of how the algorithm works can be found here and many working examples can be found on Shadertoy.
I wanted to explore this technique in more depth. The best way to understand how something works is to take it apart and put it back together, so I decided to write my own raymarcher in Processing by porting code from the above links. This project has given me a more detailed understanding of 3D rendering and a lot of practice with vector math in 3D space. Even in it’s current bare-bones state, it is capable of generating some very cool images. The most fun use of the program that I’ve discovered is creating these infinite tunnel gifs.
You can view the source code on GitHub. I’ve tried to organize the code in a readable way, and written lots of comments explaining how the different parts work.