In
mathematics
Mathematics is a field of study that discovers and organizes methods, Mathematical theory, theories and theorems that are developed and Mathematical proof, proved for the needs of empirical sciences and mathematics itself. There are many ar ...
and its applications, the signed distance function or signed distance field (SDF) is the
orthogonal distance of a given point ''x'' to the
boundary of a
set
Set, The Set, SET or SETS may refer to:
Science, technology, and mathematics Mathematics
*Set (mathematics), a collection of elements
*Category of sets, the category whose objects and morphisms are sets and total functions, respectively
Electro ...
Ω in a
metric space
In mathematics, a metric space is a Set (mathematics), set together with a notion of ''distance'' between its Element (mathematics), elements, usually called point (geometry), points. The distance is measured by a function (mathematics), functi ...
(such as the surface of a geometric shape), with the
sign
A sign is an object, quality, event, or entity whose presence or occurrence indicates the probable presence or occurrence of something else. A natural sign bears a causal relation to its object—for instance, thunder is a sign of storm, or me ...
determined by whether or not ''x'' is in the
interior of Ω. The
function
Function or functionality may refer to:
Computing
* Function key, a type of key on computer keyboards
* Function model, a structured representation of processes in a system
* Function object or functor or functionoid, a concept of object-orie ...
has positive values at points ''x'' inside Ω, it decreases in value as ''x'' approaches the boundary of Ω where the signed distance function is zero, and it takes negative values outside of Ω. However, the alternative convention is also sometimes taken instead (i.e., negative inside Ω and positive outside). The concept also sometimes goes by the name oriented distance function/field.
Definition
Let be a
subset
In mathematics, a Set (mathematics), set ''A'' is a subset of a set ''B'' if all Element (mathematics), elements of ''A'' are also elements of ''B''; ''B'' is then a superset of ''A''. It is possible for ''A'' and ''B'' to be equal; if they a ...
of a
metric space
In mathematics, a metric space is a Set (mathematics), set together with a notion of ''distance'' between its Element (mathematics), elements, usually called point (geometry), points. The distance is measured by a function (mathematics), functi ...
with
metric
Metric or metrical may refer to:
Measuring
* Metric system, an internationally adopted decimal system of measurement
* An adjective indicating relation to measurement in general, or a noun describing a specific type of measurement
Mathematics
...
, and
be its
boundary. The distance between a point of and the subset
of is defined as usual as
:
where
denotes the
infimum
In mathematics, the infimum (abbreviated inf; : infima) of a subset S of a partially ordered set P is the greatest element in P that is less than or equal to each element of S, if such an element exists. If the infimum of S exists, it is unique ...
.
The ''signed distance function'' from a point of to
is defined by
:
Properties in Euclidean space
If Ω is a subset of the
Euclidean space
Euclidean space is the fundamental space of geometry, intended to represent physical space. Originally, in Euclid's ''Elements'', it was the three-dimensional space of Euclidean geometry, but in modern mathematics there are ''Euclidean spaces ...
R
''n'' with
piecewise
In mathematics, a piecewise function (also called a piecewise-defined function, a hybrid function, or a function defined by cases) is a function whose domain is partitioned into several intervals ("subdomains") on which the function may be ...
smooth boundary, then the signed distance function is differentiable
almost everywhere
In measure theory (a branch of mathematical analysis), a property holds almost everywhere if, in a technical sense, the set for which the property holds takes up nearly all possibilities. The notion of "almost everywhere" is a companion notion to ...
, and its
gradient
In vector calculus, the gradient of a scalar-valued differentiable function f of several variables is the vector field (or vector-valued function) \nabla f whose value at a point p gives the direction and the rate of fastest increase. The g ...
satisfies the
eikonal equation
An eikonal equation (from Greek εἰκών, image) is a non-linear first-order partial differential equation that is encountered in problems of wave propagation.
The classical eikonal equation in geometric optics is a differential equation of t ...
:
If the boundary of Ω is ''C''
''k'' for ''k'' ≥ 2 (see
Differentiability classes) then ''d'' is ''C''
''k'' on points sufficiently close to the boundary of Ω. In particular, ''on'' the boundary ''f'' satisfies
:
where ''N'' is the inward
normal vector
In geometry, a normal is an object (e.g. a line, ray, or vector) that is perpendicular to a given object. For example, the normal line to a plane curve at a given point is the infinite straight line perpendicular to the tangent line to the cu ...
field. The signed distance function is thus a differentiable extension of the normal vector field. In particular, the
Hessian of the signed distance function on the boundary of Ω gives the
Weingarten map.
If, further, Γ is a region sufficiently close to the boundary of Ω that ''f'' is twice continuously differentiable on it, then there is an explicit formula involving the Weingarten map ''W''
''x'' for the Jacobian of changing variables in terms of the signed distance function and nearest boundary point. Specifically, if ''T''(''∂''Ω, ''μ'') is the set of points within distance ''μ'' of the boundary of Ω (i.e. the
tubular neighbourhood of radius ''μ''), and ''g'' is an
absolutely integrable function on Γ, then
:
where denotes the
determinant
In mathematics, the determinant is a Scalar (mathematics), scalar-valued function (mathematics), function of the entries of a square matrix. The determinant of a matrix is commonly denoted , , or . Its value characterizes some properties of the ...
and ''dS''
''u'' indicates that we are taking the
surface integral
In mathematics, particularly multivariable calculus, a surface integral is a generalization of multiple integrals to integration over surfaces. It can be thought of as the double integral analogue of the line integral. Given a surface, o ...
.
Algorithms
Algorithm
In mathematics and computer science, an algorithm () is a finite sequence of Rigour#Mathematics, mathematically rigorous instructions, typically used to solve a class of specific Computational problem, problems or to perform a computation. Algo ...
s for calculating the signed distance function include the efficient
fast marching method,
fast sweeping method In applied mathematics, the fast sweeping method is a numerical method for solving boundary value problems of the Eikonal equation.
: , \nabla u(\mathbf), = \frac 1 \text \mathbf \in \Omega
: u(\mathbf) = 0 \text \mathbf \in \partial \Omega
...
and the more general
level-set method.
For
voxel
In computing, a voxel is a representation of a value on a three-dimensional regular grid, akin to the two-dimensional pixel. Voxels are frequently used in the Data visualization, visualization and analysis of medical imaging, medical and scient ...
rendering, a fast algorithm for calculating the SDF in
taxicab geometry
Taxicab geometry or Manhattan geometry is geometry where the familiar Euclidean distance is ignored, and the distance between two points is instead defined to be the sum of the absolute differences of their respective Cartesian coordinates, a dis ...
uses
summed-area tables.
Applications

