This shader is a proof of concept to find out if I could create a “typical” Shadertoy shader, i.e. a shader that renders a non-trivial animated 3D scene, by using a ray tracer instead of the commonly used raymarching techniques. 

Use your mouse to change the camera viewpoint.

The shader is fully procedural and stateless. A naive analytical algorithm calculates the inverse kinematics to move the robotic arm. It is probably possible to rewrite the inverse kinematics algorithm and get rid of (most of the) trigonometry used.

The ray tracer supports point-lights, metallic and reflective non-metallic materials. Bounces are only used to calculate reflections, so there is no global illumination.

Some first conclusions:

  • Visualizing an animated 3D scene in a single shader using ray tracing is possible.
  • The compile time of this shader is quite long.
  • The ray tracer is not fast, so casting enough rays per pixel to support global illumination or soft shadows was impossible. I miss the cheap AO and soft shadow algorithms available when raymarching an SDF.
  • Modelling a 3D scene for a ray tracer in code is verbose. It was not possible to exploit the symmetries in the arm and the domain repetition of the sphere grid, which would have simplified the description of an SDF.
  • I ran in GPU-dependent unpredictable precision problems. Hopefully, most problems are solved now. I’m unsure if they are inherent to ray tracing, but I haven’t had these issues using raymarching before.

You can find (the full source of) the fragment shader on Shadertoy: https://www.shadertoy.com/view/tlSSDV.

Similar posts

If you like this post, you may also like one of my other posts:

Robotic Arm
Tagged on: