You are on page 1of 11

International Review on Computers and Software (I.RE.CO.S.), Vol. 3, n.

5
ISSN: 1828-6003

Per-Pixel Displacement Mapping Using Cone Tracing

Akram Halli1, Abderrahim Saaidi2, Khalid Satori3, Hamid Tairi4

Abstract – The technique of cone tracing, used for rendering very detailed surface in real-time,
is certainly among the best techniques at the present time. But unfortunately, in its two versions,
conservative and relaxed, this technique suffers from a heavy pre-processing having a quadratic
complexity. Moreover, the processing of non-square textures remains a problem. In this article we
introduce a new linear complexity algorithm for generating relaxed cone maps. Additionally, we
propose to use the Height Distributional Distance Transform HDDT for creating conservative
cone maps. The HDDT is a linear algorithm used in terrain rendering. We also introduce a new
method for supporting non-square textures using an elliptical rectification. Finally, we suggest
using the cones’ radius instead of their ratio. This eliminates the constraint limiting the cones’
apex angle to π/4 which significantly improves the performance of the cone tracing technique.

Keywords: Real time rendering, per-pixel displacement mapping, cone tracing.

Nomenclature
r r
V , V xy vector, sub-vector
Vx ,V y ,V z vector components
r r
V the Euclidean norm of V
Fig. 1. Image (a) represents a plan with texture mapping. Image (b)
dist e ( p, q ) the Euclidean distance between p and q shows the combination with per-pixel displacement mapping. As we
can notice, in both images, the mesh density is the same, but the
displacement mapping allows rendering very detailed geometry.

I. Introduction
can be used to store other data used in some techniques
Per-pixel displacement mapping is an approach like cone tracing. In that case the displacement map may
stemmed from the texture mapping. It is used to add be named according to its technique as, for example, the
very fine scale to polygonal meshes without increasing cone map.
their density (i.e. number of vertices and triangles) (see
Fig. 1). This technique allows rendering scenes with rich
visual effects while avoiding the bottleneck problem I.2. Tangent Space
caused by the huge number of data to be submitted to The tangent or TBN space (Tangent, Binormal, and
the graphics card. Normal) is a local modeling space attached to each
The displacement mapping technique is based on vertex of the mesh. This particular space is built
three main principles: the displacement map, tangent according to the normal of vertices and their texture
space and inverse ray tracing. coordinates. During the rendering stage, the tangent
space is interpolated for each fragment. TBN space is
very useful since the normals stored in the displacement
I.1. The Displacement Map map are naturally expressed in this space and it may be
The displacement map, also known as height map or very costly to transform each normal to another
depth map, is a two-dimensional image whose pixels are coordinate system. However, the lights and view vectors
not used to store colors but several data, to be specific, must be expressed in this space too.
depths and normals. The depths of the relief to be
mapped onto the 3D surface are often placed in the I.3. Inverse Ray Tracing
alpha channel. The other three channels: red, green and
blue are used to store the three coordinates x, y, and z of The main problem of the displacement mapping
the normals calculated from depths. But as the z technique is illustrated in Fig. 2. It lies in finding the
coordinate can be found from the two others, its channel first intersection point of the viewing ray with the

Manuscript received 5 Aug. 2008, revised 16 Oct. 2008 Copyright © 2008 Praise Worthy Prize S.r.l. - All rights reserved
A. Halli, A. Saaidi, K. Satori, H. Tairi

intersection. Per-pixel displacement mapping using cone


tracing exists in two versions. The first one uses
conservative cones [2] while the second uses relaxed
cones followed by a binary search [3]. Both variants use
an O(n2) complexity algorithms to generate the cone
map (where n is the total number of pixels). These two
pre-processors compute and store the cones’ ratio in a
free channel of the displacement map. It should be noted
that these two techniques have been primarily defined
for square textures.
Based on these observations, this paper makes the
following contributions:
§ A pre-processing algorithm with an O(n)
complexity instead of an O(n2) complexity, used to
generate relaxed cone maps.
§ Using the Height Distributional Distance
Transform HDDT [4] to compute conservative
cone maps. The HDDT is an O(n) complexity
algorithm used to generate cone maps for height
field ray tracing.
§ Extension to non-square textures suggesting a new
approach that makes an elliptical correction of the
cones during the rendering stage instead of a pre-
normalization which considerably slows the
convergence of ray tracing.
§ Calculation and storage of the cones’ radius
instead of their ratio. Thus we can have cones with
an apex angle up to π/2 instead of π/4, which
Fig. 2. Ray tracing of the depth field. (u,v) is the fragment currently improves visibly the results at rendering.
processed. (s,t) is the texel where the ray pierces the relief and (u’,v’)
is the texel where the ray leaves the relief, the latter depends on the
depth scale. (a) 3D view of the ray tracing. (b) The relief’s slice
including the viewing ray. (c) The depth map, here we can see that the
II. Related Work
intersection search is performed in 2D between texels (u,v) and The idea of using textures to simulate mesostructures
(u’,v’). (d) The corresponding color map, the fragment (u,v) will be
textured using the texel (s,t) instead of (u,v). was first introduced by Blinn [5]. Bump mapping
simulates the surface details using a normal
imaginary relief stored in the depth map. This perturbation. The texture coordinates and the geometry
intersection must be found for every rendered fragment remain unchanged. This technique is very fast but can't
using an inverse ray tracing algorithm. produce self-occlusions, shadows and silhouettes.
The speed constraint does not allow an exact search, Horizon maps [6] provide a shadow bump mapping
which inevitably means finding the nearest possible implemented by [7] and [8] using graphics hardware.
point to the intersection using a limited number of steps. Parallax mapping [9] optionally with offset limiting
Various solutions exist for solving this problem. [10] or with slope information [11] uses textures
Szirmay-Kalos and Umenhoffer [1] in their state of the augmented with per-texel depth. In this approach the
art in real-time displacement mapping have classified texture coordinates along the view ray direction are
these techniques into three categories: unsafe, safe (i.e. shifted according to the depth values. This technique
conservative) and combined techniques. They also produces nice results at a very low cost but it is only
provided a comparison between the different appropriate for noisy irregular bumps (it also does not
approaches. produce shadows and silhouette)
Displacement mapping [12] subdivides original
geometry into a large number of micro-polygons which
I.4. Contributions
are displaced perpendicularly according to a 2D height
Our contributions concern the cone tracing, which is map. This technique produces correct self-occlusions,
one of the best techniques for rendering 3D surface shadows and silhouettes. Unfortunately, displacement
details in real-time. In order to find the intersection mapping is unsuitable for real time rendering due to the
point between the viewing ray and the relief, this huge number of micro polygons to be rendered. To
technique uses a cone map to converge quickly to the overcome this problem, Patterson et Al [13] introduced

