Top Banner
International Review on Computers and Software (I.RE.CO.S.), Vol. 3, n. 5 ISSN: 1828-6003 Manuscript received 5 Aug. 2008, revised 16 Oct. 2008 Copyright © 2008 Praise Worthy Prize S.r.l. - All rights reserved Per-Pixel Displacement Mapping Using Cone Tracing Akram Halli 1 , Abderrahim Saaidi 2 , Khalid Satori 3 , Hamid Tairi 4 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 xy V V r r , vector, sub-vector z y x V V V , , vector components V r the Euclidean norm of V r ( ) q p dist e , the Euclidean distance between p and q I. Introduction Per-pixel displacement mapping is an approach stemmed from the texture mapping. It is used to add very fine scale to polygonal meshes without increasing 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 caused by the huge number of data to be submitted to the graphics card. The displacement mapping technique is based on three main principles: the displacement map, tangent space and inverse ray tracing. I.1. The Displacement Map The displacement map, also known as height map or depth map, is a two-dimensional image whose pixels are not used to store colors but several data, to be specific, depths and normals. The depths of the relief to be mapped onto the 3D surface are often placed in the alpha channel. The other three channels: red, green and blue are used to store the three coordinates x, y, and z of the normals calculated from depths. But as the z coordinate can be found from the two others, its channel can be used to store other data used in some techniques like cone tracing. In that case the displacement map may be named according to its technique as, for example, the cone map. I.2. Tangent Space The tangent or TBN space (Tangent, Binormal, and Normal) is a local modeling space attached to each vertex of the mesh. This particular space is built according to the normal of vertices and their texture 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 map are naturally expressed in this space and it may be very costly to transform each normal to another coordinate system. However, the lights and view vectors must be expressed in this space too. I.3. Inverse Ray Tracing The main problem of the displacement mapping technique is illustrated in Fig. 2. It lies in finding the first intersection point of the viewing ray with the Fig. 1. Image (a) represents a plan with texture mapping. Image (b) 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.
11

Per-Pixel Displacement Mapping Using Cone Tracing

Apr 10, 2015

Download

Documents

akram_halli

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
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Per-Pixel Displacement Mapping Using Cone Tracing

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

ISSN: 1828-6003

Manuscript received 5 Aug. 2008, revised 16 Oct. 2008 Copyright © 2008 Praise Worthy Prize S.r.l. - All rights reserved

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

xyVVrr

, vector, sub-vector

zyx VVV ,, vector components

Vr

the Euclidean norm of Vr

( )qpdiste , the Euclidean distance between p and q

I. Introduction

Per-pixel displacement mapping is an approach stemmed from the texture mapping. It is used to add very fine scale to polygonal meshes without increasing 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 caused by the huge number of data to be submitted to the graphics card.

The displacement mapping technique is based on three main principles: the displacement map, tangent space and inverse ray tracing.

I.1. The Displacement Map

The displacement map, also known as height map or depth map, is a two-dimensional image whose pixels are not used to store colors but several data, to be specific, depths and normals. The depths of the relief to be mapped onto the 3D surface are often placed in the alpha channel. The other three channels: red, green and blue are used to store the three coordinates x, y, and z of the normals calculated from depths. But as the z coordinate can be found from the two others, its channel

can be used to store other data used in some techniques like cone tracing. In that case the displacement map may be named according to its technique as, for example, the cone map.

I.2. Tangent Space

The tangent or TBN space (Tangent, Binormal, and Normal) is a local modeling space attached to each vertex of the mesh. This particular space is built according to the normal of vertices and their texture 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 map are naturally expressed in this space and it may be very costly to transform each normal to another coordinate system. However, the lights and view vectors must be expressed in this space too.

I.3. Inverse Ray Tracing

The main problem of the displacement mapping technique is illustrated in Fig. 2. It lies in finding the first intersection point of the viewing ray with the

Fig. 1. Image (a) represents a plan with texture mapping. Image (b) 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.

Page 2: Per-Pixel Displacement Mapping Using Cone Tracing

A. Halli, A. Saaidi, K. Satori, H. Tairi

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

