Face Tracing

15 downloads 0 Views 207KB Size Report
subdivided in order to preserve a constant accuracy for the object detection. This algorithm can ..... automatically the faces with vertex P. If, in what follows, the face ABC have to be subdivided .... It is obvious that the MCRT casts too much rays to compute the top of the picture, which is ... introduced fig. 12 on the Eiffel tower.
Face Tracing J. C. Gonzato and B. Le Sa¨ec LaBRI1 , 351 cours de la lib´eration, F-33405 Talence, France [gonzato|lesaec]@labri.u-bordeaux.fr

Abstract. We present a new algorithm called face tracing based on 3D incremental ray tracing. Faces are triangular surfaces that sample the entire view frustum. During the propagation of the faces in the scene, each is dynamically subdivided in order to preserve a constant accuracy for the object detection. This algorithm can also be applied to the problem of anti-aliasing.

1 Introduction The ray-tracing algorithm, based on the original work of Appel [3], was developed by Whitted [10]. Its basic idea is to cast rays from the viewer through the pixels of the picture following the inverse path of the light in the scene. This algorithm allows one to obtain very realistic pictures. It has two inconveniences: first, aliasing in images is generated; second, in using a perspective projection, two consecutive rays diverge and so, the area explored by a ray increases with the distance from the viewer. To avoid the two previous problems, new methods derived from classic ray tracing have been developed. Whitted [10] oversamples the image by casting more than one ray for each pixel using a hierarchical subdivision of the pixel. Heckbert and Hanrahan [5] introduce beam tracing and Amanatides [1] cone tracing in order to avoid the problem of an infinitesimal representation of a ray. Finally, Monte Carlo ray tracing [7] improves the first model of Whitted by casting rays randomly in the pixel. These methods usually give good results on some types of scenes, but typically cost a lot in computation time. A new algorithm, called face tracing, is introduced in this paper. It takes the structure of the scene in account, by sampling the entire view frustum with the same sampling accuracy but without the the problem of aliasing. Face tracing is well-adapted for two main types of natural scenes. The first one includes same-sized objects situated at very different distances from the viewer. For instance, trees all along a straight road. The second type of scene is composed of objects with very different dimensions but situated at about the same distance from the viewer. For instance, recall the well-known picture of a pigeons in flight between New York city skyscrapers. In this article, we, first, present our motivations for creating a new ray-tracer by comparing it with previous work done in this domain. Then, to simplify the presentation of this paper, we give an overview of the algorithm. Then, we develop, step by step, the complete Face Tracing algorithm. Finally, we propose a comparative test between our face tracing and the other classic ray-tracing algorithms. In fact, we will eliminate all 1 Laboratoire Bordelais de Recherche en Informatique (Universit´ e Bordeaux I and Centre National de la Recherche Scientifique). The present work is also supported by the Conseil R´egional d’Aquitaine.

algorithms except the Monte Carlo ray tracing algorithm which will remain as the only interesting comparison. The two implementations use the same software kernel and we compare the costs for high-quality rendering of a test scene. In the conclusion, we will discuss some applications of our method.

2 Motivations and previous works In this section, we detail the different previous works based on the classical ray tracing method. The naive ray-tracing algorithm has three main drawbacks: it creates aliasing in generated pictures, it does not explore the scene completely and finally, it suffers from an increase in the surface covered by a ray as it goes further from the viewer. Whitted [10] and Painter [6] oversample the image by casting more than one rays per pixel using a regular hierarchical subdivision of the pixel. Since the surface covered by a ray increases with the distance from the viewer, the problem of aliasing is put only retarded . Moreover, the subdivision criterion is only based on the difference of the return color of the rays in the pixel. So this algorithm does not take into account the structure of the scene and new rays are always cast from the viewer. Heckbert and Hanrahan [5] decompose the view frustum by beams cast from the viewer. Although beam tracing solves some of the problems associated with tracing infinitesimally thin rays, there is an increase in the complexity of the geometry computations. Indeed, the scene is limited to polygonal objects and Heckbert introduces simplifications in the refraction calculations because the beam geometry is not preserved after intersection. Another approach to the beam tracing is the pencil tracing [9]. Parallel rays are cast from the viewer, but the problem of the divergence of rays after intersections remains and so the exploration power of a ray decreases with the distance from the viewer. Cone tracing was developed by Amanatides [1]. The view frustum is decomposed into cones starting from the viewer passing through the picture. In cone tracing, objects are limited to spheres and polygons. Either cones do not tessellate the picture completely and so the view frustum is not completely explored, or there is redundancy when cones overlap, which generates noise in the pixel color computation. Finally, commercial products usually use the Monte Carlo ray tracing algorithm. It is based on the same techniques as Whitted hierarchical ray tracing, but rays are cast randomly in the pixel. So, the stochastic approach limits some specific problems of aliasing. This approach increases both the realism of pictures and the cost of computation. It explores randomly, as much as possible, the view frustum and rays cast from the viewer. Monte Carlo does not take the scene geometry in account and casts the same number of rays per pixel all over the picture. Our algorithm called face tracing is a Monte Carlo-based algorithm which explores completely the view frustum decomposed into a complete triangular tessellation faces. They are cast from the viewer. In this method, the faces are subdivided dynamically:

 