Copyright © 2008 Praise Worthy Prize S.r.l. - All rights reserved International Review on Computers and Software, Vol. 3, n. 5
A. Halli, A. Saaidi, K. Satori, H. Tairi

the idea of using per-Pixel (i.e. inverse) displacement correct, smooth and optionally curved shell mapping.
mapping. View-Dependent Displacement Mapping [29] and
Relief mapping [14], an extended technique of relief Generalized Displacement Mapping [30] do a pre-
texture mapping [15], performs an image space search to process shell space ray tracing and store the result as a
find the intersection point between the viewing ray and a five-dimensional function that can be queried during
2D depth map. It begins with a linear search using rendering time. These methods produce very nice results
regular intervals followed by a binary search to refine but require significant pre-processing and storage to
the intersection point. This technique correctly handles operate.
self-occlusions, shadows and inter-penetrations.
However some artefacts become visible at grazing
angles, especially with thin structures. Similar III. Cone Tracing
approaches to relief mapping were presented in [16], To find the first intersection between the viewing ray
[17], [18] and [19]. and the depth field surface, some techniques use unsafe
Instead of using unsafe approach, Donnelly [20] uses approaches (i.e. linear, binary or secant search).
sphere tracing. He creates a 3D distance map that gives Unfortunately, while these methods do not require
a measure of the distance between points in space and preprocessing and thus no additional data than the depth
the displaced surface. In the same way, Dummer [2] map and its derivatives, they may skip the first
uses top-opened cones as empty space bounding intersection point at grazing views or for fine scales,
volumes stored in a 2D cone step map. This idea was which results in important artifacts. To overcome this
first introduced by Paglieroni and Petersen [4] for height problem, some conservative methods were introduced
field ray tracing. Other conservative approaches were (sphere tracing, cylinder tracing, cone tracing or
proposed like the use of pyramidal structure [21], [22]. pyramidal tracing). These techniques compute and store
Baboud et Al [23] introduced the use of relaxed pre- additional data in a pre-processing stage. At the
computed volumes allowing safe binary search. They rendering step, this data is used for space leaping to
used a safety radius allowing cylinder tracing. In the avoid missing the first intersection with the relief. But
same way, Policarpo and Oliveira [3] relaxed the rule of with no guarantee of success especially if the number of
the conservative cones. steps is limited.
To resolve the problem of the flat silhouettes, In this section we first discuss two of these
Oliveira and Policarpo use a quadratic function to conservative techniques, the conservative cone tracing
approximate curved surfaces [24]. Hirche et al [25] and the recent relaxed cone tracing which combine
extrude the triangles of the base mesh along their space leaping with an unsafe method. We, then, propose
respective normal directions, and then the resulting to use cone radius instead of ratio and, finally, we
prisms are rendered by casting rays inside and present an extension to non-square displacement maps.
intersecting them with the displaced surface. The prisms
are subdivided into three tetrahedrons if the main mesh
is not planar. Porumbescu et al. [26] use barycentric III.1. Conservative cone tracing
coordinates of points inside tetrahedra to define a In cone step mapping, Dummer [2] assigns to each
mapping between points in the shell volume and texel of the depth map a top opened cone that represents
corresponding points in a 3D texture. Dufort et al. [27] the empty space above it. The cone ratio is computed
use the same technique with semi-transparent 3D during a pre-processing stage and stored in a free
textures in order to support more advanced features. channel of the displacement map called then the cone
Instead of using tetrahedral, Jeschke et al. [28] use a map.
smooth mapping function and Coons patch to render During the ray tracing stage, the next ray position is
defined as the intersection between the viewing ray and
the cone stored at the current texel. First, we normalize
r r r
the depth of the view ray (i.e. v = V / V z where V is the
normalized view ray). So according to Fig. 3, one can
write:
r
c v xy r
= = v xy
a vz
r
c = a × v xy (1)
Likewise:
Fig. 3. Ray tracing of the depth field using conservative cones. At c
= cone _ ratio
each step, the next ray position Pi+1 is calculated in term of the b
current position Pi, the viewing ray v and the value of a. v is
expressed in the TBN space of the current fragment P0