imaginary relief stored in the depth map. This intersection must be found for every rendered fragment using an inverse ray tracing algorithm.

The speed constraint does not allow an exact search, which inevitably means finding the nearest possible point to the intersection using a limited number of steps. Various solutions exist for solving this problem. Szirmay-Kalos and Umenhoffer [1] in their state of the art in real-time displacement mapping have classified these techniques into three categories: unsafe, safe (i.e. conservative) and combined techniques. They also provided a comparison between the different approaches.

I.4. Contributions

Our contributions concern the cone tracing, which is one of the best techniques for rendering 3D surface details in real-time. In order to find the intersection point between the viewing ray and the relief, this technique uses a cone map to converge quickly to the

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 improves visibly the results at rendering.

II. Related Work

The idea of using textures to simulate mesostructures was first introduced by Blinn [5]. Bump mapping simulates the surface details using a normal perturbation. The texture coordinates and the geometry remain unchanged. This technique is very fast but can't produce self-occlusions, shadows and silhouettes. Horizon maps [6] provide a shadow bump mapping implemented by [7] and [8] using graphics hardware.

Parallax mapping [9] optionally with offset limiting [10] or with slope information [11] uses textures augmented with per-texel depth. In this approach the texture coordinates along the view ray direction are shifted according to the depth values. This technique produces nice results at a very low cost but it is only appropriate for noisy irregular bumps (it also does not produce shadows and silhouette)

Displacement mapping [12] subdivides original geometry into a large number of micro-polygons which are displaced perpendicularly according to a 2D height map. This technique produces correct self-occlusions, shadows and silhouettes. Unfortunately, displacement mapping is unsuitable for real time rendering due to the huge number of micro polygons to be rendered. To overcome this problem, Patterson et Al [13] introduced

Fig. 2. Ray tracing of the depth field. (u,v) is the fragment currently 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 intersection search is performed in 2D between texels (u,v) and (u’,v’). (d) The corresponding color map, the fragment (u,v) will be textured using the texel (s,t) instead of (u,v).

Page 3: Per-Pixel Displacement Mapping Using Cone Tracing

A. Halli, A. Saaidi, K. Satori, H. Tairi

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

the idea of using per-Pixel (i.e. inverse) displacement mapping.

Relief mapping [14], an extended technique of relief texture mapping [15], performs an image space search to find the intersection point between the viewing ray and a 2D depth map. It begins with a linear search using regular intervals followed by a binary search to refine the intersection point. This technique correctly handles self-occlusions, shadows and inter-penetrations. However some artefacts become visible at grazing angles, especially with thin structures. Similar approaches to relief mapping were presented in [16], [17], [18] and [19].

Instead of using unsafe approach, Donnelly [20] uses sphere tracing. He creates a 3D distance map that gives a measure of the distance between points in space and the displaced surface. In the same way, Dummer [2] uses top-opened cones as empty space bounding volumes stored in a 2D cone step map. This idea was first introduced by Paglieroni and Petersen [4] for height field ray tracing. Other conservative approaches were proposed like the use of pyramidal structure [21], [22].

Baboud et Al [23] introduced the use of relaxed pre-computed volumes allowing safe binary search. They used a safety radius allowing cylinder tracing. In the same way, Policarpo and Oliveira [3] relaxed the rule of the conservative cones.

To resolve the problem of the flat silhouettes, Oliveira and Policarpo use a quadratic function to approximate curved surfaces [24]. Hirche et al [25] extrude the triangles of the base mesh along their respective normal directions, and then the resulting prisms are rendered by casting rays inside and 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 coordinates of points inside tetrahedra to define a mapping between points in the shell volume and corresponding points in a 3D texture. Dufort et al. [27] use the same technique with semi-transparent 3D textures in order to support more advanced features. Instead of using tetrahedral, Jeschke et al. [28] use a smooth mapping function and Coons patch to render

correct, smooth and optionally curved shell mapping. View-Dependent Displacement Mapping [29] and

