Ray tracing surfaces of revolution - Semantic Scholar

Report 2 Downloads 120 Views
Ray Tracing Surfaces of Revolution: An Old Problem with A New Perspective George Baciu

Jinyuan Jia

Gibson Lam*

gbaciu Qcs .ust .hk

[email protected]

[email protected]

Abstract I n this paper we present a new subdivision scheme that is shown to improve the performance of ray tracing surfaces of revolution over Kajiya 's classical work [8]. This is based on a monotonic interval partitioning of a generatrix of a surface of revolution. The algorithm has a search complexity upper bound of O ( l o g ( mn ) )f o r m monotonic intervals and n subdivisions f o r each interval and runs up to three times faster on large scenes. This method also suggests a novel hybrid bounding volume scheme that reduces the number of intersection tests between a ray and the actual object surface.

~

'

Keywords: ray tracing, global illumination, surfaces of revolution, rotators, procedural rendering

1

Introduction

methods [3, 10, 2, 13, 18, 11, 14, 61. However, we are currently unaware of any technique that has significantly extended or improved ray tracing surfaces of revolution over Kajiya's classical work. The closest work that reported a full implementation based on Kajiya's work is by van Wijk [16, 171. We have recently observed that significant perfomance gains are possible by using a different type of space subdivision approach in localizing the ray-curve or ray-surface intersection problem. In this article, we show our recent results in the attempt t o improve on the performance of ray tracing planar curves and surfaces of revolution. We introduce a new data structure called the Monotonic Interval B i n a y Index Tree (MIBIT) which has a significant effect on the performance of ray-surface intersections.

2

Problem Statement

Ray tracing is one of the core rendering subsystems of a rendering engine. Even though it has been well covered in the computer graphics [4] and computational geometry literature [5], much work is still being done on optimal strategies for ray tracing 3D scenes [12]. Modern ray tracing techniques often seek t o improve the performance over the classical methods by optimizing space subdivision approaches. This ultimately leads t o fast localisation methods for the ray-ob ject intersection problem. For procedurally defined objects Kajiya [8, 91 proposed an effective ray tracing algorithm for fractal surfaces and surfaces of revolution based on a hierachical subdivision structure called the strip tree [l].This classical result has been virtually uncontested until now. Furthermore, there is a large body of literature on raysurface intersection methods for parametric or implicitly defined surfaces using general spatial subdivision

Figure 1. Intersecting a ray with a surface of rev0Iution

*Computer Science Department, The Hong Kong University of Science and Technology, Clear Water Bay, Kowloon, Hong Kong. Support provided by RGC grant HKUST 6089/993.

215 0-7695-1007-8/01 $10.000 2001 IEEE

Further subdivisions can be carried out by considering both an external (or maximal) as well. as an internal (or minimaJ) cylinder.

We first assume that surfaces of revolution are produced by a generatrix. The generatrix is a o n e t e o n e mapping from the real domain to its range. Therefore, there are no self-intersections in the generatrix itself. The generatrix is specified by a series of discrete points Pi,i = 1,2, ...,n t h a t represent samples of data points on a curve assumed t o be taken at small enough intervals that the curve can be reconstructed. Given a generatrix C and an axis of rotation U, let S be the surface of revolution generated by sweeping C around U. For a ray R , we aim t o determine as efficiently as possible the nearest point of intersection I from the eyepoint E along the ray. This is illustrated in Figure 1. A generatrix can easily contain a large number of points which induces a large number of segments. Multiplying this over a large number of objects of revolution, it can be easily seen that without an efficient subdivision approach the number of intersection tests can be significantly high. We introduce a new subdivision approach that effectively reduces the intersection tests t o a much simpler range test. Our initial results show an improvement of two t o three times over the classical results reported by Kajiya [9].

z

Figure 3. Wang’s ray intersection problem Wang [15] expanded on Kajiya’s work by subdividing the curve into a series of line segments PkPk+l, k = 0,1, ..., n, Figure 3. When revolved around the axis of rotation, each such segment PkPk+l, forms a truncated cone, Figure 3. Let Pk be given by the local cylindrical coordinates (zk,Rk). ’Then,

Rk = Z k M k

(1)

Nk

where Mk is the slope of segment k and Nk is the offset:

M~ = Rk+l - Rk zk+l

-z k

Nk =

The equation of the ray

Thus,

Figure 2. Bounding box representation in Kajiya’s ray intersection problem

3

Let

Previous Work

This work has been largely motivated by Kajiya’s classical work [9] in ray tracing procedurally defined objects. A strzp tree, Figure 2, was devised t o hierarchically subdivide the curve into local regions for checking the penetration of the ray with the curve. The surface of revolution can be enclosed into a bounding cylinder.

216

RkZk+i

-Rk+iZk

Zk+l - z k

(2)

PE can be obtained from:

Cylindrical shell

Then,

4.2

By substituting 4 and 5 into 6 we can express the zcoordinate in terms of a quadratic equation of the form:

An initial cylindrical bounding volume is constructed for the entire curve C in order t o avoid intersection testing for all the n truncated cones that subdivide the surface S. A cylandra’cal shell is built by enclosing the entire curve C into a vertical bounding box, as show in Figure 4.

where

2

ed ell

The surface of the truncated cone is generated by revolving the line segment PkPk+1 around the z-axis. The size of the truncated cone Tk is determined by the distance between Zk and &+I. Tk will contain the surface patch &. A ray PE may intersect the truncated cone at zero, one or two points. Wang[l5] used this intersecting formulation for hidden line removal in CAD wireframe drawings. Jia [7] proposed an adaptive cylinder bounding volume technique t o decrease the computational time of ray-surface intersection.

4

Figure 4. Bounding Cylindrical Shell In order t o reduce the intersection tests, initially, we investigated a single bounding cylinder volume based on the following considerations. 1. The cylindrical bounding volume encloses the surface of revolution more closely than the cube bounding volume, which is often found in computer graphics literature.

A New Ray Intersection Formulation

The main drawback in Kajiya’s formulation is the complexity of performing intersection calculations and its advantage is the fast interval search technique based on the strip tree data structure. On the other hand, Wang developed a very efficient intersection algorithm but failed to incorporate an efficient search data structure. We develop a new ray-surface intersection algorithm based on the intergration of Kajiya’s strip tree data structure and Wang’s intersection computations. This algorithm has shown a two-fold improvement over both Kajiya’s and Wang’s approach in the performance of ray tracing large scenes.

2. The ray-cylinder intersection calculations is simpler and more cost effective than ray-cone intersection. Consider the general case when a ray P E intersects the external cylinder at P I ,the internal cylinder at Pz, the internal cylinder at P3, and then again the external cylinder at P4. Let the axis of revolution correspond to the z -axis. Then the z-coordinates of these points will be z1, 2 2 , z3, and 2 4 . The projection of the ray segments onto the z - axis gives the intervals [z1, 221 and [ z 3 , z 4 ] , Figure 1. The segment [ z 1 , 2 2 ] defines the height of the truncated cylinder TI and [ z 2 , 2 3 ] defines the height of the truncated cylinder Tz. Thus, we only need t o test for intersection cylinder TI and T2. All the other cylinders located outside these two intervals need not be tested for ray-surface intersection. An initial bounding cylinder can be further reduced by a progressive projection as shown in Figure 1. For example, box A is first obtained from the initial intersection points of the ray with the cylindrical shell. Then, box B is obtained from A by considering the

4.1 The Generatrix Let C be a curve in a plane P and U a vector in P. We call C the generatrix of surface S when the entire plane P is rotated about U . We specify the generatrix C by a series of sample points Pi, i = 1,2,3, ..., n. Each point P i is identified by coordinates (xi,zi) in the local coordinate frame of the generatrix, where z is the axis of rotation.

217

minimum and maximum points of the generatrix segment and box C is obtained from the intersection of the ray with box B.

I

I

I I I

4.3 Hybrid bounding volume The bounding cylinder has a simple ray intersection forumlation, but it does not bound the generatrix very tightly. On the other hand, the truncated cone provides a tighter fit of the generatrix, but it is more expensive to compute the ray intersection problem. We propose a hybrid bounding box technique in which either the bounding cylinder or the bounding cone can be used alternatively according t o one of the following criteria:

I I

I

I

I .-

.

V

1., Area Criteria: choose the bounding box that minimizes the total area; this is often related t o the tightness of fit.

monotonic interval binar-v index tree

Figure 5. MonotonicInterval Binary Index Tree

2. Potential

Intersection Interval Criteria: choose the bounding box that minimizes the extent of the interval generated by the relative orientation of the ray and the bounding box. This decides to what extent the potential intersection interval will be compressed due to either bounding box.

we can obtain the number of points included in this interval and the maximal and minimal 2: and z coordinates of the interval by comparing two ending points.

3. Factor of Four (Interval Criteria): choose the vertical box if its area and potential intersection interval is less than four times the oblique bounding box. This criteria gives us a chance to reduce the vertical bounding box by following a tighter envelope and the ray intersection problem results in a much faster computational algorithm.

5

6

A new ray tracing algorithm

The ray tracing algorithm devised in this work has two main components: 1. a pre-processing phase, and 2. the rqy tracing phase. In the pre-processing phase we first split the curve into segments over monotone intervals. Then, we associate a bounding shell with each segment of the curve. Finally, we construct the full MIBIT structure.

The Monotonic Interval Binary Index Tree

6.1 Prc-processing

The strip tree constructed by Kajiya improves the interval search in the localization of the intersection region. Based on this idea, we construct a search tree with a 3D bounding box. However, we first segment the generatrix into monotone interval subsets, Tl,T2,...,T,,, as shown in Figure 5 . First, we organize the tree as a two-level intersection search tree and then construct the search index tree. The leaves will correspond to the monotone intervals. In the tree data structure, we store the following information: an array index of the interval starting point jl , an array index of the interval ending point ji, monotonic x-coordinate, and monotonic y-coordinate. The x and y coordinates contain a boolean value, 0 for increasing, or 1 for decreasing. From this data structure

In order t o reduce the potential number of raycurve intersections we construct a hierarchical binary tree structure over the interval of the entire generatrix. The structure is based on two types of subdivisions. The first, subdivision type splits the generatrix into m monotonic segments. The projection of these segments onto the axis of rotation U generates m intervals. The second subdivision type refines the monotonic intervals into n uniformly partitioned subintervals. We first generate m nodes corresponding to the m monotonic subdivisions. Then, we build the tree towards the root node by successive combination of pairs of nodes. The leaves of the subtree will be the 2' refined subdivisions

218

of the monotonic interval, where k is the height of the subtree. The next pre-processing phase computes an appropriate bounding shell for each subinterval. One bounding shell is associated with each node in the tree. We have worked with the following bounding shell geometries: 1. cylindrical, 2. truncated cone, and 3. a hybrid composition of the first two.

6.1.1

Truncated Cone Shell t U

A subdivision method can be used on a shell generated by an oblique slab whose orientation is chosen to follow the general orientation of the curve with respect t o the axis of rotation. This shell forms a truncated cone around the generatrix. It can be subdivided in a similar manner as the cylindrical shell. The truncated cone shells around the monotonic segments of the curve have shown t o produce tighter fitting bounding volumes of the curve. At the same time they are easier t o compute than the oriented bounding boxes employed by Kajiya. However, the ray intersection with a truncated cone shell requires about four times the number of computations necessary in the ray-cylinder intersection. For this reason in many practical instances it is often better t o employ a hybrid combination of cylindrical and truncated cone shells. 6.1.2

Figure 6. Hybrid combination of cylinders and truncated cones on each object during the pre-processing phase; the nodes in this structure are of two types: 1. MG-type (Monotonic Grouping) group the monotonic intervals together up to t h e root node; 2. MR-type (Monotonic Refinement) subdivide each monotonic interval into subintervals; these subintervals are also organized hierarchically within the tree. If the range is empty then there is no intersection point between the ray and the surface of revolution. Otherwise, there may be at least one and at most two intersection points. In the case that there is only one intersection point I , we compute the u-coordinate of I ,

Hybrid Shell

The combination of cylindrical shells with cone shells is justified by the fact that in many practical situations the orientation of the curve segments with respect t o the axis of rotation is not known in advance. In this case we can both reduce the ray intersection computations by using cylindrical shells where appropriate as well as provide for a tighter bounding shell for sharp changes in the orientation of the segments of the generatrix. In the case of hybrid compositions, the hierarchical tree structure will contain either a cylindrical shells or a truncated cone shell at any given node. However, the leaves are always associated with truncated cone shells for a tighter fit of the segment, Figure 6 . In practice, we observed that it is better t o start with a cylindrical shell at the root of the tree, in order to use a minimal amount of intersection computations.

+

and construct a range [ u I , u ~from ] U - 6 , for a very small real value 6. If two intersection point exist then we have a valid initial range [UI ,uz]. The routine SearchMGI(Eye, ray, 0.Tree.RootNode, range) searches for the monotonic interval using the initial range by descending recursively down the MGtype nodes in the tree. Once the MG-type nodes are exhausted down a path in the tree the search is passed to another routine S e a r c h M R I O . This continues the recursive interval search within the subdivisions of a monotonic interval.

6.2.1

6.2 Ray Tracing The main ray tracing loop has two parts: 1. a coordinate transformation of the ray t o the local coordinates of the object defined by the surface of revolution, and 2. a recursive search and intersection algorithm. 0bject.Tree is the MIBIT structure built

Searching for a subinterval within a monotonic interval

S e a r c h M R I ( E y e , Ray, Node, Range) is the last type of recursive search down the MIBIT structure associated with an object. We emphasize that this routine performs mostly range overlap tests, and not intersection computations, until either a leaf node is reached

2 19

Algorithm 6.3 1 proc S?archMRI(Eye, Ray, Node, Range) 3 2 Inen,. = NIL; 3 ;f Node = L E A F 4 I := W a n g l n t e r s e c t i o n A l g ( R a y , N o d e ) ; 5 rei,urn I ;

Algorithm 6.1 1 proc Ray'Ibace(Eye, Ray, ObjLst, depth) E 2 color = B A C K G R O U N D ; 3 I,,,, = m; 4 foreach Object 0 0 5 ray = T r a n s f o r m ( R a y ,0 . F r a m e ) ; 6 range = I n t e r s e c t C y l ( r a y , 0.Tree.RootNode);

6

Ff range

is not e m p t y I = S e a r c h M G I f E v e .r a u . O.Tree.RootNode, r a n g e ) ; if1 # N I L S d i s t ( E y e , I ) < d i s t ( E y e , Inear) color = 0.color; Inear = 1; o,.,, = 0 ;

7 8

~

9 10 11 12

13 14 15 16

A

17

I

i f depth < M A X D E P T H

22 23 24 25 26 27 28

A

R

fi

18 19 20

;f OuerlapTypeS(Range, Node.Range) n e w R a n g e = Range;

21

I L =: S e a r c h M R I ( E y e , R a y , Node.LeftChild, newRange) I R =: S e a r c h M R I ( E y e , R a y , Node.RightChild, new Range) ;f d i s t ( E y e , I L ) < d i s t ( E y e , I R ) I,.,, = I L ;

28 29 30

+

+

5

27

27

+

+

newRange = Shelllntersection(Ray, Node); S n e w R a n g e is empty I = NIL; return I ;

22 23 24 25 26

I,,,, <m I,.,, = ToWorldFrame(l,,,,, O,,,,.Frame); N = Normal(O,.,,, Incap); R = ReflectedRay(l,,,,, N); T = TransrraittedRay(l,,,,, N); Rcol = RayTrace(l,.,,, R,ObjLst, depth 1); Tcol = RayTrace(l,.,,, T ,O b j L s t , depth 1); color = color Rcol Tcol;

20 21

E Oi,erlapTypeZ(Range, Node.Range)

14 15 16

8

od -

18 29

I .

I

R ;f O u e r l a p T y p e l ( R a n g e ,Node.Range) I I= N I L ; return I ;

7 8 9 10 11 12 23

31

return color;

I,,.,,

.

= IR;

return I,,,,;

29

Figure 9. Searching for intersection ranges in the volume tree

Figure 7. Ray tracing routine

or an range overlap of type 2 occurs (ie a partial overlap of ranges:).

OverlapTypel(Range,Node.Range) is true if the parent Range and the current Node.Range are completely disjoint (ie no overlap);

Algorithm 6.2 2 proc SearchMGl(Eye, Ray, Node,

;f ouerlap(Range, Node.Range) ;f Node.Type = M G I L = SearchMGI(Eye, Ray, Node. L e f t c h i l d , Range); IF( = S e a r c h M G I ( E y e , R a y , Node.RightChild, R a n g e ) ; ;f d i s t ( E y e , I L ) < d i s t ( E y e , I R )

4 5 6 7

8 9 10

*

11

12 13

P

2 16

18 19

fi

20 23

/*ea?

= IL;

In.,,

= IR;

OvedapType2(Range,Node.Range) is true if there is a partial overlap between the parent Range and the current Node.Range; OvecdapType3(Range,N o o k R a n g e ) is true if the parent Range is completely enclosed within the current Node.Range. This means that the projection on the U-axis of the ray between the two intersection points Il and I2 is completely embedded withing the projection of the bounding shell

Node.Type = M R I,,,, = S e a r c h M R I ( E y e ,R a y , Node, Range);

!i

17

21 22

Range) E

= NIL;

I,.,,

2 3

at the current node. This ensures that the actual ray-surface intersection point lies in one of the 'child shells of the current bounding shell.

Error: invalid node t y p e

fi

.

r e t u r n I,.,

It can be shown that searches induced by the routines SeiuchMGI and SearchMGI have a complexity upper bound of O(1og m n ) , where m is the number of monotonic intervals, and n is the number of subintervals within each monotonic interval.

Figure 8. Searching the segment tree

220

Shell Range Total Percent

Percent

Type Search Time of Time of Nodes

No. of No. of Inter- Quad.

.FJ CY TC HY

YES 30.26 104.56% YES 27.84 122.34%

0.02% 0.02%

10.85m 11.43m 10.71m 11.32111

Table 2. Performance data for example 1 with monotonic interval subdivision

Fi

1 1 I

No. of No. of Inter- Quad. 1 (sec) lImprovedlTraversedlsectionsl Eqs. 0.02% 25.21m 94.43111 138.471 --y 88.37 56.69 o 0.03 o 31.10m 34.50111 94.97 45.80% 0.03% 31.94m 34.33m 87.99 57.37% 0.03% 30.70m 33.17m 89.03 55.53% 0.03% 29.45m 32.85111 0.03% 29.14m 31.52111 93.81 47.61% 87.72 57.82% 0.03% 28.671~1 31.14m

Shell Range Total

7

Percent

Percent

%pe .. Search Time of Time of Nodes

Experiments and Results

CY

We have implemented Kajiya’s classical algorithm. This was used as a base reference for experimenting with the following: monotonic interval partitioning vs non monotonic interval partitioning with or without range searching as given in SearchMRI algorithm. Within each experiment we tested different bounding volume shapes or combinations of bounding volumes. We note t h a t in the case of no monotonic subdivision we use a simple binary subdivision without any adaptive process. K J denotes Kajiya’s original method; CY denotes subdivision methods based on cylindrical bounding shells; TC denotes subdivision methods based on conical bounding shells; HY denotes subdivision methods based on a combination of both cylindrical and conical bounding shells. We note that in the CY subdivision cases all the nodes represent cylindrical bounding shells except the leaf nodes.

HY CY TC HY

NO

NO NO NO

YES YES YES

1

chairs, cups, bottles and bowls on the tables as well as patio rails supported by fourty round rail fixtures. This scene contains one hundred surfaces of revolution. Figure 10 shows this scene rendered without any reflection rays or shadows - it represents the first level raycasting. (2) Figure 11 shows this scene rendered with reflection rays and shadows computed t o four levels of reflection;

Figure 11, Example 2: Large scene with shadows and reflections

Figure I O . Example 1: Large scene without shadow and reflection

The images generated were 300 by 300 pixels. All the experiments were performed on Pentium 111 450MHz with 256MB RAM. In all the resulting tables

The two examples given below represent: (1) An outdoor restaurant patio with three round tables, six

221

The hybrid bounding volume approach with monotonic subdivision naturally adapts t o the shape of the surface of’revolution. We believe that this is one of the main feat,ures that contribute t o the optimal ray tracing of surfaces of revolution. However, there are many criteria that one can choose from in order t o minimize the bounding volume shell around the surface of revolution. We used a-very simple criteria based on an area factor of four on the cross sectional area of the bounding shells. We need t o investigate the trade-offs between such criteria and intersection computations.

Table 4. Performance data for example 2 with monotonic interval subdivision

References

we have the following columns: Shell Type indicates the bounding volume shape used; Range Search indicates whether a range search is performed or not; Percent Time Improved indicates the performance level with respect t o Kajiya’s method (KJ); Percent Nodes Tkaversed shows the number of nodes in the tree visited during the intersection search; Number of Intersections shows the number of bounding volume intersections in millions; in the K J case, this is the number of intersections with the box extent; Number of Quad Eqs shows the number of quadratic equations computed (in millions) when an actual ray intersection is computed. The reference row is Kajiya’s method (KJ). The time taken by this method is used as a base reference in the Performance column for all the other methods. We note that in general both the cylindrical bounding shells and the hybrid case (HY) perform better than truncated cones alone. This is also due to the fact that most of the objects are mostly cylindrical in shape and the hybrid case tends t o adapt t o the cylindrical bounding volumes.

8

[l] D. Ekdard. Strip trees: A hierarchical representation for curves. Communications of the ACM, 24:310-321, May 1981. [2] R. Cook. Stochastic sampling in computer graphics. ACM fiansactions on Graphics, 5(1):51-72, January 1986. [3] S. I. D and Caspary. Data structures and the time complexity of ray tracing splines. The Visual Computer, 3(x):201-213, July 1987. [4] A. Glassner, editor. An Introduction to Ray T h i n g . Academic Press, 1989. [5] J. E:. Goodman and J. O’Rourke. Handbook of Dis-

crete and Computational Geometry. CRC Press, Boca RAtion, New York, July 1997. [6] P. IIanrahan. Ray tracing algebraic surfaces. Computer Graphics, 17(3):83-90, July 1983. [7] J. Jia. Accelerating algorithm on ray tracing revolution surfaces. In Master Thesis of Jilin University, pa es 19-49, July 1991. [8] J. I Cajiya. New techniques for ray tracing procedurally defined objects. IEEE Computer Graphics and Ayfjlications, 2(3):161-181, July 1983. [9] J. kajiya and B. VonHerzen. Ray tracing volume densities. Computer Graphics, 18(3):165-174, July 1984. [lo] T. L. Kay and J. T. Kajiya. Ray tracing complex scenes. Computer Graphics, 20(4):269-278, 1986. [ll] M. Lee, R. Redner, and S. Uselton. Statistically optimized sampling for distributed ray tracing. Computer Graphics, 19(3):61-68, July 1985. [12] J . S. B. Mitchell, D. M. Mount, and S. Suri. Querysensitive ray shooting. Intemational Joumal of Computational Geometry and Applications, 7(4):317-347, July 1997. [13] M. A. J. Sweeney and R. H. Bartels. Ray tracing freeform b-spline surfaces. IEEE Computer Graphics and Ap,plications, 6(2):41-49, 2 1986. [14] D. L. Toth. On ray tracing parametric surface. Compuler Graphics, 19(3):171-179, July 1985. [15] L. !3. Wang. Removing hidden lines and rendering patterns on rotating surfaces. Chinese Computer Joumal,

Conclusions

The main observations drawn from all these experiments are: 1. The hybrid method tends t o follow closely the best bounding volume approximation for a given object. That is, if the object is mostly cylindrical than the hybrid case will perform as well or better than using just a cylindrical bounding box. 2. The monotonic subdivision with the MIBIT data structure and an efficient range search performs significantly better up t o 193%relative t o Kajiya’s method, or approximately three times as fast.

22(3), 1989. [16] J. .J. V. Wijk. Ray tracing objects defined by sweeping

plannar cubic splines. ACM Transaction on Graphics, 3(3):223-237, July 1984. (171 - - J. ,J. V. Wijk. Ray tracing objects defined by sweeping s here. Co-mputer and Giaphics, 9(3), 1985. wy vill, T. L. Kunii, and Y . Shirai. Space division [18] for ray tracing in csg. IEEE Computer Graphics and Applications, 6(3):28-34, April 1986.

Ray-object intersection search in these problems may also be very much dependent on the relative orientation between the ray and the object’s axis. This remains t o be investigated.

2.

222