Copyright © 2008 Praise Worthy Prize S.r.l. - All rights reserved International Review on Computers and Software, Vol. 3, n. 5
A. Halli, A. Saaidi, K. Satori, H. Tairi

III.3. Using Cone Radius Instead of Ratio


Both conservative and relaxed cone tracing
techniques compute and use the cone ratio that is stored
in a single depth map channel. Since the textures used in
real-time rendering are usually in 8-bit integer format,
the number of possible values of ratios is only 256. For
this raison, both techniques chose to clamp the ratio’s
value to 1.0 (i.e. the apex angle to π/4). It should be
noted that Dummer stores the square root of the ratios to
have a better distribution.
Fig. 4. The binary search stage of relaxed cone tracing. The binary According to these observations, we propose to
search is performed between the last ray position after cone tracing Pn calculate and store the surface radius of the cones
(assumed under the surface) and the starting position P0 instead of the ratio. Since the cone ratio is the radius
divided by the depth, the combination of the radius
channel and the depth channel allows us to have up to
255x255 possible values for the cone ratio. Therefore,
c
= cone _ ratio (2) we no longer need to limit the ratio to 1 when integer
D[ Pi ] - a - Piz textures are used, which can then be theoretically
Solving (1) and (2) for a gives: infinite. Thus the apex angle can go up to π/2. The use
of cones radius will modify the equation (3). So, as
cone _ ratio × (D[ Pi ] - Piz ) we have:
a= r (3)
v xy + cone _ ratio cone _ ratio =
cone _ radius
(5)
D[ Pi ]
Finally, we compute the next ray position using the Equation (3) becomes:
equation (3), thus:
r cone _ radius × (D[ Pi ] - Piz )
Pi +1 = Pi + a × v (4) a= r
D[ Pi ] × v xy + cone _ radius

III.2. Relaxed Cone Tracing


The conservative cones are defined in such a way that III.4. Extension to Non-Square Depth Maps
the ray position never pierces the relief. This constraint Techniques using the distance (as the sphere tracing,
causes in some cases (like few steps, grazing views, or a cylinder tracing or cone tracing) are confronted to the
depth map with very fine details) visible distortions due problem of the non-orthonormal space of non-square
to the early ray tracing stops. Relaxed cone stepping [3] textures. Because the texture coordinates are afterward
eases the conservative rule and forces the cones to automatically normalized by the graphic pipeline.
intersect the surface whenever possible. This approach Authors of the previous techniques did not mention
was first used in [23] with cylinders. this issue in their articles, but they have nevertheless
In relaxed cone stepping, the ray tracing will be the taken it into account in their code. They chose to treat it
same as in the case of conservative cones using equation in the pre-processing stage by making the calculations
(4). At the end of this stage, we assume that the ray with normalized texel coordinates. This avoids the
position Pn is under the relief surface. Then we start a distortion problem due to the automatic normalization
binary search for refining the intersection point. As during the ray tracing. However this choice reduces
schematized in Fig. 4, the binary search is performed considerably the cones’ radius and thus slows down the
between the ray starting position P0 and its actual convergence of the cone tracing as schematized in
position Pn. Note that we can also use the last point over Fig._5.
the surface Pn-1 instead of P0. Unfortunately, saving Pn-1 To avoid this loss in the space leaping, we suggest
requires conditional statement in the code which will skipping the normalization during the pre-processing.
cause a performance drop. We can also use the secant Therefore, we report the distances only to one of the two
method described in [17] and [31] instead of the binary dimensions, the width for example (i.e. width→1).
search. Obviously this will induce errors during the cone tracing
It should be noted that the use of relaxed cones does as defined previously because, being in an orthonormal
not overcome all of the distortions due to the space, the cones are supposedly rounded, which is no
conservative approach, because in several cases the ray longer the case after the auto-normalization of non-
will never pierce the relief. square maps where the cones become oval. Thus, we can
note that for a given view ray, the ratio  between the
step length using elliptical cones and the step length
using rounded cones remains constant and depends only

Copyright © 2008 Praise Worthy Prize S.r.l. - All rights reserved International Review on Computers and Software, Vol. 3, n. 5
A. Halli, A. Saaidi, K. Satori, H. Tairi