Generalized Displacement Mapping [30] do a pre-process shell space ray tracing and store the result as a five-dimensional function that can be queried during rendering time. These methods produce very nice results but require significant pre-processing and storage to operate.

III. Cone Tracing

To find the first intersection between the viewing ray and the depth field surface, some techniques use unsafe approaches (i.e. linear, binary or secant search). Unfortunately, while these methods do not require preprocessing and thus no additional data than the depth map and its derivatives, they may skip the first intersection point at grazing views or for fine scales, which results in important artifacts. To overcome this problem, some conservative methods were introduced (sphere tracing, cylinder tracing, cone tracing or pyramidal tracing). These techniques compute and store additional data in a pre-processing stage. At the rendering step, this data is used for space leaping to avoid missing the first intersection with the relief. But with no guarantee of success especially if the number of steps is limited.

In this section we first discuss two of these conservative techniques, the conservative cone tracing and the recent relaxed cone tracing which combine space leaping with an unsafe method. We, then, propose to use cone radius instead of ratio and, finally, we present an extension to non-square displacement maps.

III.1. Conservative cone tracing

In cone step mapping, Dummer [2] assigns to each texel of the depth map a top opened cone that represents the empty space above it. The cone ratio is computed during a pre-processing stage and stored in a free channel of the displacement map called then the cone map.

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

the depth of the view ray (i.e. zVVv /rr

= where Vr

is the

normalized view ray). So according to Fig. 3, one can write:

xyz

xyv

v

v

ac r

r==

xyvacr

×= (1)

Likewise:

ratiocone

bc

_=

Fig. 3. Ray tracing of the depth field using conservative cones. At each step, the next ray position Pi+1 is calculated in term of the current position Pi, the viewing ray v and the value of a. v is expressed in the TBN space of the current fragment P0

Page 4: Per-Pixel Displacement Mapping Using Cone Tracing

A. Halli, A. Saaidi, K. Satori, H. Tairi

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

ratioconePaPD

c

izi