when their surface becomes too large comparing to the local scene exploration. With this, we guarantee the same accuracy of sampling all over the scene. when a face intersects partially an object to limit the aliasing generation.

This method differs from the classic anti-aliasing algorithms by the fact that oversampling is done only where it is necessary in the scene. So new rays, which describe a subdivided face, are not cast from the viewer. Face tracing does not cast the same number of rays by pixel. Finally, this ray-tracer is compatible with all types of objects like polygons, implicit surfaces, etc...

3 Face Tracing 3.1 Overview of the algorithm The view frustum is sampled by triangular faces. To simplify the algorithm, this sampling method is applied to the picture to generate. Pixels of the image are tessellated by triangular faces. The choice of the number of faces per pixel is arbitrary. The faces progress step by step in the scene and the step of progression is computed as a function of the enlargement of the surface of the face. We use the surface of each face to control the divergence of the rays progressing in the scene. When a face surface becomes too large, we split it into four sub-faces by casting three new rays. These rays are sent from the point of computation, one on each edge of the face. If there is an intersection between a face and some objects of the scene, there are four cases to treat: 1. If the three rays of a face hit one single object in the same step of computation, the face is reflected (resp. refracted) in function of the optical properties of the object. 2. If only one ray of a face hits one single object, we automatically subdivide the face in order to avoid aliasing near the boundary of the object. The management of the faces on the boundary is abandoned. 3. If two rays hit one single object, the same algorithm as case 2 is applied. 4. Finally, if two (resp. three) rays of a face hit two (resp. three) different objects, the face is subdivided and the management of new faces on the boundary is abandoned. Indeed, the surface of these new faces are lower than the threshold initially given. So, the management of the faces is abandoned in two cases: either when the maximal depth of face subdivision is reached, or, when a partial intersection between a face and an object occurs. The first avoids a combinatory explosion of the number of faces.When this management is abandoned, rays progress in the scene using the classical Whitted ray-tracing. Faces, in our method, have not a real existence, but are simply defined by three standard rays. So, to manage faces, rays must progress in the scene three by three. As a ray defines more than one face, all faces included in the pixel tessellation (thus all rays) have to progress simultaneously in the scene. This implies a specific data structure to store faces and rays which is detailed later. The color of a ray is computed using a standard illumination model. So, a ray is stopped when it touches a Lambertian object or when its maximal depth of recursion is reached. When all rays of a pixel have a assigned color, the final color is computed. 3.2 Initialisation of the Face Tracing As our method is compatible with the incremental ray-tracing algorithm [2], our scenes are voxelised to limit the number of intersection computations. The pixels of the pictures are cut into two triangular faces which vertices are the corner of these pixels (fig. 3). The four rays, so the two faces are cast into the scene. In the next figures, we consider only one face, coming from one of the two primary faces or from subdivisions, which is propagated in the scene.

3.3 Computation of the steps of progression At each step of the progression of the face, this face is subdivided into four new ones. The average of the surface of the new faces is equal to the area of the initial faces. This implies a specific computation of the step of progression which is majored by solving, in 2D, a first order equation, and in 3D a second order equation (fig. 1): A2 A1 α β

D1

D2 Step D2-D1

B1

B2

Fig. 1. Step Computation

Step

1 = tan(D 2) ?+ Dtan( )

(1)

If a ray hits an object between two steps, the ray is stopped at the point of intersection (fig. 2).

Object Rays

Face

Face

Computed Step of progression

Fig. 2. Step with intersection