Signed distance functions are applied, for example, in
real-time rendering
Real-time computer graphics or real-time rendering is the sub-field of computer graphics focused on producing and analyzing images in real time. The term can refer to anything from rendering an application's graphical user interface ( GUI) to ...
,
for instance the method of
SDF ray marching, and
computer vision
Computer vision tasks include methods for image sensor, acquiring, Image processing, processing, Image analysis, analyzing, and understanding digital images, and extraction of high-dimensional data from the real world in order to produce numerical ...
.
SDF has been used to describe object geometry in
real-time rendering
Real-time computer graphics or real-time rendering is the sub-field of computer graphics focused on producing and analyzing images in real time. The term can refer to anything from rendering an application's graphical user interface ( GUI) to ...
, usually in a raymarching context, starting in the mid 2000s. By 2007,
Valve
A valve is a device or natural object that regulates, directs or controls the flow of a fluid (gases, liquids, fluidized solids, or Slurry, slurries) by opening, closing, or partially obstructing various passageways. Valves are technically Pip ...
is using SDFs to render large pixel-size (or
high DPI)
smooth fonts with
GPU acceleration in its games. Valve's method is not perfect as it runs in
raster space in order to avoid the computational complexity of solving the problem in the (continuous) vector space. The rendered text often loses sharp corners. In 2014, an improved method was presented by
Behdad Esfahbod. Behdad's GLyphy approximates the font's
Bézier curve
A Bézier curve ( , ) is a parametric equation, parametric curve used in computer graphics and related fields. A set of discrete "control points" defines a smooth, continuous curve by means of a formula. Usually the curve is intended to approxima ...
s with arc splines, accelerated by grid-based
discretization
In applied mathematics, discretization is the process of transferring continuous functions, models, variables, and equations into discrete counterparts. This process is usually carried out as a first step toward making them suitable for numeri ...
techniques (which culls too-far-away points) to run in real time.
A modified version of SDF was introduced as a
loss function
In mathematical optimization and decision theory, a loss function or cost function (sometimes also called an error function) is a function that maps an event or values of one or more variables onto a real number intuitively representing some "cost ...
to minimise the error in interpenetration of pixels while rendering multiple objects. In particular, for any pixel that does not belong to an object, if it lies outside the object in rendition, no penalty is imposed; if it does, a positive value proportional to its distance inside the object is imposed.
:
In 2020, the
FOSS
Free and open-source software (FOSS) is software available under a license that grants users the right to use, modify, and distribute the software modified or not to everyone free of charge. FOSS is an inclusive umbrella term encompassing free ...
game engine
Godot 4.0 received SDF-based real-time
global illumination
Global illumination (GI), or indirect illumination, is a group of algorithms used in 3D computer graphics that are meant to add more realistic lighting
Lighting or illumination is the deliberate use of light to achieve practical or aest ...
(SDFGI), that became a compromise between more realistic voxel-based GI and baked GI. Its core advantage is that it can be applied to infinite space, which allows developers to use it for open-world games.
In 2023, the authors of the
Zed text editor announced a GPUI framework that draws all UI elements using the GPU at 120 fps. The work makes use of Inigo Quilez's list of geometric primitives in SDF,
Figma
Figma is a collaborative web application for interface design, with additional offline features enabled by desktop applications for macOS and Windows. The feature set of Figma focuses on user interface and user experience design, with an empha ...
co-founder Evan Wallace's
Gaussian blur
In image processing, a Gaussian blur (also known as Gaussian smoothing) is the result of blurring an image by a Gaussian function (named after mathematician and scientist Carl Friedrich Gauss).
It is a widely used effect in graphics software, ...
in SDF, and a new rounded rectangle SDF.
See also
*
Distance function
In mathematics, a metric space is a set together with a notion of ''distance'' between its elements, usually called points. The distance is measured by a function called a metric or distance function. Metric spaces are a general setting fo ...
*
Level-set method
*
Eikonal equation
An eikonal equation (from Greek εἰκών, image) is a non-linear first-order partial differential equation that is encountered in problems of wave propagation.
The classical eikonal equation in geometric optics is a differential equation of t ...
*
Parallel curve
A parallel of a curve is the envelope (mathematics), envelope of a family of Congruence (geometry), congruent circles centered on the curve.
It generalises the concept of ''parallel (geometry), parallel (straight) lines''. It can also be defi ...
(also known as offset curve)
*
Signed arc length
*
Signed area
In mathematics, the signed area or oriented area of a region of an affine plane is its area with orientation specified by the positive or negative sign, that is "plus" () or "minus" (). More generally, the signed area of an arbitrary surface r ...
*
Signed measure
In mathematics, a signed measure is a generalization of the concept of (positive) measure by allowing the set function to take negative values, i.e., to acquire sign.
Definition
There are two slightly different concepts of a signed measure, de ...
*
Signed volume
Notes
References
*
*{{cite book , author1-last=Gilbarg , author1-first=D. , author2-last=Trudinger , author2-first=N. S. , year=1983 , edition=2nd , title=Elliptic Partial Differential Equations of Second Order , publisher=Springer-Verlag , volume=224 , series=Grundlehren der mathematischen Wissenschaften (or the Appendix of the 1977 1st ed.)
Applied mathematics
Distance
Sign (mathematics)
Implicit surface modeling