As an example, suppose we are trying to ray-trace a sphere. There are two options. The first one is to build a mesh of triangles approximating the sphere and ray trace it. Unfortunately, the more triangles we have, the more expensive this computation will be, because we need to call the
rayTriangleIntersect() once for each triangle. For the specific case of a sphere, though, there is a better way to do it: we can use a
raySphereIntersect() function, generated by solving the equation of the ray with the equation of a sphere,
x^2 + y^2 + z^2 = R^2. This requires only one call and is, thus, much less expensive.
My question is: is it possible to apply the same optimisation for different shapes? I.e., is there a technique to generate a surface that approaches certain mesh, allowing us to implement a specialised
rayIntersection() function for that surface?