# Distance Ray Marching

## Basics

In contrast to classical ray tracers this technique uses a procedural description of the scene. Specifically, each object is defined by a distance function which estimates the distance between the current point on the ray and the closest point of the object, hence the name. A detailed description of ray marching and representing objects as distance fields can be found at iquilezles.org, 9bitscience.blogspot.de, and blog.hvidtfeldts.net. The demo above is a modified version of the code available at www.shadertoy.com.

## Extensions

I extended the code to represent important ray march parameters such as the distance epsilon and the maximal number of iteration steps as shader uniforms. Thus, one can explore the impact of different values on the image quality and frame rate. By enabling 'Show Steps' the renderer shows the iteration depth at each pixel from black to red where red is the iteration maximum. Furthermore, I added antialiasing and depth of field by casting multiple rays with random aperture offsets into the scene. Note, to achieve good results the sampling rate of the rays has to be high enough, i.e., the value defined by 'AA and DoF' is the number of sampled rays. Setting this number to 0 disables the effects, where a high number creates better quality images for the price of performance. However, it becomes apparent that after 60 the image quality doesn't seem to increase anymore. This is caused by the primitive, yet fast, random function in the fragment shader. In order to get a better random sampling more sophisticated random functions such as Perlin noise have to be used on the GPU or CPU.