
easy to implement and allow us to perform hardware
interpolation of neighbouring points, making sam-
pling efficient. A brute force approach to generate
uniform SDF is ray sampling (Wright, 2015).
For each discrete point in the distance field, we
shoot rays in random directions to query the distance
to the closest mesh. To calculate the direction, we ran-
domly generate a point on the surface of a sphere with
a uniform distribution (Weisstein, 2019). The mini-
mum distance traced for each point is stored in the
red channel of a 400 ×200 ×400 3D texture. Rays
traced in future frames will overwrite the value if the
newer value is smaller. To determine the sign, we first
check if it is a front or back face hit via the dot prod-
uct of the ray direction and normal of the primitive
intersected. We then accumulate the number of front
and back face hits in the green and blue channels of
the texture. Finally, we set the sign to negative if the
majority of hits are back face hits (Wright, 2015).
2.2 Jump Flooding
The jump flooding algorithm (JFA) (Rong and Tan,
2006) which can be run on parallel on the GPU al-
lows us to generate an approximate SDF in real-time.
We first initialize a 3D SDF texture where each texel
represents a 3D point or a grid point. JFA gives us in-
formation about the closest seed at any point in space.
Setting every point on each triangle in the mesh as a
seed, we can obtain the closest distance to a surface
for our distance field. To determine if a grid point
contains a triangle efficiently, we voxelize the scene
with voxel resolution equal to our final distance field.
After voxelization, we simply check if a grid point
contains a model voxel to determine if it is a seed.
We now have a 3D texture containing grid points
that are either empty or are seeds. Without loss of
generality, we assume that the dimensions of the 3D
texture are equal (i.e. 3D cube) and that its length n
is a power of 2. For each grid point, we query a con-
stant number of neighbouring grid points a predefined
offset away. For each query, if the queried grid point
is a seed or contains seed information, we check if
that seed is closer to its currently stored seed and up-
date its seed information if so. We start with an offset
of length n
2and halve it for each subsequent iteration
until it reaches 1 for our final iteration.
With current GPUs that can write to 3D textures,
we adapt the 2D JFA algorithm (Rong and Tan, 2006)
for 3D space. During a single iteration, we run the
querying in parallel, allowing us to use the GPU to
accelerate the calculations. However, the algorithm
produces an unsigned distance field. To determine the
sign, we subtract a small βfrom the distance field,
causing surface points to be of negative value and ef-
fectively thickening the surface. The surfaces gener-
ated are also hollow as they contain positive values in
their interior. With jump flooding, we can generate
an approximate SDF in real-time for a decently large
resolution of 2563at 30ms and 1283at 2.34ms.
2.3 Ray Mask
We obtain a rough approximation of the SDF or
coarse SDF via jump flooding to locate regions in the
scene to apply ray tracing. In raymarching, regions
far from the surface act as a way to accelerate the pro-
cess but closer regions require a more accurate surface
representation. Hence, we can detect regions closer to
surfaces based on a distance dfrom the coarse SDF
and only ray trace in these regions at a higher resolu-
tion for better surface representation. Essentially, the
coarse SDF is a ray mask that determines which ar-
eas in the SDF should be ray-traced to generate a fine
SDF as shown in Figure 2. dcan be used to trade-off
performance for accuracy where a larger dresults in
more rays traced as texels further from surfaces would
be within ddistance from a surface point.
(a) Coarse SDF (b) Fine SDF
Figure 2: Slice of SDF.
Unlike adaptively sampled fields which increase
the resolution at regions with finer details, we limit
the number of levels of detail to two as generation
of hierarchical SDF is difficult to parallelize (Liu and
Kim, 2014). Additionally, real-time traversal of the
SDF may require multiple texture lookups to sample
until the leaf node despite saving space with a sparse
voxel texture (Aaltonen, 2018).
With the combination of the techniques, we turn
a blocky representation of the scene into a more re-
fined triangle mesh representation without ray tracing
every texel in the SDF as shown in Figure 3. Addi-
tionally, we can resolve issues identified in the jump
flooding of voxelization of thin surfaces. As seen in
Figure 4, while the coarse SDF gets a disconnected
representation of the plant, we fill in the holes through
refinement with the ray trace pass.
2.4 Raymarching
While SDFs are surface representations, they only
provide proximity information without a direction. To