O'Reilly logo

GPU PRO 3 by Wolfgang Engel

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

2
VI
Practical Binary Surface and
Solid Voxelization with Direct3D 11
Michael Schwarz
2.1 Introduction
Regular, discrete representations of potentially complex signals are routinely used
in many fields. They provide a comfortable domain in which to work, often facil-
itate processing, and are largely independent from the represented signal’s com-
plexity. In computer graphics, we encounter such representations mainly in the
form of two-dimensional images, like the final rendering result or a shadow map.
Their three-dimensional analog, and the focus of this chapter, is voxelizations
stored in voxel grids. They offer a volumetric representation of a scene, where
each grid cell, referred to as a voxel, encodes that part of the scene that is located
within the cell. In case of a binary voxelization, this encoding is particularly sim-
ple: merely two states are distinguished, where a set voxel indicates the presence
of some, and an unset voxel the absence of any, scene object.
Largely orthogonal to this encoding, two main flavors of voxelizations can be
distinguished (see Figure 2.1). In a surface voxelization (also called boundary
voxelization), the scene is interpreted as consisting solely of surfaces, that is, all
closed objects are assumed hollow. Therefore, only voxels overlapped by a surface
(like a scene triangle) will be nonempty. By contrast, a solid voxelization treats
all objects as solids, and hence, any voxel interior to an object will be set. Note
that this basically requires the objects to be closed.
Binary voxelizations are useful for many applications, ranging from
collision detection [Zhang et al. 07, Eisemann and D´ecoret 08] to ambient oc-
clusion [Reinbothe et al. 09], soft shadows [Forest et al. 10], area light visibil-
ity [Nichols et al. 10], and volumetric shadows [Wyman 11]. Unless confined
to static settings, they all mandate that the voxelization be created on the fly
at real-time speed. This chapter describes how this goal can be achieved using
Direct3D 11, covering the process of turning an input scene, given as a collection
337
338 VI GPGPU
(a) Surface voxelization. (b) Solid voxelization.
Figure 2.1. In a surface voxelization (a), the voxels overlapping the scene’s surfaces are
set, whereas in a solid voxelization (b), the voxels that are inside a scene object are set.
(For illustration purposes, the fronts of the voxelizations have been cut away, revealing
the interiors.)
of triangles, into a binary surface or solid voxelization. We first discuss imple-
mentations that build on the standard graphics pipeline and its rasterization
stage; these are rather simple and easy to implement but also suffer from several
shortcomings. Addressing some of them, we subsequently investigate alternative
realizations that employ DirectCompute.
2.2 Rasterization-Based Surface Voxelization
With surface voxelization basically being a three-dimensional extension of ras-
terization, it is natural to try to pose this process in terms of rasterization and
harness the according existing hardware units. Assuming a target voxel grid of
size w × h × d, a simple approach is to render the scene into a deep framebuffer
of resolution w × h with (at least) d bits per pixel (see Figure 2.2). Hence, for
each triangle, all pixels covered are determined, and a fragment is generated for
each of them. In the invoked pixel shader, those voxels within the voxel column
represented by the according deep pixel are identified that are actually covered
by the triangle. The resulting voxel-column pixel value is then output by the
shader and incorporated into the existing framebuffer.
2.2.1 Challenges
Unfortunately, this appealing approach faces several problems in practice. A
major issue is that in ordinary rasterization, a pixel is only considered to be cov-
ered by a triangle if the triangle overlaps the pixel’s center. This implies that
no fragments are generated for all those pixels that a triangle partially overlaps
without simultaneously overlapping their centers. Consequently, no voxels are

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required