The same effect can be used to make hidden 3D objects out of flat patterns. Let $S(x,y)$ be the color of a planar pattern at the point $(x,y)$. Now, if $S$ is horizontally repeating, i.e. $S(x,y)=S(x+W,y)$ for all $x,y$, then we will still perceive a flat pattern when focusing on the image that merges the two copies of the pattern. Let $(\pm d/2,0,0)$ be the co-ordinates of your eyes and consider an almost flat, imagined surface $z=Z(x,y)$. The rays $\mathbf{r}_\pm(t)$ from the eyes to a point $(x,y,Z(x,y))$ on the surface can be expressed by \[ \mathbf{r}_\pm (t) = \left[\pm \frac{d}{2} + t\left(x\mp \frac{d}{2}\right)\right]\mathbf{e}_x +ty\mathbf{e}_y + tZ(x,y)\mathbf{e}_z. \] Extending these rays until they reach a plane at $z=L$, we find that $t=L/Z(X,Y)$, so that the two resulting points in the flat $z=L$ plane corresponds to \[ \mathbf{R}_\pm (t) = \left[\frac{L}{Z}x \pm \frac{d}{2}\left(1-\frac{L}{Z}\right)\right]\mathbf{e}_x +\frac{L}{Z}y\mathbf{e}_y + L\mathbf{e}_z. \] This will perhaps be more informative if we introduce $Z(x,y)=L_0+\delta z(x,y)$ and perturb to first order around $\delta z=0$. Let us also omit the $z$-co-ordinate, knowing all points are in the same plane. The result is then \[ \begin{align*} \mathbf{R}_\pm^{xy} (t) &= \frac{L}{L_0+\delta z}x\mathbf{e}_x + \frac{L}{L_0+\delta z}y\mathbf{e}_y \pm \frac{d}{2}\mathbf{e}_x \mp \frac{d}{2}\frac{L}{L_0+\delta z}\mathbf{e}_x \\ &\simeq \frac{L}{L_0}\left[x \pm \frac{d}{2}\frac{L_0-L}{L} -\left(x\mp \frac{d}{2}\right)\frac{\delta z}{L_0}\right]\mathbf{e}_x +\frac{L}{L_0}\left[y -\frac{\delta z}{L_0}y\right]\mathbf{e}_y. \end{align*} \] The first thing we should note is that if our eyes is to believe the imagined object, then both eyes should receive the same color. That is, the pattern on the plane at $z=L$ should be horizontally repeating over a distance of \[ \Delta x = d\frac{L_0(L_0-L)+L\delta z}{L_0^2} = \Delta x_0 + d\frac{L\delta z}{L_0^2}. \] The $(x,y)$-dependence of $\delta z$ makes it hard to extend this pattern indefinitely, but at the end of the day, we only need neighbouring pairs of images to satisfy this relation. It is then an easy task to create a patterned slice of width $\Delta x_0$, to the right of it, we can copy the same pattern only distorting the pattern by the additional factor of $dL\delta z(x,y)/L_0^2$. The next slice would then be a copy of this one, again performing an additional distortion of $dL\delta z(x,y)/L_0^2$. The result of such a procedure can be enjoyed in the image on top of this post.
Use SPACE to toggle the display of the drawing in "Draw Image" mode. Use buttons UP and DOWN to toggle depth of drawing.