Rayskip: Faster Ray Tracing of Implicit Surface Animations

Report 1 Downloads 90 Views
Rayskip: Faster Ray Tracing of Implicit Surface Animations Erwin de Groot∗ Department of Computer Science University of Calgary

Brian Wyvill† Department of Computer Science University of Calgary

Abstract

The RaySkip algorithm exploits object space temporal coherence to reduce the number of surface evaluations along the ray that has to be traced. This is accomplished by comparing the ray with other rays in the vicinity in 4D space (in object space and in time). This can be done for both primary and secondary rays. Unlike other algorithms using temporal coherence, RaySkip does not require the camera, the lights or the objects to be static, while still achieving a considerable speed up.

Implicit surfaces offer several advantages over other volume representations, but despite the ease with which CSG and smooth blending can be used to construct complex models they are not commonly used. The main reason for this is the long visualization time, especially when the surface is being rendered using ray tracing. In this paper an algorithm called RaySkip is described. Rayskip improves rendering times of ray tracing animations of implicit surfaces (19% to 55% per frame). This is accomplished by exploiting object space coherence and temporal coherence, reducing the number of evaluations of the surface needed to trace a ray.

2

There are several ways to reduce the time spent on calculating intersections. Some techniques try to speed up the evaluation of the surface, usually by simplifying the definition of the surface [Fox et al. 2001; Goldfeather et al. 1988; Gascuel 1995]. Space subdivision algorithms [Duff 1992; Fox et al. 2001; Szirmay-Kalos et al. 2002; Cleary and Wyvill ] reduce the number of evaluations by splitting up the space into voxels, where each voxel is either empty or contains part of the surface. This way empty voxels can be traversed more quickly. Adaptive Supersampling [Genetti and Gordon 1993; Lau 1995; Lee et al. 1985], Undersampling [Akimoto et al. 1991] and some anti-aliasing algorithms [Carpenter 1984; Wyvill and Sharp 1989] reduce the number of rays in low detail areas.

CR Categories: I.3.5 [Computer Graphics]: Curve, surface, solid, and object representations; I.3.7 [Computer Graphics]: Animation, Raytracing Keywords: Raytracing, Animation, Implicit Surfaces, Temporal coherence

1

Previous work

Introduction

Implicit surfaces are volume representations where the surface of the volume is defined by an iso-value of a real function. There are several kinds of implicit surfaces [Wyvill et al. 1986; Pasko et al. 1995; Bloomenthal ], but in general implicit surfaces can be represented by a function f : R3 → R which takes a point p ∈ R3 and returns the field value f (p) of that point. A surface S of a function f can be defined as the collection of points with a certain field value c ∈ R: S = ∀p∈R3 (f (p) = c) (c is called the iso-value). The volume inside surface S is the collection of points for which the field value is greater than or equal to c.

Temporal coherence between frames in an animation can be exploited in several ways. Some methods use image-temporal coherence [Chapman et al. 1990; Jr. 1988]. These methods assume that when the color of a pixel in frame f1 equals the color of that pixel in frame f2 , the pixel has the same color in all frames between f1 and f2 . These methods usually fail when small objects are quickly moving across the screen, since these object might be missed in certain frames. Furthermore, these methods are not very useful when the viewpoint or light sources are moving because that usually causes almost every pixel to change color.

The problem with ray tracing implicit surfaces [Bloomenthal ; Hart 1993] is that finding intersections between rays and surface is computationally expensive. Unlike with polygonal meshes, it usually takes several iterations and a lot of time consuming evaluations of the implicit surface. There are several techniques to find intersections with implicit surfaces such as Ray Marching, Interval Analysis [Mitchell 1990; Fox et al. 2001], LG-Surfaces [Kalra and Barr 1989] and Sphere Tracing [Hart 1996]. Al of these techniques evaluate the implicit surface S in several points or intervals along a ray r, to find the intersection of r with S. Even though some of these techniques can drastically reduce the total rendering time, finding intersections still remains the bottleneck in ray tracing implicit surfaces.

Several methods monitor which parts of the object space have changed between two consecutive frames and then decide which rays need to be recalculated [Sanna and Montuschi 1998; Jevans 1992; Davis and Davis 1999]. As with the methods based on imagetemporal coherence, these methods fail for the same reason when the viewpoint or light sources are moving. If the model is build out of polygons, a speed up can be obtained by searching for the frames where a certain polygon becomes visible or invisible [Chapman et al. 1991; Hubschman and Zucker 1982]. Ray polygon intersections for the frames in between can be sped up because only a subset of the polygons have to be considered. Unfortunately these methods are not applicable to implicit surfaces.

