视觉人工智能指南

有符号距离函数

A signed distance function (SDF) describes a shape by giving, for any point in space, the distance to the nearest surface, with a sign that says whether the point is inside or outside.

听听这个指南AI叙述 · ~9 min

在本页10 分钟阅读
  1. 概述
  2. 主要要点
  3. 深入探讨
  4. Sphere tracing a ray against a sphere SDF
  5. 现实世界的实施
  6. 有符号距离函数的未来
  7. 付诸实践
  8. 资料来源与延伸阅读
  9. 不断探索
  10. 常见问题

概述

The surface is wherever the value is zero. SDFs drive real-time ray-marched graphics, depth-camera 3D scanning and neural 3D reconstruction methods such as DeepSDF and NeuS.

主要要点

  1. A signed distance function returns the distance to the nearest surface, negative inside and positive outside by the DeepSDF convention.
  2. The surface of an SDF is its zero level set, and its gradient at the surface gives the normal.
  3. Sphere tracing, described by John C. Hart in 1996, renders SDFs by stepping along each ray by the distance value.
  4. Union of two SDFs is min(a, b), while intersection and subtraction produce distance bounds rather than exact distances.
  5. Curless and Levoy's 1996 SIGGRAPH paper fused up to 70 range scans into a cumulative weighted signed distance volume.
  6. DeepSDF in 2019 represented a whole category of ShapeNet shapes with a single 7.4 MB neural network.

深入探讨

A signed distance function, usually shortened to SDF, is a rule that takes any point in space and returns one number: how far that point is from the nearest surface of a shape. The sign carries extra information. By the most common convention, used in the DeepSDF paper, points inside the shape get negative values and points outside get positive values. The surface itself is the set of points where the function equals zero, called the zero level set. A sphere of radius r centered at the origin is the simplest example: its SDF is the length of the point's position vector minus r. A point 3 units from the center of a sphere of radius 1 has a value of 2, and the center has a value of -1. Because the description is a function rather than a list of triangles, it is called an implicit representation of the surface.

An SDF can come from three places. It can be written as a formula, as shader programmers do for spheres, boxes, capsules and tori. It can be stored as samples on a 3D grid of voxels, small cubes of space, with values between grid points interpolated. Or it can be learned by a neural network that takes a 3D coordinate as input and outputs the distance. In every case the same two operations matter: evaluating the distance at a point, and finding where the value crosses zero.

Rendering an SDF directly uses a technique called sphere tracing, described by John C. Hart in The Visual Computer in 1996. A ray leaves the camera. At each step the renderer evaluates the SDF at the current point. That value is the radius of a sphere guaranteed to contain no surface, so the ray can safely jump forward by exactly that much. Steps are long in empty space and shrink as the ray approaches a surface, and the loop stops when the value falls below a small threshold. The guarantee holds when the function never overstates the true distance, a property the paper ties to the Lipschitz condition, which limits how fast the function can change. The gradient of the SDF at the hit point gives the surface normal for lighting.

Combining shapes is where SDFs become a modeling tool. Given two SDFs a and b, the union of the shapes is min(a, b), the intersection is max(a, b), and subtracting a from b is max(-a, b). Smooth versions replace min and max with blended functions controlled by a radius k, producing organic joins without seams. Inigo Quilez's widely used reference of distance functions makes an important distinction: basic primitives such as the sphere and box are exact, while subtraction, intersection, smooth blends and non-uniform scaling produce bounds, values that are never larger than the true distance but may be smaller. Bounds still render correctly with sphere tracing but need more steps, and they can break effects that rely on true distances, such as soft shadows.

SDFs also became the standard way to merge real scans. In 1996 Brian Curless and Marc Levoy presented a volumetric method at SIGGRAPH that adds each range image into a cumulative weighted signed distance function stored on a grid, then extracts the zero isosurface. They showed the result is least-squares optimal under certain assumptions, integrated up to 70 range images, and produced models of about 2.6 million triangles. The DeepSDF authors credit that work and KinectFusion (Newcombe and colleagues, 2011) as the pioneers of truncated SDF fusion, in which distances are stored only near the surface. KinectFusion applied the idea in real time with a moving Kinect depth camera.