3.4 Oversampling method When the rays diverge from each other during the progression in the scene, the surface of the face increases. When it becomes too large, the face is subdivided into four new faces to preserve the accuracy of sampling. This decomposition is obtained using three new random points on the edges of the face. Three new rays are sent from these three points. The used data structure is a Quad-Tree [8]. Each node of the Quad-Tree refers a face in progression: so, three rays. Moreover, some rays present in the data structure may be linked to a face F . This occurs when such a ray is cast from the edge of F . In this case, it could be used by later subdivision of F . For instance in fig 3, for the face A0 B 0 C 0 of our example, a link is created with the ray P . This link allows us to keep the advantages of the hierarchical structure. Indeed, if the face A0 B 0 C 0 has to be subdivided, the creation of a new ray on the edge B 0 C 0 is useless. We choose directly the ray P generated by the face B 0 C 0 C . The level of subdivision is stored on each ray. The four first rays are given level 0.

A

B

A

A’

A

B

A’

B Eye

B’ C’

C’

C

D

D

C

D

C

Image

Pro

gres

c.

b.

a.

B’

P

sion

Step

Fig. 3. Face subdivision method

The maximal surface area for the first faces is Area 2Pixel . This area defines the minimal frequency for sampling the scene. It is the based on the threshold computation for new subdivisions. We use: Threshold

= 4  Area 2Pixel

(2)

Since a face is subdivided into four new faces, the ”4” factor allows us to keep on average the area of the initial face on each new face. To avoid a computational explosion, we naturally choose to limit the number of subdivisions so as to limit the depth of the quad-tree. The user fixes this limit during the phase of description of its image parameters. When the maximal level of subdivision is reached, the subdivision process is abandoned and then the rays progress in the scene as in classical ray tracing. 3.5 Intersection with objects If there is no intersection between an object and a face, the face follows its ”natural” progression.

Eye

M M Object

Image

Pro

gres

sion

Step

Fig. 4. Intersection with a specular object

If an intersection between the treated face and one or more objects occurs, a specific treatment must be done which could lead to immediate subdivision of the face:

 

If the three rays of a face hit a same object, a reflected face (resp. refracted) is generated using reflected rays (resp. refracted). If one ray hits an object, a refracted ray may be created. In this case, it is substituted to the incident ray in the face after its deflection computation. The face

follows its progression normally. If a refracted ray is not generated, the face is first subdivided. In our example on fig. 5, the faces BPD, DPE and EPC are subdivided to improve detection of the object boundary. The algorithm removes automatically the faces with vertex P. If, in what follows, the face ABC have to be subdivided, only AGH will continue its progression in the scene. Object C

C

A

A

E

P

C

H

A E

P

E

P G

D

B

B

D

B

D

c.

b.

a.

Fig. 5. Subdivision following an intersection

 

If two rays of a face hit one object, the algorithm follows the same process as the previous case that is, if there are reflected rays, the face is first subdivided and some of the new faces are abandoned. It two or three rays of a face hit two or three different objects, the face is first subdivided in order to preserve a good boundary detection and then, new faces on the boundary are destroyed.

3.6 Color of a pixel When all rays of the pixel have an assigned color, the final color is computed. Their contributions are equivalent in the pixel, the weight of each rays is:

%(A) = %(B) = %(C ) = %(D) = 41 A

A

B

A = 1/4 B = 1/4 C = 1/4 D = 1/4 C

D

A’

A = 2/11 B = 2/11 C = 2/11 D = 2/11 A’ = 1/11 B’ = 1/11 C’ = 1/11

B’ C’

C

A

B

(3) A’

A"

B

B’

C’ B"

C"

D

C

D

A = 4/25 B = 4/25 C = 4/25 D = 4/25 A’ = 2/25 B’ = 2/25 C’ = 2/25 A" = 1/25 B" = 1/25 C" = 1/25

Fig. 6. Weight of each ray in the pixel

The first method usually implemented in ray-tracing using Monte Carlo approximation computes the final color of the pixel by computing the average of the color of each ray. When we generate new rays somewhere in the scene, these rays start implicitly from the viewer. So, the first method could be applied to compute our final color. In fact, it is unsuitable for our algorithm. Indeed, with the stochastic ray tracing algorithm, the area represented by each ray on the pixel is equivalent on average and so, computing the average color of each ray is correct. In our case, the area covered by each ray decreases by four at each subdivision. By computing the average color of rays, the color

of subdivided zones of pixel becomes predominant, thus we have to use the following color computation: When a subdivision occurs (ABC in fig. 6), a part of the weight of A, B and C is redistributed to the new created rays ( A0 B 0 C 0 ). We assign the “normalized” half weight of the parents rays to these news rays. The color of a pixel is:

PR %(Ri)Color(Ri) iP ColorPixel = R %(Ri ) i

(4)

%(Ri ) = 2N1Ri where Ri are the different rays of the pixel, %(Ri ) is the weight of Ri and NRi the with