_][

=--

(2)

Solving (1) and (2) for a gives:

( )

ratioconev

PPDratioconea

xy

izi

_

][_

+

-×= r (3)

Finally, we compute the next ray position using the equation (3), thus:

vaPP iir×+=+1 (4)

III.2. Relaxed Cone Tracing

The conservative cones are defined in such a way that the ray position never pierces the relief. This constraint causes in some cases (like few steps, grazing views, or a depth map with very fine details) visible distortions due to the early ray tracing stops. Relaxed cone stepping [3] eases the conservative rule and forces the cones to intersect the surface whenever possible. This approach was first used in [23] with cylinders.

In relaxed cone stepping, the ray tracing will be the same as in the case of conservative cones using equation (4). At the end of this stage, we assume that the ray position Pn is under the relief surface. Then we start a binary search for refining the intersection point. As schematized in Fig. 4, the binary search is performed between the ray starting position P0 and its actual position Pn. Note that we can also use the last point over the surface Pn-1 instead of P0. Unfortunately, saving Pn-1 requires conditional statement in the code which will cause a performance drop. We can also use the secant method described in [17] and [31] instead of the binary search.

It should be noted that the use of relaxed cones does not overcome all of the distortions due to the conservative approach, because in several cases the ray will never pierce the relief.

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.

According to these observations, we propose to calculate and store the surface radius of the cones 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, we no longer need to limit the ratio to 1 when integer textures are used, which can then be theoretically infinite. Thus the apex angle can go up to π/2. The use of cones radius will modify the equation (3). So, as we have:

][

__

iPDradiuscone

ratiocone = (5)

Equation (3) becomes:

( )

radiusconevPD

PPDradiusconea

xyi

izi

_][

][_

-×= r

III.4. Extension to Non-Square Depth Maps

Techniques using the distance (as the sphere tracing, cylinder tracing or cone tracing) are confronted to the problem of the non-orthonormal space of non-square textures. Because the texture coordinates are afterward automatically normalized by the graphic pipeline.

Authors of the previous techniques did not mention this issue in their articles, but they have nevertheless taken it into account in their code. They chose to treat it in the pre-processing stage by making the calculations with normalized texel coordinates. This avoids the distortion problem due to the automatic normalization during the ray tracing. However this choice reduces considerably the cones’ radius and thus slows down the convergence of the cone tracing as schematized in Fig._5.

To avoid this loss in the space leaping, we suggest skipping the normalization during the pre-processing. Therefore, we report the distances only to one of the two dimensions, the width for example (i.e. width→1). Obviously this will induce errors during the cone tracing as defined previously because, being in an orthonormal space, the cones are supposedly rounded, which is no longer the case after the auto-normalization of non-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

Fig. 4. The binary search stage of relaxed cone tracing. The binary search is performed between the last ray position after cone tracing Pn (assumed under the surface) and the starting position P0

Page 5: Per-Pixel Displacement Mapping Using Cone Tracing

A. Halli, A. Saaidi, K. Satori, H. Tairi

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

on the viewing ray and the ratio of the map dimensions. This ratio can be easily calculated from the equation of the ellipse. It can be formulated as:

222yx

xy

VRV

V

+=

r

a withwidthheight

R =

where we can verify that: if width=height then =1 (square texture), and when Vy=0 then =1 because we chose to modulate the distances according to the width. is calculated only once for a given viewing ray,

equation (4) becomes:

avaPP iir×+=+1 with vv

rr×= aa

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:

)1,,(

)1,,(

yx

yxscale

dscaledscale

dscaledscaleN

×-×-

×-×-=

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 algorithms and, then we present the linear algorithms. Finally, we discuss the tilling options.

IV.1. Quadratic Algorithms

Conservative cone Maps

The pre-processor assigns a cone ratio to each texel of the depth map. This cone represents the largest one that does not pierce the relief. Dummer [2] instead of using the HDDT [4] proposed an optimized O(n2) algorithm described as follows: for each texel, look outwardly (in expanding squares) for the minimal cone ratio. This search is stopped when the current cone ratio

Algorithm 2: Relaxed Cones (Quadratic)

Input : Depth Map D

Output : Cone Map C

for each texel t do

C[t] = MAX_VALUE

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 */

step = ray/SEARCH_STEPS /* step length */

pos = (p.x, p.y, D[p]) + step

for i=0 to SEARCH_STEPS do

if pos.z ≤ D(pos.xy) then

pos = pos + step

else

break

end if

end for i

if D[t] > pos.z then

C[t]=min(dist(t,pos.xy)/(D[t]-pos.z), C(t))

end if

end for p

end for t

Algorithm 1: Conservative Cones (Quadratic)

Input : Depth Map D

Output : Cone Map C

for each texel t do

C[t] = MAX_VALUE

for each texel p in each outward square S do

if C[t] > S_Radius/(D[t]-D[p]) then

break /* process next texel t */

else if D[t] > D[p] then

C[t] = min( dist(t,p)/(D[t]-D[p]), C[t] )

end if

end for p

end for t

Fig. 5. Comparison between the two approaches for processing non-square maps. (a) A rectangular depth map where the texels r and q are 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 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 difference is less important.

Page 6: Per-Pixel Displacement Mapping Using Cone Tracing

A. Halli, A. Saaidi, K. Satori, H. Tairi

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

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 Oliveira [3] used an O(n2) algorithm described by the pseudocode shown in Algorithm 2. The idea is: for each 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 each such ray, compute its next (second) intersection with the depth field using an accurate linear search and, then, use the intersection point to compute the cone ratio Cp[t], the final ratio C[t] is given by the smallest of all cone ratios computed for t.

The relaxed cones algorithm does not use an optimisation as in the conservative algorithm, so it is considerably slower. In addition, the algorithm as described in [3] gives just an approximate solution, since it may result on some errors as illustrated in Fig. 6. To avoid such errors the ray used to find the second intersection must start at point (tx, ty, D[p]). This ray is horizontal, so it is not adapted for the standard linear search since it needs the intersection with the bottom of the relief. Then a Bresenham-like algorithm should be used to find the second intersection between this ray and 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.

{ }OqqpdistpT e Î= ),,(min)(

For the EDT computation, we opted for the 4SED EDT algorithm of Danielsson presented in [32], which has the advantage of being very fast while giving a very good approximation of the distance transform. The

difference with an exact EDT lies only in some texels. Nevertheless, we can use linear algorithms that give an exact EDT.

Conservative Cone Maps

In order to present the main idea of this algorithm, called Height Distributional Distance Transform (HDDT) in [4], let us suppose that the depth map contains only two depth levels a and b. According to Fig. 7 (top) we can easily notice that the widest cone based on the texel t that does not pierce the relief is the one whose ratio is:

ab

ptdisttC e

-=

),(][ (6)

where t is a texel with the depth b and p is the closest texel to t having the depth a (with b>a). Therefore the

Fig. 6. The quadratic algorithm may skip a bump and thus, some grazing rays can pierce and leave the relief inside the relaxed cone area.

Fig. 7. Computing conservative cones using the linear algorithm. (Top) we suppose that the depth has only two values: a and b. Then we can easily notice that we can calculate the conservative cone based 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 gives a cone. The conservative cone based on t is the smallest of these cones (the blue one).

Page 7: Per-Pixel Displacement Mapping Using Cone Tracing

A. Halli, A. Saaidi, K. Satori, H. Tairi

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

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 based on texels with depth b will be calculated using this EDT according to (6). For texels with depth a, their ratio will not be calculated from the EDT, because their value is equal to 0 and, thus, will keep their initial ratio which is the maximal value in this case.

In view of the fact that the depth map is a greyscale image (usually 256 levels), thus, the relief is constituted by several depth levels (see Fig. 7). Then we just have to calculate the cone ratio of each level using the EDT of the binary image constituted by 1 for texels with depth above l and 0 for the other texels. The cone ratio will be changed if its value is less than that previously calculated. The pseudocode of this algorithm is shown in Algorithm 3. Note that we use the same algorithm to calculate the cone map both for storing ratios or radii using (5).

The calculation of the EDT of a binary image is an algorithm with a linear complexity O(n) (where n=width x height). In our case, the calculation of the EDT is repeated a constant number of times which is the

number of the depth map levels. Therefore, the algorithm for the calculation of conservative cone maps is also a linear algorithm.

Of course, the complexity depends on the number of depth levels, but 256 levels (i.e 8 bits both for integer or real format) are largely sufficient for rendering surface details. Note that this algorithm is not limited to integer depths.

Relaxed Cone Maps

Although, in the quadratic case, the conservative cone algorithm and the relaxed cone algorithm are rather different, let us try to use the same approach in their linear version (i.e. using the EDT). We can notice that the relaxed cones such as they were defined in [3] are the cones that pass by the local maxima of the depth map. Thus, the relaxed cone based on a given texel t is the smallest of cones based on t and go through a local maximum of the relief (see Fig. 8).

Algorithm 3 : Conservative Cones (Linear)

Input : Depth Map D

Output : Cone Map C

Intermediate: Binary Map B, Distance Map T

for each level l of D do

for each texel t do

B[t] = {0 if D[t] ≤ l, 1 otherwise}

end for t

T = EDT( B ) /* distance of ones to zeros */

for each texel t do

if D[t] > l then

C[t] = min( T[t]/(D[t]-l), C[t] )

else

C[t] = MAX_VALUE

end if

end for t

end for l

Fig. 8. The relaxed cone based on the texel t is the most narrow cone (the blue one) going by a local maximum of the relief (here the maximum a)

Algorithm 4 : Relaxed Cones (Linear)

Input : Depth Map D

Output : Cone Map C

Intermediate: Binary Map M /* local maxima */

Binary Map B, Distance Map T

M = LOCAL_MAXIMA( D ) /* if maximum 1 else 0 */

for each level l of D ∩ M do /* level of maxima */

for each texel t do

B[t] = {0 if D[t] ≤ l and M[t]==1, 1 otherwise}

end for t

T = EDT( B ) /* distance of ones to zeros */

for each texel t do

if D[t] > l then

C[t] = min( T[t]/(D[t]-l), C[t] )

else

C[t] = MAX_VALUE

end if

end for t

end for l

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 linear algorithm take the nearest point q. note that this schema is just a 2D slice, thus for other slices the distance between r and q can be zero.

Page 8: Per-Pixel Displacement Mapping Using Cone Tracing

A. Halli, A. Saaidi, K. Satori, H. Tairi

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

The algorithm is then as follows: first, we begin by calculating the local maxima using an intermediate binary image where local maxima have the value 1. The second part is rather similar to the conservative cones 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. All other texels will receive the value 1. Then, we compute the EDT of this binary image which will be used to calculate the ratio or the radius of the cones. These values will be modified only if they are smaller 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

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.

V. Results and Discussion

We implemented the different algorithms discussed in this paper in C++. For the rendering algorithms, we used OpenGL and its high level shading language GLSL. The measurements and figures were made on a PENTIUM IV 3GHz with 512Mb of RAM and a GeForce 7600GS AGP with 256Mb of memory.

V.1. Pre-Processing

The execution times of the four algorithms described in this article are presented in Table 1. Fig. 11 shows the graph of a part of the table data. As expected, the results clearly reveal the quadratic or the linear trend of these

Fig. 11. Running times graphic of the conservative cones algorithms. We can clearly notice the linear (blue) or quadratic (red) trend of these algorithms. Note the difference between the processing of the two depth maps a and b in the quadratic case.

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 maps a and b (see fig. 11) with different sizes. The values between brackets are the timings of shifted tilling versions. Asterisk means that the value is only estimated.

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 the cone processing. Finally, we extract the middle portion to have the correct cone map.

Page 9: Per-Pixel Displacement Mapping Using Cone Tracing

A. Halli, A. Saaidi, K. Satori, H. Tairi

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

algorithms. Indeed, we can verify that in the linear case, the ratio between the running time of a texture with a given dimension and the texture with the lower dimension is equal to 4 (because the total number of pixels is each time multiplied by 4).

With regard to the conservative algorithms, Table 1 shows that in the case of the texture a, the speed of the quadratic algorithm remains reasonable up to the dimension 1024x1024. It is even faster than the linear version with shifted tilling for dimensions less than 512x512. But for the texture b that contains a spaced relief, the quadratic algorithm is much slower from the 256x256 size.

With regard to relaxed cones algorithms, the linear one is as fast as its conservative version. On the other hand, the quadratic algorithm is extremely slow. So, we only calculated the execution time of the 256x256 maps size. Even so, it took 8 hours! For this raison, Policarpo and Oliveira [3] used a GPU-based pre-processing to reduce the calculation time.

It should also be noted that when we calculate and store radii instead of ratios, the timing results are almost

the same, except for the quadratic conservative algorithm which is clearly slower because the apex angle is no more limited to π/4.

The Fig. 12 shows cone maps storing ratios. We notice that the linear and the quadratic conservative algorithms produce exactly the same map. For the relaxed algorithms, both linear and quadratic generate maps with wider cones (brighter texels) but we can clearly notice that the quadratic algorithm produce larger cones. This is due to the approximation used by this algorithm which results in some artefacts shown in Fig. 13, even if the binary search tends to rectify most of these errors.

V.2. Rendering

In order to compare the rendering performance of the different techniques, we used 20 steps for cone tracing and 10 steps for the binary search used by the relaxed cones algorithms. Fig. 14 shows screen shots of the four techniques. We can notice that the use of radii instead of 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. 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.

Fig. 13. Comparison between the quadratic (top) and the linear (bottom) algorithms for computing relaxed cones. Note the artefact due to the approximation of the quadratic approach (see also Fig 6).

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 better results as well as using relaxed cones instead of conservative cones. However, the relaxed algorithms run more slowly (94 FPS) than the conservatives (115 FPS) as a result of the binary search.

Page 10: Per-Pixel Displacement Mapping Using Cone Tracing

A. Halli, A. Saaidi, K. Satori, H. Tairi

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

steps for cone tracing will produce approximately same results as the relaxed approach, and with the same framerate.

Fig. 15 highlights the use of non-square textures. As we have described in Fig. 5, we can easily notice that the normalization of the depth map before the cones pre-processing gives slightly better results only when the viewing ray is almost parallel to the direction of the biggest dimension. On the other hand, in all other directions, the elliptical rectification method is sharply better.

VI. Conclusion

In this paper, we have introduced an novel O(n) algorithm for generating relaxed cone maps, the proposed algorithm is obviously faster than the quadratic one, but it can result in smaller cones when the depth map contains uniform areas. We also suggested using the linear algorithm HDDT to create the conservative cone maps. Cone maps are used in the cone tracing techniques at the pre-process stage. We also proposed a new method for extending these techniques to rectangular textures. Furthermore, we have used cone radius instead of ratio, which allows storing cones with an apex angle up to π/2 improving in this way the convergence of the cone tracing.

We are convinced that the passage to a linear complexity pre-processing will favor the cone tracing technique, which remains one of the best ways to simulate mesostructure surfaces for real-time rendering. Even if the pre-processing does not affect the performance of this technique during the rendering

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.

[6] N. Max, Horizon mapping: shadows for bump-mapped surfaces, The Visual Computer, Vol. 4, no. 2, pp. 109–117, 1988.

[7] P. Sloan, M. F. Cohen, Interactive horizon mapping, Eurographics Workshop on Rendering, vol. 2, pp. 281-286, 2000.

[8] W. Heidrich, K. Daubert, J. Kautz, and H. Seidel, Illuminating micro geometry based on precomputed visibility, Proc. of Siggraph 2000, ACM Press, pp. 455–464, 2000.

[9] T. Kaneko, T. Takahei, M. Inami, N. Kawakami, Y. Yanagida, T. Maeda, and S. Tachi, Detailed shape representation with parallax mapping, Proc. of the ICAT 2001, pp. 205–208, 2001.

[10] T. Welsh. Parallax mapping with offset limiting: A per-pixel approximation of uneven surfaces, Infiscape Corp., 2004.

[11] M. Premecz, Iterative parallax mapping with slope information, Central European Seminar on Computer Graphics CESCG’06, Available online at http://www.cescg.org/CESCG-2006/papers/ TUBudapest-Premecz-Matyas.pdf, 2006.

[12] R. L. Cook. Shade trees, Proc. of Siggraph 1984, ACMPress, pp. 23–231, 1984.

[13] J. W. Patterson, S. G. Hoggar, and J. R. Logie, Inverse displacement mapping, Computer Graphics Forum, Vol. 10, no 2, pp. 129–139. 1991.

[14] F. Policarpo, M.M. Oliveira, and J. L. D. Comba, Real-time 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, 2000.

[16] M. McGuire, Steep parallax mapping, I3D’05 Poster, 2005. [17] Z. Brawley, N. Tatarchuk, Parallax Occlusion Mapping: Self-

Shadowing, Perspective-Correct Bump Mapping Using Reverse Height Map Tracing, ShaderX3, 2004.

[18] N. Tatarchuk, Dynamic parallax occlusion mapping with approximate soft shadows, SI3D’06, pp. 63-69, 2006.

[19] F. Policarpo, and M.M. Oliveira, Relief Mapping of Non-Height-Field Surface Details, Proc. of the 2006 Symposium on Interactive 3D Graphics and Games, pp. 55–62. 2006.

[20] W. Donnelly, Per-pixel displacement mapping with distance functions; GPUGems2, Addison-Wesley, 2004.

[21] K. Oh, H. Ki, and C.H. Lee, Pyramidal displacement mapping: A GPU-based artifacts-free ray tracing through an image pyramid, ACM Symposium on Virtual Reality Software and Technology (VRST’06), pp..75–82, 2006.

[22] A. Tevs, I. Ihrke, and H.-P. Seidel, Maximum Mipmaps for Fast, Accurate, and Scalable Dynamic Height Field Rendering, Proc. Symp. Interactive 3D Graphics and Games, pp. 183-190, 2008.

[23] L. Baboud, and X. Décoret, Rendering Geometry with Relief Textures, Proc. of Graphics Interface 2006, vol 137, pp. 195-201, 2006.

Fig. 15. Comparison between the two approaches for processing rectangular maps. (Left) the standard approach which normalizes the depth map before cone processing. (Right) our method skips the normalization and uses an elliptical rectification during rendering stage. Note that for the viewing ray V’ which follows the largest dimension, the standard approach produces better results but the difference is hardly visible. But for other directions and especially according to the direction of the smallest dimension V, the standard method looks flat and our method produces sharply better results (see also Fig. 5.).

Page 11: Per-Pixel Displacement Mapping Using Cone Tracing

A. Halli, A. Saaidi, K. Satori, H. Tairi

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

[24] M. M. Oliveira, F. Policarpo, An Efficient Representation for Surface Details, UFRGS technical report RP-351, 2005

[25] J. Hirche, A. Ehlert, S. Guthe, and M. Doggett, Hardware accelerated per-pixel displacement mapping, Proc. of Graphics Interface 2004, vol. 62, pp. 153–158, 2004.

[26] S.D. Porumbescu, B. Budge, L. Feng, and K.I. Joy, Shell maps, Proc. of ACM SIGGRAPH 2005, ACM Trans. Graphics , vol. 24, pp. 626–633. 2005

[27] J.-F. Dufort, L. Leblanc, and P. Poulin, Interactive rendering of meso-structure surface details using semi-transparent 3d textures, Proc. of Vision, Modeling and Visualization 2005, pp. 399-406. 2005

[28] S. Jeschke, S. Mantler, and M. Wimmer, Interactive smooth and curved shell Mapping, Rendering Techniques 2007, Proc. of the Eurographics Symposium on Rendering, pp. 351-360, 2007.

[29] L. Wang, X. Wang, X. Tong, S. Lin, S. Hu, B. Guo, and H. Y. Shum, View-dependent displacement mapping, ACM Trans. Graphics, vol. 22, no. 3, pp. 334–339, 2003.

[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, Symposium on Interactive 3D Graphics and Games (I3D'06 Poster), 2006.

[32] P.E. Danielsson, Euclidean Distance Mapping, Computer Graphics and Image Processing, Vol. 14, pp. 227–248, 1980.

Authors’ information 1 LIIAN laboratory, Faculty of Science Dhar El Mahraz, P.O. Box 1796, Fez, MOROCCO. [email protected] 2 LIIAN laboratory, Faculty of Science Dhar El Mahraz, P.O. Box 1796, Fez, MOROCCO. [email protected] 3 LIIAN laboratory, Faculty of Science Dhar El Mahraz, P.O. Box 1796, Fez, MOROCCO. [email protected] 4 LIIAN laboratory, Faculty of Science Dhar El Mahraz, P.O. Box 1796, Fez, MOROCCO. [email protected]

Akram Halli received the bachelor’s and master’s degrees from USMBA-Fez University in 2002 and 2004 respectively. He is currently working toward the PhD degree in the LIIAN Laboratory (Laboratoire d’Informatique, Imagerie et Analyse Numérique) at USMBA-Fez University. His current research interests include real-time rendering, Image-based rendering and virtual reality.

Abderrahim Saaidi received the bachelor’s and master’s degrees from USMBA-Fez University in 1997 and 2004 respectively. He is currently working toward the PhD degree in the LIIAN Laboratory at USMBA-Fez University. His current research interests include camera self calibration, 3D reconstruction and real-time rendering.

Khalid Satori received the PhD degree from the National Institute for the Applied Sciences INSA at Lyon in 1993. He is currently a professor of computer science at USMBA-Fez University. His is the director of the LIIAN Laboratory. His research interests include real-time rendering, Image-based rendering, virtual reality, biomedical signal, camera self calibration and 3D reconstruction.

Hamid Tairi received the PhD degree from USMBA-Fez University in 2001. He is currently a professor of computer science at USMBA-Fez University. His is also a member of the LIIAN Laboratory. His research interests include image processing, biomedical signal, Image-based rendering, visual tracking for robotic control and 3D reconstruction.