IV. Pre-Processing
Giving a greyscale depth map, the pre-processor
creates the displacement map as an RGB texture that
stores the data used by the cone tracing technique. The
depth is assigned to the alpha channel while its x, y
derivatives are mapped to the [0,1] range and stored
respectively in the red and green channels. During the
rendering stage, the normal will be calculated using the
following formula:
(- scale × d x ,- scale × d y ,1)
N scale =
(- scale × d x ,- scale × d y ,1)
where scale is the depth scale, which can be
modulated in real-time.
Finally, the blue channel is used to store conservative
or relaxed cones using their ratio or radius. In this
section we first describe the existing quadratic
Fig. 5. Comparison between the two approaches for processing non- algorithms and, then we present the linear algorithms.
square maps. (a) A rectangular depth map where the texels r and q are Finally, we discuss the tilling options.
candidates to give the cone based on p (q and r have the same depth).
Here, the point q is the nearest to p so it gives the blue cone. (b)
Normalization before cone processing. In this case the texel r became
closer to p and thus gives the green cone. (c) The rendering stage. We
IV.1. Quadratic Algorithms
can clearly notice that the elliptical cone deduced from the blue cone
will gives the largest steps in all view’s directions (V) except for
directions following the largest dimension (V’), but in that case the Conservative cone Maps
difference is less important.
The pre-processor assigns a cone ratio to each texel
on the viewing ray and the ratio of the map dimensions. of the depth map. This cone represents the largest one
This ratio can be easily calculated from the equation of that does not pierce the relief. Dummer [2] instead of
the ellipse. It can be formulated as: using the HDDT [4] proposed an optimized O(n2)
r
V xy algorithm described as follows: for each texel, look
height
a= with R = outwardly (in expanding squares) for the minimal cone
V +R V
2 2 2 width ratio. This search is stopped when the current cone ratio
x y

where we can verify that: if width=height then =1 Algorithm 2: Relaxed Cones (Quadratic)
(square texture), and when Vy=0 then =1 because we Input : Depth Map D
chose to modulate the distances according to the width. Output : Cone Map C
 is calculated only once for a given viewing ray,
equation (4) becomes: for each texel t do
r r r C[t] = MAX_VALUE
Pi +1 = Pi + a × va with va = a × v
for each texel p do
ray = (p.x-t.x, p.y-t.y, D[p]) /* view ray */
ray = ray/ray.z /* scale view ray */
ray = ray × (1-D[p]) /* scale again */
Algorithm 1: Conservative Cones (Quadratic)
step = ray/SEARCH_STEPS /* step length */
Input : Depth Map D
pos = (p.x, p.y, D[p]) + step
Output : Cone Map C
for i=0 to SEARCH_STEPS do
if pos.z ≤ D(pos.xy) then
for each texel t do
pos = pos + step
C[t] = MAX_VALUE
else
for each texel p in each outward square S do
break
if C[t] > S_Radius/(D[t]-D[p]) then
end if
break /* process next texel t */
end for i
else if D[t] > D[p] then
if D[t] > pos.z then
C[t] = min( dist(t,p)/(D[t]-D[p]), C[t] )
C[t]=min(dist(t,pos.xy)/(D[t]-pos.z), C(t))
end if
end if
end for p
end for p
end for t
end for t

Copyright © 2008 Praise Worthy Prize S.r.l. - All rights reserved International Review on Computers and Software, Vol. 3, n. 5
A. Halli, A. Saaidi, K. Satori, H. Tairi

cannot be outdone by any subsequent square. The


corresponding pseudocode is listed in Algorithm 1.

Relaxed Cone Maps


Unlike conservative cones, relaxed cones are defined
with the following constraint: as a viewing ray travels
inside a cone, it cannot pierce the relief more than once,
so the resulting cones are obviously larger than the
conservative cones.
To calculate relaxed cone maps, Policarpo and Fig. 6. The quadratic algorithm may skip a bump and thus, some
Oliveira [3] used an O(n2) algorithm described by the grazing rays can pierce and leave the relief inside the relaxed cone
pseudocode shown in Algorithm 2. The idea is: for each area.
source texel t, trace a ray through each destination texel
p, this ray starts at (tx,ty,0) and points to (px,py,D[p]). For difference with an exact EDT lies only in some texels.
each such ray, compute its next (second) intersection Nevertheless, we can use linear algorithms that give an
with the depth field using an accurate linear search and, exact EDT.
then, use the intersection point to compute the cone ratio
Cp[t], the final ratio C[t] is given by the smallest of all Conservative Cone Maps
cone ratios computed for t.
The relaxed cones algorithm does not use an In order to present the main idea of this algorithm,
optimisation as in the conservative algorithm, so it is called Height Distributional Distance Transform
considerably slower. In addition, the algorithm as (HDDT) in [4], let us suppose that the depth map
described in [3] gives just an approximate solution, contains only two depth levels a and b. According to
since it may result on some errors as illustrated in Fig. 6. Fig. 7 (top) we can easily notice that the widest cone
To avoid such errors the ray used to find the second based on the texel t that does not pierce the relief is the
intersection must start at point (tx, ty, D[p]). This ray is one whose ratio is:
horizontal, so it is not adapted for the standard linear dist e (t , p)
search since it needs the intersection with the bottom of C[t ] = (6)
b-a
the relief. Then a Bresenham-like algorithm should be where t is a texel with the depth b and p is the closest
used to find the second intersection between this ray and texel to t having the depth a (with b>a). Therefore the
the depth field. Unfortunately, such a solution may make
the algorithm slower. Thus, we will not explore this way
since the linear algorithm does not suffer from this
problem.

IV.2. Linear Algorithm