subdivision level of Ri .

3.7 How to prevent Ray-recomputations At this point of the description of the algorithm, we treat the pixels independently, but we can notice that we have to recompute the path of each initial (A, B, C,D) rays four times. So we group in a same treatment a set of pixels using a constant size zone cache. This will limit the number of ray recomputations. For instance, the pixel can treated row by row and the paths situated at the bottom of each pixel of the cache are stored. They will be not recomputed when the next row of pixels will be treated. Picture

Pixels Computed In Computation Not Computed Computation way

Fig. 7. Picture/screen generation

In order to limit the memory size of the cache, its size is not automatically equal to the picture width. In the case of a shorter cache (part gray fig. 7), the picture is generated column by column, each one corresponds to the size of the cache. Each part is computed row by row as previously described. Only rays situated on the boundary of two columns of computations are recalculated twice.

4 Comparative test between face tracing and ray tracing In this section, we compare our algorithm (FT) to the ray-tracing algorithm using Monte Carlo anti-aliasing method (MCRT) only. In fact, MCRT is only the method which has the same desired properties as our algorithm:

    

To have a complete exploration of the scene, To protect rendering against aliasing, To control the surface covered by a ray in function of the distance to the viewer, To be used with any time of scene (polygonal, implicit, ...) And finally to deal with completely with reflection and refraction.

In order to make this test, we want to compute same images with the two algorithms, i.e the surface covered by any ray all over the scene had to be the same. In this case, our two images are called images with the same Quality. Two main types of scene put the classical algorithm to their limits. The first one includes a number of the same object situated at very different distances from the viewer. The second type of scene is composed of objects with very different dimension but situated at about the same distance from the viewer. These two types of scenes are analogous from the point of view of algorithm complexity and we propose to make the test with the first described type. So, we choose a scene composed of two sets of fifty of the same object. The first set is situated closed to the viewer (10 meters), and the second one at increasing distances (10 - 120 meters) at each step of evaluation.

Viewer

Position of the set of objects

Image Test 1

Test N

Fig. 8. Our test scene

With this test, we want to emphasize the weakness of the MCRT algorithm. We compare the computation time with the two methods (using the same kernel software). To guarantee the same quality of the images rendered, we first compute the image with our algorithm (FT). The maximal level of subdivision (N ) for the image generation is stored. N implies that for at least one pixel of the image, our method cast SN rays done by:

SN = SN ?1 + AN ?1 (5) with S0 = 4 and AN = 2N +1 + 3:22N where AN is the edge number at level N . So, MCRT has to cast SN rays per pixels in order to obtain the same accuracy of

intersection and color computation. In our test simulation, we limit the depth of the quad-tree to three subdivisions. rays per pixel with Indeed, with three subdivisions on the FT, we have to cast S3 the MCRT method. We can consider that this number is really sufficient to obtain high quality pictures. Figure 9.a and 9.b presents two pictures generated at two steps of comparison (a. 30 meters and b. 90 meters). Figure 9.c presents a depth image of 9.b where only the level of subdivision is printed. The dashed lines on figure 9.c represents the edges of the bounding box including the scene. Our algorithm generates all these presented figures.

= 81

0. 1. 2. a.

c.

b. Fig. 9. The test series time(s)

ys ra

ra

81

25

=

=

Su

bd

:3

:2 bd Su

:1 bd Su

Su

bd

:0

=

=

9

4

ra

ra

ys

ys

ys

MCRTth

MCRTpr FT

d(m)

Fig. 10. Computation costs

The computation cost graph (fig. 10) displays the rendering time in seconds for the test scene. The test is realised on a PC Pentium II 300 MHz and the size of images rendered is 512x512 pixels. The FT curve (resp. MCRTth and MCRTpr) represents the face tracing computation test (resp. ray tracing with Monte Carlo algorithm, a theoretical and a practical curve). The theoretical curve MCRTth corresponds to our comparative test method, the MCRTpr is detailed below. We can notice, on the graph (fig. 10), that the cost of computation increases linearly for our face tracing. Indeed, this phenomenon is linked to the type of progression of the faces in the scene, i.e. surface and step computations. The different steps visible in the MCRTth curve correspond to the different level of subdivisions in the FT algorithm on the same scene (0, 1, 2 and 3 which correspond to 4, 9, 25 and finally 81 rays per pixels). The more the set of objects in the bottom of the scene (fig. 9) is farther from the viewer, the more the accuracy of the computation is important. Therefore, the MCRT algorithm has to cast a great number of rays per pixel over all the image.