Neural SDFs arrived in 2019. DeepSDF, from researchers at the University of Washington, MIT and Facebook Reality Labs, trained an eight-layer fully connected network with 512-unit layers to output the SDF of a shape given a 3D point and a latent code, a short vector identifying which shape. Training samples 500,000 points per ShapeNet mesh, concentrated near the surface, and clamps distances to 0.1 so capacity is spent near the surface. One network represented an entire shape category in 7.4 MB, and the paper reports state-of-the-art shape reconstruction and completion from partial, noisy scans. In 2020 Implicit Geometric Regularization (IGR) showed that a network could be fit to raw point clouds with a loss that makes the function vanish on the points and keeps its gradient at unit length. In 2021 NeuS learned SDFs from photographs by deriving a volume-rendering formulation that is unbiased to first order at the surface, and reported better Chamfer distance than IDR and NeRF on the DTU benchmark.

Compared with the alternatives, SDFs trade explicitness for convenience. Triangle meshes are what graphics hardware draws fastest, but they make topology changes and inside-outside queries awkward. Occupancy fields store only inside or outside, which loses the distance information that sphere tracing and collision tests use. Point clouds have no surface at all. Density fields such as the original NeRF render well, but the NeuS authors note that extracting high-quality surfaces from them is difficult because the representation has too few surface constraints. An SDF gives a well-defined surface, cheap inside tests, smooth normals from the gradient, and arbitrary topology, and a mesh can always be extracted with Marching Cubes when one is needed.

The limitations are concrete. A sign requires a closed shape; the DeepSDF authors note that human-made meshes are often not watertight and contain internal structures that must be cleaned before distances can be computed. Grid SDFs grow with the cube of resolution, which is why fusion systems truncate them. Neural SDFs are limited by the number of sample points and the network's capacity, and they must be evaluated many times per ray. Learned functions are not guaranteed to be true distances everywhere, which is why IGR and NeuS add an Eikonal term that pushes the gradient length toward one. Optimization can also be slow: NeuS trained each scene for 300,000 iterations, about 14 to 16 hours on a single NVIDIA RTX 2080 Ti GPU.

In practice the cost depends on the representation. Analytic SDFs cost almost nothing to store and run in real time in a fragment shader. Voxel SDFs need memory proportional to the grid size but allow constant-time lookups. Neural SDFs compress shapes well, as DeepSDF's 7.4 MB category model shows, but each query is a full network evaluation, so rendering and mesh extraction need a GPU and careful sampling.

04工作示例

Sphere tracing a ray against a sphere SDF

  1. Define the scene as a sphere of radius 1 at the origin, so f(p) = length(p) - 1.

  2. Start a ray at o = (0, 0, -5) pointing along d = (0, 0, 1), with t = 0 and a hit threshold of 0.001.

  3. Evaluate f at (0, 0, -5): the distance is 5 - 1 = 4, so advance t to 4.

  4. Evaluate f at (0, 0, -1): the distance is 1 - 1 = 0, which is below the threshold, so report a hit at t = 4.

  5. Compute the normal as the normalized gradient of f at the hit point, which for a sphere is the hit position divided by its length, (0, 0, -1).

  6. Repeat with a ray offset sideways, such as o = (0.9, 0, -5), and count how many steps it takes as the ray grazes the sphere.

它显示了什么

A hit at distance 4 with normal pointing back toward the camera, found in two evaluations. Check it against the analytic ray-sphere intersection, which gives the same t = 4, and note that the grazing ray needs noticeably more steps because the distance values stay small near the silhouette.

现实世界的实施

Shader artists build entire scenes from exact SDF primitives and combine them with min and max operators; Inigo Quilez's reference page lists the formulas and notes which operations keep distances exact.

Curless and Levoy's 1996 SIGGRAPH method merged up to 70 laser range scans into a cumulative weighted signed distance volume and extracted models of about 2.6 million triangles.

Microsoft Research's KinectFusion project, established in 2011, tracked a handheld depth camera and fused its frames into a 3D surface in real time, building on truncated SDF fusion.

DeepSDF (2019) trained one neural network to represent thousands of ShapeNet chair models in 7.4 MB, less than half the size of a single uncompressed 512-cubed voxel grid.

NeuS (2021) reconstructs object surfaces from ordinary photos by learning a neural SDF through volume rendering, evaluated on 15 DTU scenes with 49 or 64 images each.