The calculation of cones is based on the distance
between a given texel ti and the other texels pj in order
to find the minimal ratio of this distance to the
difference in depth between ti and pj. Therefore, the
Euclidean distance plays a major role. We, thus, propose
to use the Euclidean Distance Transform (EDT) of a
binary image that we will define next, knowing that
there are linear algorithms for computing the EDT.
The EDT is defined as follow: From a binary image B
made of an object O and its background O', an euclidean
distance transformation makes an image, the distance
map T, in which the value of any pixel is the Euclidean
distance from this pixel to the object O, i.e. the distance
to the nearest pixel of O.
T ( p ) = min{dist e ( p, q ), q Î O} Fig. 7. Computing conservative cones using the linear algorithm.
(Top) we suppose that the depth has only two values: a and b. Then
For the EDT computation, we opted for the 4SED we can easily notice that we can calculate the conservative cone based
EDT algorithm of Danielsson presented in [32], which on t using the minimal distance from t to areas with the depth a.
(bottom) extending the idea to several depths. Each depth less than d
has the advantage of being very fast while giving a very gives a cone. The conservative cone based on t is the smallest of these
good approximation of the distance transform. The cones (the blue one).

Copyright © 2008 Praise Worthy Prize S.r.l. - All rights reserved International Review on Computers and Software, Vol. 3, n. 5
A. Halli, A. Saaidi, K. Satori, H. Tairi

Algorithm 3 : Conservative Cones (Linear) Algorithm 4 : Relaxed Cones (Linear)


Input : Depth Map D Input : Depth Map D
Output : Cone Map C Output : Cone Map C
Intermediate: Binary Map B, Distance Map T Intermediate: Binary Map M /* local maxima */
Binary Map B, Distance Map T
for each level l of D do
for each texel t do M = LOCAL_MAXIMA( D ) /* if maximum 1 else 0 */
B[t] = {0 if D[t] ≤ l, 1 otherwise} for each level l of D ∩ M do /* level of maxima */
end for t for each texel t do
T = EDT( B ) /* distance of ones to zeros */ B[t] = {0 if D[t] ≤ l and M[t]==1, 1 otherwise}
for each texel t do end for t
if D[t] > l then T = EDT( B ) /* distance of ones to zeros */
C[t] = min( T[t]/(D[t]-l), C[t] ) for each texel t do
else if D[t] > l then
C[t] = MAX_VALUE C[t] = min( T[t]/(D[t]-l), C[t] )
end if else
end for t C[t] = MAX_VALUE
end for l end if
end for t
end for l
problem relates to the calculation of the Euclidean
Distance Transform of the binary image composed by
the two depths a and b. Thus, the ratio of the cones number of the depth map levels. Therefore, the
based on texels with depth b will be calculated using this algorithm for the calculation of conservative cone maps
EDT according to (6). For texels with depth a, their is also a linear algorithm.
ratio will not be calculated from the EDT, because their Of course, the complexity depends on the number of
value is equal to 0 and, thus, will keep their initial ratio depth levels, but 256 levels (i.e 8 bits both for integer or
which is the maximal value in this case. real format) are largely sufficient for rendering surface
In view of the fact that the depth map is a greyscale details. Note that this algorithm is not limited to integer
image (usually 256 levels), thus, the relief is constituted depths.
by several depth levels (see Fig. 7). Then we just have to
calculate the cone ratio of each level using the EDT of Relaxed Cone Maps
the binary image constituted by 1 for texels with depth
above l and 0 for the other texels. The cone ratio will be Although, in the quadratic case, the conservative cone
changed if its value is less than that previously algorithm and the relaxed cone algorithm are rather
calculated. The pseudocode of this algorithm is shown different, let us try to use the same approach in their
in Algorithm 3. Note that we use the same algorithm to linear version (i.e. using the EDT). We can notice that
calculate the cone map both for storing ratios or radii the relaxed cones such as they were defined in [3] are
using (5). the cones that pass by the local maxima of the depth
The calculation of the EDT of a binary image is an map. Thus, the relaxed cone based on a given texel t is
algorithm with a linear complexity O(n) (where n=width the smallest of cones based on t and go through a local
x height). In our case, the calculation of the EDT is maximum of the relief (see Fig. 8).
repeated a constant number of times which is the

Fig. 9. Comparison between the linear and the quadratic relaxed cones
algorithms when the depth map includes uniform areas. The quadratic
algorithm results on wider cones (it detects the point r) while the
Fig. 8. The relaxed cone based on the texel t is the most narrow cone linear algorithm take the nearest point q. note that this schema is just
(the blue one) going by a local maximum of the relief (here the a 2D slice, thus for other slices the distance between r and q can be
maximum a) zero.

Copyright © 2008 Praise Worthy Prize S.r.l. - All rights reserved International Review on Computers and Software, Vol. 3, n. 5
A. Halli, A. Saaidi, K. Satori, H. Tairi

detect the tangential point to the uniform area while the


linear algorithm always detects the closet point to this
area.

IV.3. Tilling Cone Maps

If the displacement map must be tilled, we must take


