I created a reference shader with ray-primitive intersection routines on Shadertoy. A simple path tracer is used to visualize the scene.
I wanted to create a reference shader similar to “Raymarching – Primitives“, but with ray-primitive intersection routines instead of SDF routines.
As usual, I ended up mostly just copy-pasting code from Íñigo Quílez.
You can find all intersection routines in the Common tab of the shader. The routines have a similar signature: a routine returns the distance to the first hit inside the [distBound.x, distBound.y]
interval and will set the normal if an intersection is found.
If no intersection is found, the routine will return MAX_DIST
.
The following ray-primitive intersection routines are implemented:
- Ray / Plane
- Ray / Sphere
- Ray / Box
- Ray / Cylinder
- Ray / Torus
- Ray / Capsule
- Ray / Cone
- Ray / Ellipsoid
- Ray / Rounded Cone
- Ray / Triangle
- Ray / Sphere4
- Ray / Goursat
- Ray / Rounded Box
Please let me know if there are other routines that I should add to this shader.
You can find (the full source of) the fragment shader on Shadertoy: https://www.shadertoy.com/view/tl23Rm.
Similar posts
If you like this post, you may also like one of my other posts:
- Raytracing in one weekend
- Raytracing: the next week
- Old watch: a WebGL path tracer
- Image-Based Lighting
- Human Document