It is obvious that the MCRT casts too much rays to compute the top of the picture, which is composed of objects closed to the viewer (top of fig 9). The FT algorithm casts few rays to compute the top of the picture and at most the same number of rays than the MCRT method for the inferior part of the image. So, on the upper of the scene, FT is less expensive than MCRT, but, on the lower part, MCRT costs less than FT because it does not have to manage the faces and does not progress step by step. We add another curve called MCRTpr because a typical user manipulating a commercial product will not pass directly from 4 to 9, 25, 81 rays per pixels. In fact, he will progressively increase, depending on his scene, the number of rays to cast. We consider that the usual limit is 30 rays per pixel to obtain an high quality picture. So the MCRTpr curve is an interpolated version of the MCRTth curve limited to this maximum of 30 rays per pixels. With 30 rays per pixels, the surface covered by each ray is more important than our method for the objects situated after 80 meters and so the rendered objects were not as accurately described as in our method. We can remarks that our method still seems to be more rapid.

5 Conclusion This article presented a new ray tracing algorithm called face tracing. Faces are cast from the viewer in the scene. To keep the same accuracy of sampling all over the scene and thus to avoid aliasing, we subdivide a face, composed of three rays, when it is necessary in the scene. Since new rays are not cast directly from the viewer and since we do not send the same number of rays per pixel, face tracing distinguishes itself from other classic ray tracing methods. A comparative test has been done. We conclude that, for a fixed quality of generated image, face tracing turns out to be more efficient on some scenes (landscapes for instance). Finally, it can be used to different applications:



Mirage generation [4]: This method has been used to produce images of mirage phenomena. Mirages are caused by the deflection of light rays going through a non constant media, usually a high temperature gradient. Our rendering algorithm is then adapted to advance step by step in the media and compute the deflection of the rays and faces. Moreover, two neighboring rays leaving the non constant media, can diverge very quickly and very much, especially after the ray crossing point (fig. 11). In this case, the surface of exploration of each ray be-

Heat increase

Fig. 11. Nonlinear progression of ray light

comes too large to be representative, which introduces aliasing in pictures. So our rendering algorithm takes this into account this by casting new rays between those which diverge. This application is already implemented and an example of mirage is introduced fig. 12 on the Eiffel tower.





The face tracing can also generate images coming from a virtual endoscopy examination. Traditional virtual endoscopy is a technique that mimicks a real endoscope with a single virtual camera to render volumetric imaging data from a NMR2 tool or a scanner. Indeed, with endoscopy, surgeons examine organs of patient via an optic fiber. He views a mirage image of the organ caused by the multiple refraction of light in the optic fiber. With this method, we can also render gems[11] and diamonds3. Gems have the particularity that two consecutive rays follows very different ways inside it. So, a lot of details in the gems between these two rays are lost with a classical raytracer. With our method, we can subdivide rays inside the gems to limit the lost part and so render the gems with accuracy.

References 1. J. Amanatides. Ray tracing with cones In Siggraph’84, pages 129–135, 1984. 2. J. Amanatides and A. Woo. A fast voxel traversal algorithm for ray tracing. In Proceedings of Computer Graphics International, pages 149–155, 1987. 3. A. Appel. Some techniques for shading machine renderings of solids. In SJCC, 37–45 1968. 4. Marc Berger, Nancy Levit, and Terry Trout. Rendering mirages and other atmospheric phenomena. In Eurographics’90, pages 459–68, September 1990. 5. P. S. Heckbert and P. Hanrahan Beam tracing polygonal objects In Siggraph’84, pages 119–127, 1984. 6. J. Painter and K. Sloan. Antialiased ray tracing by adaptative progressive refinement. In Siggraph’89, pages 281–288, 1989. 7. T. Porter R. L. Cook and L. Carpenter. Distributed ray tracing. In Siggraph’84, pages 165– 174, 1984. 8. H. Samet. The quadtree and related hierarchical data structures. In Computing Surveys, volume 16(2), pages 187–260, 1984. 9. M. Shinya, T. Takahashi and S. Naito Principles and Applications od Pencil Tracing In Siggraph’87, pages 45–54, 1987. 10. T. Whitted. An improved illumination model for shaded display. In CACM, pages 343–349, 1980. 11. Y. Yuan, T. L. Kunii, N. Inamoto and L. Sun Gemstone fire : Adaptative disperse ray tracing of polyhedrons. In The Visual Computer, pages 259–270, 1988.

2 Nuclear 3 This

Magnetic Resonnance idea was suggested by Patrick CALLET. An implementation is in progress.

Fig. 12. The Eiffel Tower