by gh123man · 6y ago · 0 comments
From this, a regular grid of probes are placed and integrated using the data from the SDF, using ray-marching. Material shading reads from the probes.
While I wouldn't insist on it, I think you could even argue that it's the other way around, ray tracing could be seen as a subset of ray marching, because it's possible to build a ray tracing query out of ray marching, but not possible to build a ray marching query using ray tracing, for example, the kind of basic ray marching you find on ShaderToy can tell you by how much you almost hit a surface, but vanilla ray tracing can't.
SDF ray marching is quite commonly used in the demo scene and on ShaderToy without an acceleration structure (or "BVH" - Bounding Volume Hierarchy), while ray tracing usually has one. It's common for SDF ray marching scenes to have a very limited number of procedural hand-coded primitives, while ray tracing usually has a lot of simple primitives like triangles and spheres that come out of some modeling tool.
The Godot engine, however, has a BVH, so their SDF complexity will depend on that.
In it's inner loop, SDF ray marching does a point query against the BVH, while ray tracing does a line query. Both will end up traversing along the line (ray) through the BVH.
I'd guess that, attempting to compare apples to apples, ray marching has a slightly higher complexity in practice than ray tracing since it takes multiple iterations to reach a surface, where ray tracing (usually) gets there in one step. But there are multiple factors that can offset this complexity difference, because there are some amazing tricks you can play with ray marching to reduce the number of rays, and because ray marching often better utilizes a GPU.