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.
The shader is fully procedural and stateless. A naive analytical algorithm is used to calculate 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:
- It is possible to visualize an animated 3D scene in a single shader using ray tracing.
- The compile-time of this shader is quite long.
- The ray tracer is not super fast, so it was not possible to cast enough rays per pixel to support global illumination or soft shadows. Here I miss the cheap AO and soft shadow algorithms that are 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 that would have simplified the description of an SDF.
- I ran in GPU-dependent unpredictable precision problems. Hopefully, most problems are solved now. I’m not sure if they are inherent to ray tracing, but I didn’t have these kinds of problems using raymarching before.
You can find (the full source of) the fragment shader on Shadertoy: https://www.shadertoy.com/view/tlSSDV.
If you like this post, you may also like one of my other posts:
- More spheres
- Old watch: a WebGL path tracer
- Ray Tracing – Primitives
- Yet another Cornell Box
- Raytracing in one weekend