into account the tilling version. In the quadratic
algorithms, we can access extra texels using shift or
mirror functions. That allows us to compute shifted and
mirrored tilling versions of the cone map. But in the
linear algorithms, which use the distance transform,
processing the depth map directly gives only the
mirrored tilling version. To generate the shifted version,
we use, in an intermediate process, a double size depth
map created by shifting the original one. Then we
compute its cone map and, finally, we extract the middle
portion as schematized in the Fig. 10.
Fig. 10. Computing the shifted tilling version of cone maps. First we
create a 2x shifted depth map from the original one. Then, we perform V. Results and Discussion
the cone processing. Finally, we extract the middle portion to have the
correct cone map. We implemented the different algorithms discussed in
this paper in C++. For the rendering algorithms, we used
The algorithm is then as follows: first, we begin by OpenGL and its high level shading language GLSL. The
calculating the local maxima using an intermediate measurements and figures were made on a PENTIUM
binary image where local maxima have the value 1. The IV 3GHz with 512Mb of RAM and a GeForce 7600GS
second part is rather similar to the conservative cones AGP with 256Mb of memory.
algorithm. For each depth level of local maxima, a
binary image is built in which only local maxima less
than or equal to the current depth level will be set to 0. V.1. Pre-Processing
All other texels will receive the value 1. Then, we The execution times of the four algorithms described
compute the EDT of this binary image which will be in this article are presented in Table 1. Fig. 11 shows the
used to calculate the ratio or the radius of the cones. graph of a part of the table data. As expected, the results
These values will be modified only if they are smaller clearly reveal the quadratic or the linear trend of these
than the values already processed (see Algorithm 4).
It should be noted that when the depth map contains
areas with a uniform depth, the quadratic algorithm may
give wider cones. Because, as we can see in Fig. 9, the
linear algorithm tends to take the first maximum q, while
the quadratic algorithm detects the last one r. But this is
not always the case because, in most cases, the latter will

TABLE 1
CONE MAPS PRE-PROCESSING TIMES (IN SECONDS).

Timing results of the four algorithms described in this paper. The


pre-processor stores the cone ratio. We used two different depth Fig. 11. Running times graphic of the conservative cones algorithms.
maps a and b (see fig. 11) with different sizes. The values between We can clearly notice the linear (blue) or quadratic (red) trend of
brackets are the timings of shifted tilling versions. Asterisk means these algorithms. Note the difference between the processing of the
that the value is only estimated. two depth maps a and b in the quadratic case.

Copyright © 2008 Praise Worthy Prize S.r.l. - All rights reserved International Review on Computers and Software, Vol. 3, n. 5
A. Halli, A. Saaidi, K. Satori, H. Tairi

Fig. 12. Resulting cone maps using the different algorithms described in this paper. We notice that for the conservative cones algorithms, the linear
and quadratic algorithms produce the same cone map. For the relaxed cones, the quadratic algorithm produces wider cones (i.e. brighter areas), this is
due to the approximation of this algorithm which can results in some artefacts shown in Fig. 13.

algorithms. Indeed, we can verify that in the linear case, the same, except for the quadratic conservative
the ratio between the running time of a texture with a algorithm which is clearly slower because the apex angle
given dimension and the texture with the lower is no more limited to π/4.
dimension is equal to 4 (because the total number of The Fig. 12 shows cone maps storing ratios. We
pixels is each time multiplied by 4). notice that the linear and the quadratic conservative
With regard to the conservative algorithms, Table 1 algorithms produce exactly the same map. For the
shows that in the case of the texture a, the speed of the relaxed algorithms, both linear and quadratic generate
quadratic algorithm remains reasonable up to the maps with wider cones (brighter texels) but we can
dimension 1024x1024. It is even faster than the linear clearly notice that the quadratic algorithm produce
version with shifted tilling for dimensions less than larger cones. This is due to the approximation used by
512x512. But for the texture b that contains a spaced this algorithm which results in some artefacts shown in
relief, the quadratic algorithm is much slower from the Fig. 13, even if the binary search tends to rectify most of
256x256 size. these errors.
With regard to relaxed cones algorithms, the linear
one is as fast as its conservative version. On the other
V.2. Rendering
hand, the quadratic algorithm is extremely slow. So, we
only calculated the execution time of the 256x256 maps In order to compare the rendering performance of the
size. Even so, it took 8 hours! For this raison, Policarpo different techniques, we used 20 steps for cone tracing
and Oliveira [3] used a GPU-based pre-processing to and 10 steps for the binary search used by the relaxed
reduce the calculation time. cones algorithms. Fig. 14 shows screen shots of the four
It should also be noted that when we calculate and techniques. We can notice that the use of radii instead of
store radii instead of ratios, the timing results are almost ratios produces appreciably a better convergence
without slowing down the framerate (115 FPS). On the
other hand, using relaxed cones produces sharply better
results, but with the cost of the binary search (94 FPS).
So, running the conservative techniques with additional

Fig. 14. Comparison of the four cone tracing techniques. We can


clearly notice that the rendering quality increases from bottom to top.
Then we can conclude that using radii instead of ratios produces
Fig. 13. Comparison between the quadratic (top) and the linear better results as well as using relaxed cones instead of conservative
(bottom) algorithms for computing relaxed cones. Note the artefact cones. However, the relaxed algorithms run more slowly (94 FPS)
due to the approximation of the quadratic approach (see also Fig 6). than the conservatives (115 FPS) as a result of the binary search.

