1Beijing Engineering Research Center of Mixed Reality and Advanced Display, School of Optics and Photonics, Beijing Institute of Technology, Beijing 100081, China
2MOE Key Laboratory of Optoelectronic Imaging Technology and Systems, Beijing Institute of Technology, Beijing 100081, China
We implement Monte Carlo-based parallel ray tracing to achieve quick irradiance evaluation for freeform lenses with non-uniform rational B-splines (NURBS) surfaces. We employ the inverse transform sampling method to sample rays uniformly from the Lambertian light source and adopt the analytical form of the B-spline basis function to achieve fast surface interpolation. When performing parallel calculations for the intersections between the rays and the NURBS surfaces, we propose a parameter transformation method to avoid the parameters escaping from the defined range in the iteration process. Simulation results of two complex picture-generating freeform lenses show that our method is fast and effective.
Freeform optics, which refers to refractive or reflective optical elements with freeform surfaces, is considered a revolution in modern optics[1]. Freeform surfaces are those surfaces that do not have rotational or translational symmetries[2]. Compared with traditional optical surfaces, including spherical, aspherical, and cylindrical surfaces, freeform surfaces offer much greater design freedom, allowing optical systems to achieve previously unimaginable imaging[3–5], illumination[6,7], and laser beam shaping performances[8]. The performance evaluation of these freeform optical systems is highly dependent on the light transport simulation from source to target. An efficient light transport computation is crucial in finding the optimal freeform optical systems through optimization techniques.
Ray tracing is currently the most popular and powerful technique for light transport simulation. The main operation of ray tracing is to acquire the intersection points between light rays and surfaces. The computation efficiency of this process is strongly influenced by the surface complexities. Freeform surfaces for imaging can be conveniently described by polynomials, e.g., polynomials[3]. However, plenty of illumination problems, e.g., picture-generating freeform lens design[6], are solved numerically. The resulting freeform surfaces, which contain many local curvature features, are hard to describe by using polynomial expansions. Time and memory consumption of ray tracing could increase rapidly as the surface representation becomes more and more complex. Generally, iterative methods have to be employed to obtain the intersection points, which heavily rely on the initial solutions. The meshing method is commonly used to find appropriate initial solutions[9–11]. In this method, the grids are checked one by one to judge if the intersection occurs on the current grid. However, this method becomes less efficient when the required number of mesh grids is large.
Optical surfaces that are highly freeform and contain both global and local structures can be represented by B-splines, especially by its subset, non-uniform rational B-splines (NURBS)[12,13]. However, it is not easy to determine the intersection points, even their initial approximations, between the rays and the NURBS surface with high efficiency. The clipping method can be employed to accelerate the ray-tracing process of NURBS surfaces[14,15]. This method adaptively divides the surface parameters into uniform parts on the 2D parameter space to find the region where the light ray intersects with the surface. Then, the region is gradually subdivided to determine an appropriate initial solution. However, this method suffers from reporting wrong intersections because the sampling points on the surface are not uniformly distributed when parameters are uniformly sampled[15,16].
Sign up for Chinese Optics Letters TOC. Get the latest issue of Chinese Optics Letters delivered right to you!Sign up now
Aside from the intersection problem, another important issue is the way of implementing ray tracing. Although some deterministic methods have been discussed, it is restricted in many applications[17]. In the evaluation and optimization process, the Monte Carlo (MC) ray-tracing method gains wider acceptance as the gold standard for calculating light transport through optical systems[18–20]. MC ray tracing randomly samples light rays on a light source with a specific probability and traces the light path through the optical system by Snell’s laws. Then, it accumulates the light energy transmitted to the receiver to calculate the irradiance distribution.
Some commercial softwares can perform MC ray tracing of freeform optical elements and systems, but the related algorithms are rarely discussed publicly. Many self-developed ray-tracing programs are successfully applied to artificial image simulation[21–27], aberration analysis[28–32], and optical inspection[33–36]. Some entire ray-tracing pipelines for nonimaging systems have been described in detail[11,20]. Most of the current MC ray-tracing algorithms trace rays one by one, based on the same law and formula.
The ray-tracing process could be accelerated if plenty of rays are traced simultaneously. However, it is a high-dimensional problem that the parallel intersection process requires simultaneous acquisition of the initial solutions of all current rays. The traditional way of obtaining an initial solution to the intersection problem of a single ray and the freeform surface requires simultaneous computation on mesh grids, which is not suitable for parallel ray tracing. In addition, when the initial solution is not accurate enough, the parameters of the intersection could easily escape from the defined range as the iteration progresses, resulting in many calculation errors.
We implement MC parallel ray tracing (PRT) for freeform illumination lenses with NURBS surfaces to realize a fast irradiance evaluation. We achieve uniform sampling by inverse transform sampling and fast surface interpolation by adopting the analytical form of the B-spline basis function. We propose a parameter transform method to reduce the accuracy requirement of the initial solution during the intersection process using Newton’s method, which could improve the percentage of successfully traced light rays by parallel computation. This fast MC simulation program can facilitate the evaluation and optimization of freeform lenses. Section 2 describes in detail the parallel ray-tracing method for freeform NURBS surfaces. Section 3 gives two examples to demonstrate the effectiveness of the proposed method.
2. Methods
The purpose of the ray-tracing process is to trace the changes in the spatial parameters and orientation parameters , which uniquely characterize a light ray in a three-dimensional space. form a four-dimensional parameter space, which degenerates to a two-dimensional one for a special case when all the rays are emitted from a point light source. Figure 1 illustrates the procedures of our parallel ray-tracing algorithm. After defining the optical system parameters, we sample the light source randomly in both spatial locations and orientations, generating a random set of rays. We then implement MC ray propagation from the source, through the freeform lenses, to the receiver. The difficulty arises in simultaneously determining all the parameters for the current set of rays transporting through a complex freeform surface. In this decisive and important step, we propose a parameter transformation method to reduce the ray-surface intersection errors in the iterative process of Newton’s method. Finally, we count the number of rays that reach different positions of the receiver to determine the irradiance distribution. The three steps are described in detail in the following section.
Figure 1.Flow chart of our parallel ray-tracing algorithm.
The light source is required to be sampled randomly in both spatial locations and orientations. Different sampling probability density functions should ensure that is proportional to , where is the radiance distribution of the source, denotes the weights of the sampled rays, and denotes the angles from the source surface normal to the sampled rays. The initial values of can be set as 1, and then is proportional to the intensity distribution of the light source. However, this can add computation complexity when is not a constant.
Here, we first sample the position coordinates and solid angle of the light source uniformly and then assign the initial weights proportional to . In this way, there is an equivalent relation between the radiance distribution and the weights of the sampled light rays,
Herein, denotes a small area on the surface around , and denotes a small solid angle around . is the mathematical expectation of the summed weight of the light rays inside the small space , and denotes the number of rays inside the small space.
In a spherical coordinate system, can be replaced with the zenith angle and the azimuth angle , as shown in Fig. 2(a). Note that the light rays sampled uniformly with and are not uniformly distributed in space[19]. Since the magnitude of the small solid angle around is proportional to , uniform sampling of the solid angle should guarantee that the probability is proportional to and .
Figure 2.(a) Zenith angle θ and azimuth angle φ of a randomly sampled ray. (b) The illustration of two different sampling strategies, θ ∼ sin θ and θ ∼ U (0, 0.5π), where φ is uniformly sampled. (c) The distribution of the sampling points with azimuth and zenith angles corresponding to the uniform spatial sampling.
We employ the inverse transform sampling method[37] to obtain random variables with arbitrary probability distribution , where . This method first calculates the cumulative probability distribution function according to the required probability distribution function . A uniformly distributed random variable can be generated. Finally, the random variable with probability distribution can be obtained as . For the sampling of the zenith angle here, we first obtain a random uniformly distributed variable between 0 and 1; then the probability distribution function is a sine function. Thus, uniform sampling of random rays in space can be generated based on setting the probability distribution functions as , .
Figures 2(b) and 2(c) illustrate the ray distributions of a Lambertian light source sampled in two strategies: and , where is uniformly sampled for each strategy. The pseudo-code of the random rays sampling process is shown in Algorithm 1.
Number of rays
107
106
108
107
107
107
107
Source size
(0.001,0.001)
(0.001,0.001)
(0.001,0.001)
(0.001,0.001)
(0.001,0.001)
(0.001,2.0)
(2.0,2.0)
Number of bins
(128,128)
(128,128)
(128,128)
(64,64)
(256,256)
(128,128)
(128,128)
Time cost (s)
11.16
1.30
112.86
11.13
11.12
11.11
11.17
Intersection precision (mm)
max
2.80 × 10−4
2.40 × 10−4
2.83 × 10−4
2.75 × 10−4
2.70 × 10−4
2.72 × 10−4
2.64 × 10−4
mean
5.33 × 10−8
5.31 × 10−8
5.35 × 10−8
5.33 × 10−8
5.32 × 10−8
5.34 × 10−8
5.34 × 10−8
Success rate
0.99978
0.99978
0.99973
0.99978
0.99978
0.99965
0.99945
Table 1. Performances of the Proposed PRT Algorithm Evaluated by the Time Consumption, the Intersection Precision, and the Success Rate τ
2.2. Light propagation through freeform optical surfaces
After generating a sequence of random rays from the light source, we trace the rays propagating through the freeform optical surfaces represented with NURBS. The key operation is the determination of the intersection points between rays and surfaces. Thus, we accelerate the intersection process by modifying the surface interpolation strategy and introducing a parameter transformation method. After obtaining the intersection points, we use Snell’s law in vector form to calculate the outgoing ray vectors.
2.2.1. Intersection acquisition on optical surface
An NURBS surface is obtained as the tensor product of two NURBS curves parameterized by two parameters and , where and lie in , denotes the control point, is the weight of , and and are the basis functions of the B-splines of degree and in the and directions, respectively. The basis function is defined by the De Boor Cox recursion formula[12],
Herein, is the selected node which divides into segments. We employ the quasi-uniform nodes here, which can simplify the formula for the B-spline basis functions.
The computation volume required for interpolation increases exponentially with the number of control points and the interpolation degree. The major reason is that the recursive method repeatedly computes the formula with a large storage of accumulative data and no zero only when . These unnecessary calculations slow down the intersection point-finding process. Abert et al. transferred the computationally expensive recursion into single instruction multiple-data (SIMD) suitable form to reduce the time cost of executed commands[13]. Jester et al. proposed the B-spline quasi-interpolation scheme, which improves the computational speed of B-spline surfaces within a certain error range[38]. To improve the speed of the interpolation process, we employ the analytical form of the B-spline basis function of degree 2[13]. In addition, only the control points whose corresponding basis functions are not 0 are considered in the interpolation process to avoid meaningless operations. Such a strategy can promote calculation efficiency greatly when the control point number is much larger than the interpolation order.
After specifying the interpolation strategy, let us now turn to the calculation of the intersection between the rays and the NURBS surface. Suppose we have a ray parameterized as , where is the starting point, and denotes the ray direction. The intersection can be formulated by the following equation: where denotes a point on the NURBS surface. After expressing the ray direction with and , Eq. (4) can be rewritten as
We rotate and around the -axis and -axis, respectively, so that the new -axis coincides with the direction of the light ray. This way can simplify the intersection-solving process[39]. The transformation matrices describing the rotations are where describes the rotation around the -axis, and describes the rotation around the -axis.
After applying the rotation matrices to Eq. (5), we obtain
We take the first two equations, which could be represented as . Then, the parameters of the intersection point on the surface can be solved by using Newton’s method. Newton’s iteration step is given by where is the approximate solution of the th iteration, and J is the Jacobian matrix,
Newton’s method needs a good initial estimate. Most of the methods divide the surface into many triangular meshes to find a suitable initial solution. If the meshing is sufficiently detailed, then the initial solution could lead to a good iteration result. Such a strategy is not suitable for parallel computation here.
A slight deviation from the exact initial solution could cause the value of or to exceed the range of [0,1], resulting in surface interpolation errors. We adopt a parameter transformation method to solve this problem. In this method, a new pair of parameters, , are employed to replace , and their relationships can be described as
The parameter transformation has the following characteristics:
Such a transformation can avoid the values of exceeding [0, 1]. The intersection equations now become . The new Jacobian matrix J in Newton’s method can be acquired based on the chain rule
Herein, can be or . We obtain the initial solution using a coarse mesh on the surface. For the th iteration, can be calculated from by the inverse operation of Eq. (10). The Newton iteration formula Eq. (8) is changed into
Such a parameter transformation could reduce the accuracy requirement of the initial solution to the iterative computation. Thus, we can adopt surface points with a relatively coarse density as the initial solution, which can save a lot of time.
2.2.2. Refraction on the optical surface
Once we obtain the intersection points between the rays and the surface, we determine the refraction directions of the outgoing rays based on Snell’s law. As illustrated in Fig. 3, denotes the unit incident ray vectors, denotes the unit outgoing ray vectors, denotes the unit normal vectors to the intersection points on the surface, and and denote the refractive indices of the incident and exit media. Then, can be obtained based on Snell’s law in vector form,
Fresnel loss occurs when a light ray passes through a refractive optical surface. The reflectivities and for s-polarized light and p-polarized light, respectively, are written as where and denote the incident and refracted angles, respectively. The reflectances and for s-polarized light and p-polarized light, respectively, can be obtained as . The transmittances and for s-polarized light and p-polarized light, respectively, can be simply obtained as and . For natural light or typical LED light, the total transmittance can be taken as the average of and . We adjust the weights of the light rays according to the transmittance during ray tracing.
The pseudo-code for simulating the light transport through a freeform surface is provided in Algorithm 2. Herein, we consider ray tracing as successful when the cosine distance is less than the allowed error , where Q is the found intersection point.
Input: incident ray parameters , surface control points , refractive indices
Output: outgoing ray parameters
1: function TRACE()
2:
3:
4: get surface normal vectors
5: get refraction directions by Eq. (14)
6: get reflectances and based on Eq. (15)
7:
8:
9: return
10: end function
11: function INTER() intersection acquisition
12: generate rough mesh grids
13:
14:
15:
16:
17: initial solution
18: ,
19: whiledo is the allowed error
20:
21:
22: get Jacobian matrix J by Eqs. (9) and (12)
23: get by Eq. (13)
24:
25:
26: end while
27: return
28: end function
29: function NURBS() surface interpolation
30: generate quasi-uniform node vectors and using shape ()
31: get based on Eq. (3)
32: get interpolation points and the partial derivatives , while based on Eq. (2)
33: return
34: end function
Table 2. Light transport simulation through a freeform NURBS surface. During the parallel ray-tracing process, we specify a fixed number of iterations in the INTER( ) function and record the number of rays that satisfy
After finishing the ray tracing through the entrance surface, the ray tracing through the second surface can be implemented based on the same procedure, where the intersection points on the entrance surface are set as the starting points of the next ray tracing. Such a process is repeated until the light rays hit the receiver.
2.3. Energy statistics on the receiver
After finishing the ray tracing through all the freeform surfaces and determining the intersection points between the rays and the target plane, we count the number of rays for each small grid of the discretized receiver.
Suppose that the total radiant power emitted from the light source is . The weight of the th ray is denoted as , and the number of rays is . The radiant power of a ray with the unit weight can be acquired by
Suppose that the range of the receiver is , which is discretized into cells. The area of each cell can be obtained as
The energy weight of the th light ray that hits the receiver is changed into . The total number of rays of the th cell is . The irradiance value of the th cell, , , can be acquired by
The pseudo-code of the energy statistic process and the arithmetic flow of our PRT are shown in Algorithm 3. Note that the more the total traced rays, the higher the signal-to-noise ratio (SNR) of the simulated irradiance distribution. A discussion of the appropriate number of rays to be traced for a certain setting can be found in Ref. [40].
Input: light source size , total energy , number of rays , control points of the two surfaces, refractive indices of air and lens, -coordinate of receiver, range of the receiver, number of cells
Output: the irradiance distribution on the receiver
1: ,
2: for to do
3:
4:
5:
6:
7: decomposition
8:
9:
10: end for
11:
12:
13: function STATIC()
14:
15: for to do
16: for to do
17:
18: sum of the rays on the th cell
19:
20: end for
21: end for
22: return
23: end function
Table 3. Pseudo-code for PRT. We use the GPU to trace batches of light rays simultaneously. The function means generating an zeros matrix
To demonstrate the effectiveness of our method, we implement irradiance evaluation of the picture-generating freeform lenses designed with the iterative wavefront tailoring (IWT) method[41]. As shown in Fig. 4, the light rays emitted from a light source propagate through the entrance and exit optical surfaces and then generate a complex irradiance distribution of the picture type at the receiver. The entrance surface can be a spherical, aspherical, or freeform surface, and the exit surface is a freeform one. Note that the freeform surface profiles of the picture-generating freeform lenses can be very complex, which is difficult to be described by conventional polynomials, e.g., or Zernike polynomials.
Figure 4.Schematic of the ray tracing from the source, through the entrance and exit surfaces of the freeform lens, to the target, generating a complex irradiance pattern.
The ray tracing performances are evaluated by the time consumption, the intersection precision, and the success rate. The intersection precision is measured by the maximum or average value of the Euclidean distances from the calculated intersection points on the exit surface to the light rays. The success rate is defined as the ratio of the number of successfully traced rays to the total number of traced rays.
Our computer is equipped with an Intel i9-12900 k CPU with x86-64 architecture and an NVIDIA RTX3090 GPU with 24 GB video memory and NVIDIA Ampere architecture. The programming language is Python 3.11. We use the GPU to trace batches of light rays simultaneously and the CPU to control the calculation flow. We use the CuPy package of Python for surface modeling, intersection solving, and other parallel scientific calculations. The computing time is mainly affected by the GPU performance.
The first example is the ray tracing of a spherical-freeform lens as shown in Fig. 5(a). The refractive index of the lens is 1.4932. This lens is aimed at converting the light distribution of an LED source into a irradiance distribution at , forming the letters “BIT”. The maximum dimensions of the lens along the , , and directions are 16.97 mm, 16.28 mm, and 12.01 mm, respectively. It can be seen from Fig. 5(b) that the freeform exit surface has complex local features which are directly related to the target irradiance pattern. The entrance surface is 3D grids sampled from a semi-sphere of 5 mm radius, which is also expressed with NURBS. The complex exit freeform surface is described by control points. We employ a uniform filter for the simulated irradiance distribution to decrease the noise of the MC method. Figure 6 shows the simulated irradiance distributions of our algorithm under different settings of the number of light rays , the number of receiver cells , and the source sizes. Table 1 gives the corresponding time consumption, precision of the solved intersections, and the success rates.
Figure 5.Illustration of (a) the spherical-freeform lens and an extended light source and (b) the continuous change of the freeform exit surface.
Figure 6.Simulated irradiance distributions of the first example under different settings of the number of rays, the number of cells, and the source size. Each simulated irradiance distribution is in the range of {(x,y) | −1000 mm < x <1000 mm, −1000 mm < y < 1000 mm} and filtered by a 3 × 3 uniform mask.
As shown in Table 1, for each case of the first example, the success rate is higher than 99.9%. could be reduced to below about 96% without using the parameter transformation method. In addition, the parameter transformation method improves the convergence of Newton’s method for solving the intersection points. The iterative solutions would not jump out of the allowed range of the parameters in the early stage of the iterative process. However, the intersection calculation errors can rise rapidly toward the edge of the surface ( or 1) since the derivatives of the transformation functions tend to 0. This problem could be avoided by extending the surface so that the active area is bounded away from the edge of the surface.
The second example is about the ray tracing of a more complex double-freeform lens with the maximum dimensions of [see Fig. 7(a)], whose refractive index is also 1.4932. Each of the freeform surfaces contains control points. This freeform lens aims at generating a portrait of Johann Carl Friedrich Gauss[42] with the size of at from a point-like source whose size is . We perform the PRT using rays. The simulated irradiance distribution is shown in Fig. 7(b). The maximum and average values of the distances from the calculated intersection points on the exit surface to the light rays are and , respectively. Our program only takes to perform the simulation, and is about 99.951%.
Figure 7.The second simulation example. (a) The double-freeform lens with a point-like source and (b) its simulation result.
We analyze the time complexity of our PRT program for the first example with respect to the number of rays, the number of receiver cells, the size of the light source, and the number of control points. We use the control variable method to practically test the time consumption of the program. The results are presented in Fig. 8. The time complexity for the number of rays is . Because is much larger than the number of GPU cores, parallel computing is still done in batches on the hardware. As shown in Fig. 8(a), the simulation time increases linearly as increases. For the number of receiver cells, the total time complexity is approximately . As shown in Fig. 8(b), as increases, the simulation time remains almost unchanged. The reason is that most of the time is spent on the intersection-seeking process. Theoretically, the time complexity of the ray energy statistical process is . However, since is typically much larger than to ensure low-level Monte Carlo noise, the impact of on the overall simulation time is negligible. The total time complexity for the source size is about , as illustrated in Fig. 8(c). The source size only affects the range of the starting points of the randomly sampled rays. We adopt the 2-order analytic form of the NURBS basis functions, which can avoid many recursive operations in base function modeling. Thus, the total time complexity for the control points of the lens surfaces is , as demonstrated in Fig. 8(d).
Figure 8.Variations of the runtime with (a) the number of rays, (b) the number of receiver cells, (c) the source size, and (d) the number of control points (of each surface) for the first example.
We have proposed a PRT method for freeform lenses with complex NURBS surfaces. In this method, we employ the inverse transform sampling strategy to uniformly sample rays in space. We also adopt the analytical form of the B-spline basis function of 2 degrees to achieve a fast surface interpolation. More importantly, we proposed a parameter transform method to reduce the initial solution requirement of Newton’s method for solving intersections, which thus increases the success rate of parallel ray tracing. Two examples verify that the proposed PRT method is efficient and effective for quick irradiance evaluations of complex freeform irradiance tailoring lenses.
The proposed PRT method is also applicable to freeform surfaces with other expressions, including polynomials, Zernike polynomials, and radial base functions. Our method can help designers quickly evaluate their design results, especially for freeform surfaces with high degrees of freedom. As a relatively fast irradiance evaluation technique, our method can also be applied to the optimal design of freeform lenses. The proposed method is currently restricted to those cases in which a single light ray does not have multiple intersections with a surface. However, such a restriction is fulfilled by most of the freeform lens designs for illumination and beam-shaping applications. Future work may include the development of non-sequential PRT algorithms and the application of freeform illumination lens design using the automatic differentiation technique in the framework of MindSpore.
[15] A. Efremov, V. Havran, H.-P. Seidel. Robust and numerically stable Bézier clipping method for ray tracing NURBS surfaces. Proceedings of the 21st Spring Conference on Computer Graphics, 127(2005).
[24] J. Hanika. Spectral light transport simulation using a precision-based ray tracing architecture(2011).
[25] D. S.-M. Liu, C.-W. Hsu. Ray-tracing based interactive camera simulation. MVA2013 IAPR International Conference on Machine Vision Applications, 383(2013).