Test: Gpu Raymarch of Distance fields

YouTube Preview Image


  • Ray marching of distance fields done on the Gpu inspired by IQ demo “Slisesix” and  Shadertoy. The video shows two scenes rendered with a pixel shader: the simple scene showing basic distance fields and the more elaborated one, showing procedural distance fields and shading.


This test is heavily inspired by the IQ’s work done on ray marching and his several raymarched demos. The test builds the pixel shader, which is the ray marcher, on the fly everytime the shader changes. The algorithm is as straightforward as cast a ray, sample the distance in a position and advance to the next with the distance obtained until you reach a minimun distance or a maximun number of iterations. The distance fields are functions like spheres, cylinders and torus. The fun comes with the csg operators you can use like union or difference. I have had a great amount of fun developing the procedural distance fields but requires a lot of tweaking and time.


  • Left click plus mouse movement to rotate the camera around the center of the scene.


  • C++
  • Boost
  • Opengl 2.0
  • Glew
  • CMake
  • Microsoft Visual Studio 2010
  • Subversion
  • Redmine
  • Windows 7 x64

Develop/Build/Test Machine Specs

  • Intel(R) Core(TM) i7 CPU 920 @ 2.67GHz
  • 3072 Mb RAM
  • Nvidia GeForce GTX 260
  • Nvidia Driver Version: 260.99
  • Microsoft Windows 7 Professional x64


3 Responses to “Test: Gpu Raymarch of Distance fields”

  1. Adrien says:

    Do you have updated sources for this work?

    I’ve tried to compile it but I have several errors and I suspect some different source files not to come from the same revision…

    There are some unknown structures and method used in Render.cpp

    Thanks in advance!

  2. Ruben Penalva says:

    thank you very much for letting me know! Unfortunately you are right, the libraries version are wrong but I cant upload the new ones right now. I am sorry. I have removed the link to the source code. If I have some time I will upload it again with the correct libraries.

    Ruben Penalva

  3. DD says:

    Hi Ruben,

    Is it ok for you to released the updated source code now? I’m hoping to learn more from them.