Copyright © 2008 Praise Worthy Prize S.r.l. - All rights reserved International Review on Computers and Software, Vol. 3, n. 5
A. Halli, A. Saaidi, K. Satori, H. Tairi

stage, but it may be very important for interactive


applications, or in the case where the depth map must be
updated regularly.

References
[1] L. Szirmay-Kalos and T. Umenhoffer, Displacement Mapping
on the GPU – State of the Art, Computer Graphics Forum,
preprint, 3 Jan. 2008
[2] J. Dummer, Cone Step Mapping: An Iterative Ray-Heightfield
Intersection Algorithm, Technical Report, Available online at
http://www.lonesock.net/files/ConeStepMapping.pdf, 2006.
[3] F. Policarpo and M.M. Oliveira, Relaxed Cone Stepping for
Relief Mapping, GPU Gems 3, pp. 409-428, 2007.
[4] D.W. Paglieroni and S. M. Petersen, Height Distributional
Distance Transform Methods for Height Field Ray Tracing,
ACM Transactions on Graphics (TOG), Vol. 13, no 4, pp. 376-
399, 1994.
[5] J. F. Blinn. Simulation of wrinkled surfaces, Proc. of Siggraph
1978, ACMPress, pp. 286–292, 1978.
Fig. 15. Comparison between the two approaches for processing
[6] N. Max, Horizon mapping: shadows for bump-mapped surfaces,
rectangular maps. (Left) the standard approach which normalizes the
The Visual Computer, Vol. 4, no. 2, pp. 109–117, 1988.
depth map before cone processing. (Right) our method skips the
[7] P. Sloan, M. F. Cohen, Interactive horizon mapping,
normalization and uses an elliptical rectification during rendering
Eurographics Workshop on Rendering, vol. 2, pp. 281-286,
stage. Note that for the viewing ray V’ which follows the largest
2000.
dimension, the standard approach produces better results but the
[8] W. Heidrich, K. Daubert, J. Kautz, and H. Seidel, Illuminating
difference is hardly visible. But for other directions and especially
micro geometry based on precomputed visibility, Proc. of
according to the direction of the smallest dimension V, the standard
Siggraph 2000, ACM Press, pp. 455–464, 2000.
method looks flat and our method produces sharply better results (see
[9] T. Kaneko, T. Takahei, M. Inami, N. Kawakami, Y. Yanagida,
also Fig. 5.).
T. Maeda, and S. Tachi, Detailed shape representation with
parallax mapping, Proc. of the ICAT 2001, pp. 205–208, 2001.
steps for cone tracing will produce approximately same [10] T. Welsh. Parallax mapping with offset limiting: A per-pixel
results as the relaxed approach, and with the same approximation of uneven surfaces, Infiscape Corp., 2004.
framerate. [11] M. Premecz, Iterative parallax mapping with slope
information, Central European Seminar on Computer Graphics
Fig. 15 highlights the use of non-square textures. As CESCG’06, Available online at http://www.cescg.org/CESCG-
we have described in Fig. 5, we can easily notice that the 2006/papers/ TUBudapest-Premecz-Matyas.pdf, 2006.
normalization of the depth map before the cones pre- [12] R. L. Cook. Shade trees, Proc. of Siggraph 1984, ACMPress,
processing gives slightly better results only when the pp. 23–231, 1984.
[13] J. W. Patterson, S. G. Hoggar, and J. R. Logie, Inverse
viewing ray is almost parallel to the direction of the
displacement mapping, Computer Graphics Forum, Vol. 10, no
biggest dimension. On the other hand, in all other 2, pp. 129–139. 1991.
directions, the elliptical rectification method is sharply [14] F. Policarpo, M.M. Oliveira, and J. L. D. Comba, Real-time
better. relief mapping on arbitrary polygonal surfaces, Proc. of
I3D’05, ACMPress, pp. 155–162, 2005.
[15] M.M. Oliveira, G. Bishop, and D. McAllister, Relief texture
mapping, Proc. of Siggraph 2000, ACM Press, pp. 359–368,
VI. Conclusion 2000.
[16] M. McGuire, Steep parallax mapping, I3D’05 Poster, 2005.
In this paper, we have introduced an novel O(n)
[17] Z. Brawley, N. Tatarchuk, Parallax Occlusion Mapping: Self-
algorithm for generating relaxed cone maps, the proposed Shadowing, Perspective-Correct Bump Mapping Using Reverse
algorithm is obviously faster than the quadratic one, but it Height Map Tracing, ShaderX3, 2004.
can result in smaller cones when the depth map contains [18] N. Tatarchuk, Dynamic parallax occlusion mapping with
uniform areas. We also suggested using the linear algorithm approximate soft shadows, SI3D’06, pp. 63-69, 2006.
[19] F. Policarpo, and M.M. Oliveira, Relief Mapping of Non-
HDDT to create the conservative cone maps. Cone maps Height-Field Surface Details, Proc. of the 2006 Symposium on
are used in the cone tracing techniques at the pre-process Interactive 3D Graphics and Games, pp. 55–62. 2006.
stage. We also proposed a new method for extending these [20] W. Donnelly, Per-pixel displacement mapping with distance
techniques to rectangular textures. Furthermore, we have functions; GPUGems2, Addison-Wesley, 2004.
[21] K. Oh, H. Ki, and C.H. Lee, Pyramidal displacement mapping:
used cone radius instead of ratio, which allows storing A GPU-based artifacts-free ray tracing through an image
cones with an apex angle up to π/2 improving in this way pyramid, ACM Symposium on Virtual Reality Software and
the convergence of the cone tracing. Technology (VRST’06), pp..75–82, 2006.
We are convinced that the passage to a linear [22] A. Tevs, I. Ihrke, and H.-P. Seidel, Maximum Mipmaps for Fast,
Accurate, and Scalable Dynamic Height Field Rendering, Proc.
complexity pre-processing will favor the cone tracing Symp. Interactive 3D Graphics and Games, pp. 183-190, 2008.
technique, which remains one of the best ways to [23] L. Baboud, and X. Décoret, Rendering Geometry with Relief
simulate mesostructure surfaces for real-time rendering. Textures, Proc. of Graphics Interface 2006, vol 137, pp. 195-
Even if the pre-processing does not affect the 201, 2006.
performance of this technique during the rendering