有符号距离函数的未来

Research since DeepSDF in 2019 has focused on making learned SDFs more accurate, faster and easier to train from ordinary data. IGR (2020) showed that a simple Eikonal regularizer can recover smooth surfaces from raw point clouds, and NeuS (2021) showed that photographs alone, without foreground masks, can supervise a neural SDF. Open problems named or implied in these papers include thin structures, non-watertight inputs, per-scene training times measured in hours, and the cost of evaluating a network many times along each ray. In graphics practice, analytic SDFs remain a staple of shader programming, and Inigo Quilez's reference continues to document which operators preserve exact distances. In scanning, the truncated SDF fusion approach that Curless and Levoy introduced in 1996 and KinectFusion ran in real time in 2011 remains a common baseline for depth-camera reconstruction. Whether future systems favor SDFs, density fields or explicit primitives for a given task is an active research question, and published benchmark results such as Chamfer distance on DTU are the reliable way to compare them.

付诸实践

为什么这很重要

  • 速度与规模. 视觉人工智能可以大规模自动化检查、检测和标记任务。
  • 构建选择. 创意团队可以通过更少的手动修改更快地构建概念原型。
  • 团队与工作流程. 操作可以使用以前难以处理的图像和视频信号。

留意

  • 如果出处不明,肖像权和同意可能会成为法律风险。
  • 模型性能可能因光照、人口统计和环境的不同而有所不同。
  • 除非监控置信阈值,否则误报可能会被忽视。

后续步骤

  1. 定义精确度、召回率和错误成本的接受标准。
  2. 使用符合实际生产条件的数据进行测试。
  3. 为低置信度或高影响力的预测添加人工审核。
  4. 跟踪模型漂移并在相机或数据集更改后重新验证。

资料来源与延伸阅读

  1. The Visual Computer (Springer)Sphere tracing: a geometric method for the antialiased ray tracing of implicit surfaces
  2. ACM SIGGRAPH History ArchiveA volumetric method for building complex models from range images
  3. Microsoft ResearchKinectFusion Project Page
  4. arXiv (Facebook Reality Labs)DeepSDF: Learning Continuous Signed Distance Functions for Shape Representation
  5. arXiv (ICML 2020)Implicit Geometric Regularization for Learning Shapes
  6. arXiv (NeurIPS 2021)NeuS: Learning Neural Implicit Surfaces by Volume Rendering for Multi-view Reconstruction
  7. Inigo QuilezDistance functions

不断探索

免费通讯

获取每日AI简报

每个工作日早晨提供三条经过验证的AI故事,使用简明英文撰写。永久免费,无广告。

每个工作日发送一封邮件。一键退订。我们永不出售或分享您的地址。

测试一下自己

Take the Signed Distance Functions quiz

每个答案即时反馈,课程通过后可获得可验证ID的可分享证书。

开始测验

支持免费AI教育。AI Understanding是一家501(c)(3)非营利组织——无广告,无付费墙,永不收费。 捐款

常见问题

什么是有符号距离函数?

A signed distance function (SDF) describes a shape by giving, for any point in space, the distance to the nearest surface, with a sign that says whether the point is inside or outside. The surface is wherever the value is zero. SDFs drive real-time ray-marched graphics, depth-camera 3D scanning and neural 3D reconstruction methods such as DeepSDF and NeuS.

对于给定的 3D 点,有符号距离函数返回什么?

SDF 将任意点映射到其距最近表面的距离;符号指示该点是在内部(负)还是在外部(正)。

SDF 的实际表面位于哪里?

表面是有符号距离恰好为零的点的集合,是内部和外部之间的边界。

Where does a true signed distance function satisfy the unit-gradient eikonal condition?

A true SDF has gradient magnitude one where it is differentiable, which holds almost everywhere; at nonsmooth points such as the medial axis, the gradient may be undefined.

球体追踪如何使用 SDF 值?

由于 SDF 给出了到最近表面的距离,因此光线可以安全地前进该距离而不会超调,重复直到达到零。

DeepSDF用什么来表示特定的形状?

DeepSDF 将每个形状编码为低维潜在向量,该向量调节预测 SDF 的网络,从而实现紧凑、连续的形状。