[email protected]

[Glassner 1988] describes how 4D bounding volumes (bounding the objects in object space and in time) can be calculated in a preprocessing step. This is more efficient than calculating 3D bounding volumes for every frame separately. Unfortunately the computation time to construct bounding volumes for implicit surfaces is almost negligible compared to the rest of the ray tracing process, so not much can be gained by applying 4D bounding volumes.

[email protected]

Copyright © 2005 by the Association for Computing Machinery, Inc. Permission to make digital or hard copies of part or all of this work for personal or classroom use is granted without fee provided that copies are not made or distributed for commercial advantage and that copies bear this notice and the full citation on the first page. Copyrights for components of this work owned by others than ACM must be honored. Abstracting with credit is permitted. To copy otherwise, to republish, to post on servers, or to redistribute to lists, requires prior specific permission and/or a fee. Request permissions from Permissions Dept, ACM Inc., fax +1 (212) 869-0481 or e-mail [email protected]. © 2005 ACM 1-59593-201-1/05/0010 $5.00

Reprojection [Jr. 1988; Adelson and Hodges 1995; Havran et al. 2003] stores the intersection points of the primary rays of a frame

31

current frame y-1

f1

previous frame

y

element of V x,y

y+1

f2

x-1 x

x+1

Figure 3: Pixels used to estimate the length of ray rx,y

l v0

Figure 1: Reprojection

px,y+1 px,y-1

l v3 l v4 l v1 l v2

r x,y+1

px,y

rx,y

srx, y

rx,y

-1 distance from the eye

Figure 2: Primary rays

0

3

rx, y

Vrx, y

Figure 4: Determining the skip of a ray

RaySkip exploits the coherence between the lengths of rays by estimating the length of ray rx,y based on rays in the vicinity of rx,y . If pixels are traced in a left to right, bottom to top fashion, rays rx−1,y and rx,y−1 can be used to estimate the length of rx,y . Besides the rays of the current frame, the rays rx,y , rx+1,y and rx,y+1 of the previous frame are good candidates to be included in the estimation of lrx,y . The collection Vx,y is defined as the collection of rays that can be used to estimate lrx,y and includes the 5 rays described above (see figure 3). Theoretically more rays could be included to increase robustness, but in practice more rays only slow down the algorithm and do not contribute much at all to the robustness.

The Rayskip algorithm

The RaySkip algorithm tries to reduce the portion of the rays that have to be traced. To accomplish this, RaySkip exploits object space coherence and temporal coherence to search for a portion of a ray that is not likely to hit the surface. This is done by comparing a ray with neighboring rays and rays from the previous frame.

3.1

v0 v1 v2 v3 v4