Copyright © 2008 Praise Worthy Prize S.r.l. - All rights reserved International Review on Computers and Software, Vol. 3, n. 5
A. Halli, A. Saaidi, K. Satori, H. Tairi

[24] M. M. Oliveira, F. Policarpo, An Efficient Representation for Akram Halli received the bachelor’s and master’s
Surface Details, UFRGS technical report RP-351, 2005 degrees from USMBA-Fez University in 2002 and
[25] J. Hirche, A. Ehlert, S. Guthe, and M. Doggett, Hardware 2004 respectively. He is currently working toward
accelerated per-pixel displacement mapping, Proc. of Graphics the PhD degree in the LIIAN Laboratory
Interface 2004, vol. 62, pp. 153–158, 2004. (Laboratoire d’Informatique, Imagerie et Analyse
[26] S.D. Porumbescu, B. Budge, L. Feng, and K.I. Joy, Shell maps, Numérique) at USMBA-Fez University. His
Proc. of ACM SIGGRAPH 2005, ACM Trans. Graphics , vol. current research interests include real-time
24, pp. 626–633. 2005 rendering, Image-based rendering and virtual
[27] J.-F. Dufort, L. Leblanc, and P. Poulin, Interactive rendering of reality.
meso-structure surface details using semi-transparent 3d
textures, Proc. of Vision, Modeling and Visualization 2005, pp.
399-406. 2005
Abderrahim Saaidi received the bachelor’s and
[28] S. Jeschke, S. Mantler, and M. Wimmer, Interactive smooth and
master’s degrees from USMBA-Fez University in
curved shell Mapping, Rendering Techniques 2007, Proc. of the
1997 and 2004 respectively. He is currently
Eurographics Symposium on Rendering, pp. 351-360, 2007.
working toward the PhD degree in the LIIAN
[29] L. Wang, X. Wang, X. Tong, S. Lin, S. Hu, B. Guo, and H. Y.
Laboratory at USMBA-Fez University. His current
Shum, View-dependent displacement mapping, ACM Trans.
research interests include camera self calibration,
Graphics, vol. 22, no. 3, pp. 334–339, 2003.
3D reconstruction and real-time rendering.
[30] X. Wang, X. Tong, S. Lin, S. Hu, B. Guo, and H. Y. Shum.
Generalized displacement maps, Proc. of the Eurographics
Symposium on Rendering, pp. 227-234, 2004.
[31] E.A. Risser, M.A. Shah, and S. Pattanaik, Interval mapping, Khalid Satori received the PhD degree from the
Symposium on Interactive 3D Graphics and Games (I3D'06 National Institute for the Applied Sciences INSA at
Poster), 2006. Lyon in 1993. He is currently a professor of
[32] P.E. Danielsson, Euclidean Distance Mapping, Computer computer science at USMBA-Fez University. His is
Graphics and Image Processing, Vol. 14, pp. 227–248, 1980. the director of the LIIAN Laboratory. His research
interests include real-time rendering, Image-based
rendering, virtual reality, biomedical signal, camera
Authors’ information self calibration and 3D reconstruction.
1
LIIAN laboratory, Faculty of Science Dhar El Mahraz, P.O. Box
1796, Fez, MOROCCO. Hamid Tairi received the PhD degree from
Akram_halli@yahoo.fr USMBA-Fez University in 2001. He is currently a
professor of computer science at USMBA-Fez
2 University. His is also a member of the LIIAN
LIIAN laboratory, Faculty of Science Dhar El Mahraz, P.O. Box
1796, Fez, MOROCCO. Laboratory. His research interests include image
saaidi.abde@caramail.com processing, biomedical signal, Image-based
rendering, visual tracking for robotic control and
3
LIIAN laboratory, Faculty of Science Dhar El Mahraz, P.O. Box 3D reconstruction.
1796, Fez, MOROCCO.
khalidsatori@caramail.com
4
LIIAN laboratory, Faculty of Science Dhar El Mahraz, P.O. Box
1796, Fez, MOROCCO.
htairi@yahoo.fr

Copyright © 2008 Praise Worthy Prize S.r.l. - All rights reserved International Review on Computers and Software, Vol. 3, n. 5

You might also like