Is there a method to do ray marching style modulus repeat with raytracing? One of the features of ray marching is that you can use modulus to repeat shapes infinitely, like in the image below, which is from https://www.shadertoy.com/view/MsBGW1



I was curious if there exists any technique which allows you to do the same thing with ray tracing instead of ray marching?

One method I do know of is to ray trace a plane from above, and then where you hit the plane, calculate your location on a grid on that plane, and use the relative position in that grid cell as an absolute position to raytrace a scene.  That will repeat the scene across the grid.

However, a problem with that is if your ray doesn't hit anything in the grid cell, and it would then enter another grid cell, this technique won't catch those other shapes without walking the grid cells down the path of the ray until it exits the back side of the grid, which is very ray-marching-esque and iterative.

Does anyone know of a technique that allows you to have ray marching type repetition in ray tracing?
I've tried to figure this out as well, but I don't think there is a solution that is just as performant as tracing one sphere.  Basically you would want to cast one ray to hit a infinite set of repeating spheres with no marching iteration.  That would be awesome but is not possible:  Let me explain.

 

Ray-tracing is basically finding the analytical solution to this equation:
$$
f(\vec{r(t)}) = 0 \ for \ t
$$

Where $f(\vec{p})$ is the implicit surface function (which gives the distance the given point $\vec{p}$ is from the surface) and $\vec{r(t)}$ is the parametric ray equation ($\vec{r(t)} = \vec{origin} + \vec{direction}*t$).  $t$ would represent the distance along the ray the intersection happens.

In order to ray-trace domain manipulations (like repeating space), these domain manipulations need to be present in the implicit surface function $f(\vec{p})$ while finding an analytical solution.  Let's take a 3D repeating sphere for instance.
$$
f'(\vec{p}) = \|\vec{p}\bmod \vec{d}\| - r
$$
(where $\vec{d}$ is a constant representing the grid size and $r$ is the radius)

In order to solve $f'(\vec{r(t)}) = 0$ for $t$ we would need the inverse of the modulo operator which doesn't really exist : http://mathforum.org/library/drmath/view/51619.html.  That means there is no analytical solution to this equation, but there is a numerical one. Hence Ray-marching.

 

This is true for a lot of cool distance functions you see on shadertoy.com, the analytical solution does not exist for these surfaces so you cannot ray-trace.