Fractal Raymarcher rust

Links

About

Raymarching is a method of rendering where a light ray from the camera is iteratively moved forward based on the distance from the ray to an object. This offers an advantage over other rendering techniques (triangle rasterization or raytracing) because the geometry of the scene does not need to be known. Objects in the scene only need to provide a distance field that describes the distance of every point in space to the surface of the object. Based on this distance field, pixels can be rasterized. The component-wise gradient of the distance field give a normal vector, allowing Phong lighting to be calculated "for free".

This project renders julia sets in 4d space using quaternions. The same iterative "z^2 + c" technique used for 2d julia sets is employed, but using quaternions instead of complex numbers. Using the derivative of the iterative equation, a distance field can be calculated, which is then used bythe raymarcher.

This implementation is written in rust and is fully parallelized. The specific julia set, camera options, rendering options, and colors can be specified on the command line. A minimum working example compiled to webassembly can be viewed here. The renderer is also available in library form.

Sweeping a 3d hyperplane through a 4d julia set, rendered using libraymarcher.

Gallery

The command-line arguments used to generate each image are given.

marcher 3d --c=-0.125,-0.256,0.847,0.0895 --aa-level=4 -w600 -h600 --object-color=0.5,0,0.08 --zoom=4 --bg-color=0.1,0.1,0.1

marcher 3d --c=-0.2,0.4,-0.4,-0.4 --aa-level=5 -w600 -h600 --object-color=0.3,0.3,0.3 --zoom=1.5 --bg-color=0.9,0.9,0.9 --camera-pos=1.5,0.0,1.5 --specular-shininess=2 --specular-color=0.7,0,0

marcher 3d --c=-0.445,0.339,-0.0889,-0.562 --aa-level=5 -w600 -h600 --object-color=0.08,0,0.5 --zoom=2 --bg-color=0.1,0.1,0.1 --camera-pos=1.5,0.0,1.5 --specular-shininess=5

marcher 3d --c=-1,0.2,0,0 --aa-level=5 -w600 -h600 --object-color=0.6,0.6,0.6 --zoom=1.5 --bg-color=0.1,0.1,0.1 --camera-pos=1.5,0.0,1.5 --specular-shininess=5