2nd Order Implicit Surface Distance

The Shadertoy demo (https://www.shadertoy.com/view/MdtXWM) shows how to approximate the distance of an implicit surface using a second order approximation. Usually, a first order one is used. This second order version can help in more tricky surfaces, which would otherwise require smaller tracing stepsizes.

The second order approximation for a function f\operatorname{f} at point q\mathbf{q} is:

(f(q)2Hf(q)2+2f(q)Hf(q)f(q)Hf(q))sign(f(q));(\sqrt{ \frac{||\nabla \operatorname{f}(\mathbf{q})||^2 }{||\mathbf{H}_{\operatorname{f}}(\mathbf{q})||^2} + 2 \frac{|\operatorname{f}(\mathbf{q})|}{||\mathbf{H}_{\operatorname{f}}(\mathbf{q})||} } - \frac{||\nabla \operatorname{f}(\mathbf{q})||}{||\mathbf{H}_{\operatorname{f}}(\mathbf{q})||}) \operatorname{sign}(\operatorname{f}(\mathbf{q}));

Here, f\nabla \operatorname{f} is the gradient of f\operatorname{f} and Hf\mathbf{H}_{\operatorname{f}} is its Hessian. The norm of the Hessian (as it is a matrix) can be chosen arbitrarily, as long as it is a norm compatible with the dot product. The smallest such norm is the spectral norm, but the Frobenius norm can also be chosen as it is fast to calculate. As shadertoy embeds don't seem to work anymore, here is an image of one of the shapes included in the shader. On the left is the first order approximation, on the right the second order one:

On the left is the first order approximation, on the right the second order one