{

f1 with the surface and projects them back to the camera of a following frame f2 . This way the intersection points of several primary rays of frame f2 can be determined without having to trace the rays (see figure 1). Even shadow ray information can be reused, but viewpoint dependent rays like reflection and refraction rays always have to be traced. The downside of Reprojection algorithms is that they require a static scene which is usually not the case in animations.

Primary rays

The length lv of any ray v in Vx,y could be used as an estimate for lrx,y . If Vx,y contains 5 rays, there are 5 equally plausible estimations for lrx,y . Since only the first intersection of ray rx,y with the surface matters, we will use the smallest length to estimate lrx,y : srx,y = minimumv∈Vx,y (lv ), where srx,y is the ‘estimated length’ of ray rx,y called the skip (see figure 4).

To calculate the color of a pixel px,y , the ray rx,y starting in the ‘eye’ or ‘camera’ going through px,y has to be traced (see figure 2). Because the viewpoint and objects usually do not move a lot between consecutive frames, the distance from the eye to the intersection point of ray rx,y (called the ‘length’ lrx,y of ray rx,y ) will most likely not change much either. The lengths of the rays through two neighboring pixels will most likely be similar as well.

The skip srx,y of a ray rx,y does not guarantee the length lrx,y is

32

px,y+1 inside volume outside volume

srx, y

distance from the eye

0

px,y

A

B

C

Figure 6: Secondary rays

3.2

Secondary rays

With a secondary ray it is not as obvious which rays are in the vicinity, or which rays can be used to calculate the skip. Other than finding the right rays to calculate the skip value, the RaySkip algorithm for secondary rays is the same as for primary rays.

D

If a ray rs is a secondary ray of pixel px,y : rs ∈ Sec(rx,y ) (Sec(r) denotes the collection of rays that are cast as a consequence of an intersection of r with the surface), it is likely to be similar to a secondary ray of a neighboring pixel, provided the intersections of the primary rays are close to each other and the directions of the secondary rays are almost parallel (see figure 6).

Figure 5: Possible situations after skipping part of a ray

equal to or even similar to srx,y , but since all rays in Vx,y have at least length srx,y , it is most likely that the length of ray rx,y is not much smaller than srx,y either. Figure 5 shows the four possible relations between the estimated length srx,y and the actual length lrx,y .

If rp is either a primary or secondary ray, Vrp is a subset of Vrp that contains the rays of Vrp with a length similar to lrp (the relative difference is less than a certain constant). Vrp contains the rays that (up until that recursion) traversed a similar path as rp . Now Vrs can be defined for each rs ∈ Sec(rp ): Vrs = {r ∈ Sec(Vrp )|r ⊗ rs } where Sec(Vrp ) = ∪v∈Vrp Sec(v) and r0 ⊗ r1 is only true when one of the following constraints is true:

To determine which part of the ray should be traced, the field value f (p) of the implicit surface is calculated in point p on ray rx,y at distance srx,y (this is not possible with polygonal models). If this field value is bigger than the iso-value c (this means p lies inside the volume), there must be an intersection closer than point p: lrx,y < srx,y (possibility B in figure 5). In this case tracing ray rx,y will be started at distance srx,y in the direction of the eye. Since lrx,y is expected to be close to srx,y , a smaller part of the ray has to be traced to get the intersection (in most cases lrx,y is closer to srx,y than the eye). Unlike polygonal meshes, ray tracing implicit surfaces requires several recursions and evaluations to find an intersection of a ray with the surface. By tracing a smaller part of the ray, fewer evaluations are needed and therefore a speed up is realized. In our implementation ray interval analysis is used, but other methods should benefit from the RaySkip algorithm as well.

• r0 and r1 are both shadow rays and target the same light source • r0 and r1 are both reflection rays and are almost parallel (the dot product of the normalized directions is bigger than a certain constant) • r0 and r1 are both transparency rays and are almost parallel Now Vr can be constructed for all rays r (primary and secondary rays), the RaySkip can be applied to all rays as described in section 3.1.

If the field value f (p) is smaller than the iso-value c (p lies outside the volume), lrx,y is most likely bigger than srx,y . In this case tracing of ray rx,y can be started at srx,y . Sometimes an intersection will be found (possibility A in figure 5) and sometimes not (possibility C in figure 5). In both cases a speed up is realized by not tracing the first part of the ray.

3.3

Error correction

Possibility D in figure 5 shows the case where RaySkip fails to find the first intersection. This happens when the ray rx,y has at least two intersections closer than srx,y (one intersection where the ray enters the volume and one where it exits the volume).

Possibility D in figure 5 shows the case where RaySkip fails to find the first intersection. This happens when the ray rx,y has at least two intersections closer than srx,y (one intersection where the ray enters the volume and one where it exits the volume). Section 3.3 describes how the occurrence of this case can be reduced to a minimum.

To reduce the missed intersections due to this problem a flooding algorithm is used. The flooding algorithm corrects the neighbors of a pixel p after its (primary and secondary) rays have been traced. The flooding algorithm will terminate when a pixel is not corrected.

33

Figure 7: Frame 25 of ‘Dancing Trees’ at 20 frames per second. Left: RaySkip without error correction. Right: RaySkip with error correction.

Figure 8: Frame 40 of ‘Dancing Trees’ at 10 frames per second. Left: RaySkip with error correction. Right: Ray traced image.

In most cases this flooding algorithm will terminate in the first iteration and will not take up too much time (see section 4). When a pixel px,y is considered for correction, first the skip srx,y of the primary ray will be calculated again based on the current lengths of the rays of the neighboring pixels. If the new skip value is greater than or equal to the old value, this ray does not need correction. If the new skip value is smaller than the old value, the part of the ray between the new and old skip value has to be traced. The pixel px,y needs to be corrected only if an intersection is found (secondary rays have to be traced again). If the primary ray did not need a correction, the secondary rays will be checked in the same way. To correctly handle objects that ‘fly’ into the scene, the primary rays of the pixels on the edge of the screen will always have a skip value of 0. Figure 7 shows the result of applying these error corrections. Figure 9: 9 frames from ‘Morphing Sphereflake’

In certain extreme cases a number of errors might not get corrected. Unfortunately it’s hard to tell in which cases this happens, but usually it involves low frame rates, small objects and/or fast moving objects. In figure 8 the frame rate has been reduced to 10 frames per second. Together with the small and fast moving branches of the trees this results in some errors in the shadows.

4

Results

The RaySkip algorithm has been implemented in the Blobtree.net software package [Blobtree.net ]. Although Blobtree.net uses Blob-

34

Times in hours:minutes:seconds

Ray tracing

Morphing Sphereflake Dancing Trees

RaySkip

5:05:04.1 3:01:32.6

Total 3:06:04.4 2:07:31.3

Speed up 39.01% 29.76%

Minimum speed Maximum speed up per frame up per frame 27.39% 54.17% 19.28% 38.70%

Corrections 0:09:06.3 0:03:53.2

Figure 13: Rendering results

Dancing trees 0:02:36 0:02:18

Rendering time

0:02:01

Ray tracer

0:01:44 0:01:26

RaySkip

0:01:09 0:00:52 0:00:35 0:00:17

RaySkip Correction

0:00:00 1

11

21

31

41

51

61

71

81

91

Frame

Figure 12: Results from rendering ‘Dancing Trees’

faster using the RaySkip algorithm.

Figure 10: 9 frames from ‘Dancing Trees’

The results shows that RaySkip produces a minimum of artifacts. When error correction is applied, only in certain extreme cases some errors are noticeable. The time spent on correcting errors is negligible. In both animations the error correction consumes less than 5% of the total rendering time (see figure 13).

Morphing sphereflake 0:04:19

0:03:36

Rendering time

0:02:53

In the result tables, rendering times are used rather than the number of surface evaluations. Although a reduction of evaluations leads to a reduction in rendering time, there is no direct relationship between the difference in evaluations and the amount of speed up. This is because the computation time of an evaluation is highly dependent on several factors like the distance from the surface and the local complexity of the surface.

Ray tracer

0:02:10

RaySkip

0:01:26

0:00:43

RaySkip Correction

Since the length and the direction of each ray in the scene have to be stored, the RaySkip algorithm can use a significant amount of memory. The amount of memory used by the RaySkip algorithm to render the two animations of figures 9 and 10 never exceeded 150MB. This amount of memory is not an issue on modern machines, but could still easily be reduced by optimizing the implementation. Even if the complexity of the scene requires a critical amount of memory, this can be solved by splitting up the frames of the animation into smaller parts and rendering each part separately.

0:00:00 1

11

21

31

41

51

61

71

81

91

Frame

Figure 11: Results from rendering ‘Morphing Sphereflake’

trees [Wyvill et al. 1999] and interval analysis [Mitchell 1990; Fox et al. 2001] similar speed ups are to be expected for other implicit surfaces and other intersection methods.

5

Two animations with moving cameras and moving objects have been rendered using the RaySkip algorithm (figures 9 and 10). Even though other temporal coherence algorithm can not be applied because of the moving camera/objects, RaySkip produces a considerable speed up (figures 11, 12 and 13). Although the speed up depends on the composition of the scene and the amount of changes between frames, both animations could be rendered considerably

Conclusion

RaySkip produces a considerable speed up in cases where other temporal coherence algorithms fail (19% to 55% per frame) without using an unreasonable amount of memory. It might not get the speed up other algorithms promise, but RaySkip does not depend on a static viewpoint or static objects. Therefore RaySkip should

35

not be considered as a replacement for other algorithms, but as an addition to be used in situations where other methods cannot be applied.

H ART, J. C. 1996. Sphere tracing: A geometric method for the antialiased ray tracing of implicit surfaces. The Visual Computer 12, 10 (Dec.), 527–545. H AVRAN , V., DAMEZ , C., M YSZKOWSKI , K., AND S EIDEL , H.P. 2003. An efficient spatio-temporal architecture for animation rendering. In Proceedings of Eurographics Symposium on Rendering 2003, ACM SIGGRAPH.

References A DELSON , S. J., AND H ODGES , L. F. 1995. Generating exact ray-traced animation frames by reprojection. IEEE Computer Graphics and Applications 15, 3 (May), 43–52.

H UBSCHMAN , H., AND Z UCKER , S. W. 1982. Frame-to-frame coherence and the hidden surface computation: constraints for a convex world. ACM Transactions on Graphics 1, 2 (Apr.), 129– 162.

A KIMOTO , T., M ASE , K., AND S UENAGA , Y. 1991. Pixelselected ray tracing. IEEE Computer Graphics and Applications 11, 4 (July), 14–22.

J EVANS , D. A. 1992. Object space temporal coherence for ray tracing. In Proceedings of Graphics Interface ’92, 176–183.

B LOBTREE . NET. http://www.blobtree.net.

J R ., S. B. 1988. Two algorithms for taking advantage of temporal coherence in ray tracing. The Visual Computer 4, 3 (Sept.), 123– 132.

B LOOMENTHAL , J. Introduction to Implicit Surfaces. Morgan Kaufmann, ISBN 1-55860-233-X. Edited by Jules Bloomenthal With Chandrajit Bajaj, Jim Blinn, Marie-Paule Cani-Gascuel, Alyn Rockwood, Brian Wyvill, and Geoff Wyvill.

K ALRA , D., AND BARR , A. H. 1989. Guaranteed ray intersections with implicit surfaces. Computer Graphics 23, 3 (July), 297– 306.

C ARPENTER , L. 1984. The A-buffer, an antialiased hidden surface method. Computer Graphics 18, 3 (July), 103–108.

L AU , R. W. H. 1995. An adaptive supersampling method. Lecture Notes in Computer Science 1024, 205–214.

C HAPMAN , J., C ALVERT, T. W., AND D ILL , J. 1990. Exploiting temporal coherence in ray tracing. In Proceedings of Graphics Interface ’90, 196–204.

L EE , M. E., R EDNER , R. A., AND U SELTON , U. 1985. Statistically optimized sampling for distributed ray tracing. Computer Graphics 19, 3 (July), 61–68.

C HAPMAN , J., C ALVERT, T. W., AND D ILL , J. 1991. Spatiotemporal coherence in ray tracing. In Proceedings of Graphics Interface ’91, 101–108.

M ITCHELL , D. P. 1990. Robust ray intersection with interval arithmetic. In Proceedings on Graphics interface ’90, Canadian Information Processing Society, 68–74.

C LEARY, J., AND W YVILL , G. Analysis of an algorithm for fast ray tracing using uniform space subdivision. Visual Computer, 4(2), 65.

PASKO , A., A DZHIEV, V., S OURIN , A., AND S AVCHENKO , V. 1995. Function representation in geometric modeling: concepts, implementation and applications. The Visual Computer 11, 8, 429–446.

DAVIS , T., AND DAVIS , E. 1999. Exploiting frame coherence with the temporal depth buffer in a distributed computing environment. In Proceedings of Parallel Visualization and Graphics Symposium, 1999 IEEE, 29–116.

S ANNA , A., AND M ONTUSCHI , P. 1998. An efficient algorithm for ray casting of CSG animation frames. The Journal of Visualization and Computer Animation 9, 4 (Oct.–Dec.), 229–242.

D UFF , T. 1992. Interval arithmetic and recursive subdivision for implicit functions and constructive solid geometry. Computer Graphics 26, 2 (July), 131–138.

S ZIRMAY-K ALOS , L., H AVRAN , V., AND BALAZS , B. 2002. On the efficiency of ray-shooting acceleration schemes. In Proceedings of the Spring Conference on Computer Graphics 2002 (SCCG 2002).

F OX , M., G ALBRAITH , C., AND W YVILL , B. 2001. Efficient Use of the BlobTree for Rendering Purposes. International Conference on Shape Modeling and Applications (May).

W YVILL , G., AND S HARP, P. 1989. Fast antialiasing of ray traced images. In New Advances in Computer Graphics (Proceedings of CG International ’89), Springer-Verlag, 579–588.

G ASCUEL , J.-D. 1995. Implicit patches: An optimized and powerful ray intersection algorithm for implicit surfaces. In Implicit Surface.

W YVILL , B., M C P HEETERS , C., AND W YVILL , G. 1986. Data structure for soft objects. The Visual Computer 2, 4, 227–234. W YVILL , B., G UY, A., AND G ALIN , E. 1999. Extending the CSG tree. warping, blending and boolean operations in an implicit surface modeling system. Computer Graphics Forum 18, 2 (June), 149–158. ISSN 1067-7055.

G ENETTI , J., AND G ORDON , D. 1993. Ray tracing with adaptive supersampling in object space. In Proceedings of Graphics Interface ’93, Canadian Information Processing Society, Toronto, Ontario, 70–77. G LASSNER , A. S. 1988. Spacetime ray tracing for animation. IEEE Computer Graphics and Applications 8, 2, 60–70. G OLDFEATHER , J., M OLNAR , S., T URK , G., AND F UCHS , F. 1988. Near real-time CSG rendering using tree normalization and geometric pruning. Tech. Rep. TR88-006, UNC at Chapel Hill. H ART, J. C. 1993. Ray tracing implicit surfaces. Tech. Rep. EECS93-014, Washington State University - School of EECS.

36