Photon mapping on programmable gr...
Graphics Hardware (2003) M. Doggett, W. Heidrich, W. Mark, A. Schilling (Editors) Photon Mapping on Programmable Graphics Hardware Timothy J. Purcell1, Craig Donner2, Mike Cammarano1, Henrik Wann Jensen2 and Pat Hanrahan1 1 Stanford University 2 University of California, San Diego Abstract We present a modified photon mapping algorithm capable of running entirely on GPUs. Our implementation uses breadth-first photon tracing to distribute photons using the GPU. The photons are stored in a grid-based photon map that is constructed directly on the graphics hardware using one of two methods: the first method is a multipass technique that uses fragment programs to directly sort the photons into a compact grid. The second method uses a single rendering pass combining a vertex program and the stencil buffer to route photons to their respective grid cells, producing an approximate photon map. We also present an efficient method for locating the nearest photons in the grid, which makes it possible to compute an estimate of the radiance at any surface location in the scene. Finally, we describe a breadth-first stochastic ray tracer that uses the photon map to simulate full global illumination directly on the graphics hardware. Our implementation demonstrates that current graphics hardware is capable of fully simulating global illumination with progressive, interactive feedback to the user. Categories and Subject Descriptors (according to ACM CCS): I.3.7 [Computer Graphics]: Three-Dimensional Graphics and Realism Keywords: Programmable Graphics Hardware, Global Illumination, Photon Mapping 1. Introduction Global illumination is essential for realistic image synthesis in general environments. Effects such as shadows, caustics, and indirect illumination are important visual cues that add to the perceived realism of a rendered scene. Global illumination algorithms have a long history in computer graphics from early work based on radiosity8 and Monte Carlo ray tracing12, to more recent algorithms such as photon mapping10. Photon mapping is one of the more widely used algorithms, since it is very practical and capable of computing a full global illumination solution efficiently. It is a two-pass technique in which the first pass consists of tracing photons through the scene and recording their in- teraction with the elements in the scene in a data structure, the photon map. This photon map is used during the second pass, the rendering pass, to estimate diffuse indirect illumi- nation as well as caustics. The illumination at a given point is estimated based on statistics, such as the density, of the nearest photons located in the photon map. Global illumination algorithms such as photon mapping have traditionally relied on sophisticated software imple- mentations and offline rendering. Using graphics processors (GPUs) for computing a global illumination solution has not previously been possible due to the lack of floating point capability, as well as insufficient programmability. This has changed with the most recent generation of programmable graphics hardware such as the ATI Radeon 9800 Pro1 and the NVIDIA GeForce FX 5900 Ultra19. The programming model for these GPUs is still somewhat limited, mainly due to the lack of random access writes. This prevents efficient construction of most data structures and makes many com- c The Eurographics Association 2003.
Purcell et al. / Photon Mapping on Programmable Graphics Hardware mon algorithms such as sorting difficult to implement effi- ciently. Nonetheless, several researchers have harnessed the computational power of programmable GPUs to perform computations previously run in software4, 5, 9, 14, 15, 21. Simi- larly, we are interested in using GPUs to simulate global il- lumination using photon mapping. Previous research on graphics hardware has explored the idea of simulating global illumination. Ma et al.16 proposed a technique for approximate nearest neighbor search in the photon map on a GPU using a block hashing scheme. Their scheme is optimized to reduce bandwidth on the hardware, but it requires processing by the CPU to build the data struc- ture. Carr et al.5 and Purcell et al.21 used the GPU to speed up ray tracing, and they also simulated global illumination using path tracing. Unfortunately, path tracing takes a sig- nificant number of sample rays to converge and even with the use of GPUs it remains a very slow algorithm. The idea of speeding up global illumination to achieve interactive frame rates has been explored by several re- searchers in the last few years. Parker et al.20 demonstrated how ray tracing, and to some extent path tracing, could be made interactive on a 32 processor shared memory SGI ma- chine. This concept was later extended to Linux clusters by Wald et al.24. Recently, Wald et al.23 also demonstrated that photon mapping combined with instant radiosity could be used to simulate global illumination at interactive rates on a Linux cluster. They achieve interactive speeds by bias- ing the algorithm and by introducing a number of limita- tions such as a highly optimized photon map data-structure, a hashed grid. By choosing a fixed search radius apriori, they set the grid resolution so that all neighbor queries sim- ply need to examine the 8 nearest grid cells. However, this sacrifices one of the major advantages of the k-nearest neigh- bor search technique, the ability to adapt to varying photon density across the scene. By adapting the search radius to the local photon density, Jensen���s photon map can maintain a user-controllable trade off between noise (caused by too small a radius yielding an insufficient number of photons) and blur (caused by too large a search radius) in the recon- structed estimate. In this paper we present a modified photon mapping algo- rithm that runs entirely on the GPU. We have changed the data structure for the photon map to a uniform grid, which can be constructed directly on the hardware. In addition, we have implemented a variant of Elias���s algorithm6 to search the grid for the k-nearest neighbors of a sample point (kNN- grid). This is done by incrementally expanding the search ra- dius and examining sets of grid cells concentrically about the query point. For rendering, we have implemented a stochas- tic ray tracer, based on a fragment program ray tracer like that introduced by Purcell et al.21. We use recursive ray trac- ing for specular reflection and refraction26 and distributed tracing of shadow rays to resolve soft shadows from area lights7. Finally, our ray tracer uses the kNN-grid photon map to compute effects such as indirect illumination and caustics. Our implementation demonstrates that current graphics hardware is capable of fully simulating global illumination with progressive and even interactive feedback to the user. The contribution of this paper is a method for obtaining a complete global illumination solution on the GPU using photon maps. To compute various aspects of the global il- lumination solution, we introduce a number of GPU based algorithms for sorting, routing, and searching. 2. Photon Mapping on the GPU The following sections present our implementation of pho- ton mapping on the GPU. Section 2.1 briefly describes the tracing of photons into the scene. Section 2.2 describes two different techniques for building the photon map data struc- tures on the GPU. Section 2.3 describes how we compute a radiance estimate from these structures using an incremen- tal k-nearest neighbor search. Finally, section 2.4 briefly de- scribes how we render the final image. A flow diagram for our system is found in figure 1. Trace Photons Build Photon Map Render Image Ray Trace Scene Compute Radiance Estimate Compute Lighting Figure 1: System flow for our rendering system. Photon trac- ing and photon map construction only occur when geometry or lighting changes. Ray tracing and radiance estimates oc- cur at every frame. Most of our algorithms use fragment programs to simu- late a SIMD array of processors. For every processing pass, we draw screen sized quad into a floating point pbuffer, ef- fectively running an identical fragment program at every pixel in the 2D buffer. This setup is common among sev- eral systems treating the GPU as a computation engine4, 5, 21. When computing the radiance estimate, however, we tile the screen with large points, enabling us to terminate certain tiles sooner than other tiles. The benefits of tiling are examined further in section 3. 2.1. Photon Tracing Before a photon map can be built, photons must be emitted into the scene. The process of tracing eye rays and tracing photons from a light source is very similar. The most impor- tant difference is that at each surface interaction, a photon is stored and another is emitted. Much like tracing reflec- tion rays, this takes several rendering passes to propagate the photons through several bounces. Each bounce of pho- tons is rendered into a non-overlapping portion, or frame, c The Eurographics Association 2003.