• No results found

Photon Mapping Acceleration

2.4 Acceleration Structures

2.4.2 Photon Mapping Acceleration

The structures used to accelerate the photon search in Photon Mapping- based approaches have quite a different task. Given a point in space, their main goal for them is to return either the closest k points stored in the structure (k-NN search) or to return all points within a radius r from the query point (range query). While these acceleration structures are used for quite different tasks, the basic structures are similar. Classic Photon Mapping [Jensen 2001] uses a kd-tree to implement its k-NN search, while Progressive Photon Mapping [Hachisuka et al. 2008] typically uses a grid for its range queries with mostly uniform radii.

Kd-Tree. There are two different basic approaches to building a point based kd-tree. Median split (Figure2.17a) aims at the most shallow struc- ture possible. All photons of a node are sorted along the axis of the node’s longest dimension and the node is split through the median photon. These photons are stored with the plane, i.e., it is inner nodes that store photons, leaves of the tree are actually empty (and thus not explicitly stored). In our example, the final level of nodes is marked by gray split lines.

(a) Median split (b) Sliding midpoint

Figure 2.17: 2D point kd-tree. Two different builds of point kd-tree. In the median split approach (top), the split plane always goes through the middle (median) photon of the node, and the photon is stored with the plane. The sliding midpoint approach (bottom) splits nodes in the geometric center. When one of the child nodes would be empty, the split plane slides to put at least one photon into each child.

The goal of sliding midpoint (Figure 2.17b) is to have nodes as cube- like as possible, even at the cost of a deeper acceleration structure. The motivation is that some types of queries (e.g., approximate k-NN queries) tend to perform faster [Maneewongvatana and Mount 1999]. The build algorithm also splits nodes along the longest axis, but in the geometrical center, irrespective of the photon distribution. The only exception is that one of the children would have zero photons, the split plane is slid so it would have at least one photon. This situation is denoted by the red line in our example. Queries into both structures differ in details (e.g., based on where the photons are stored), but the same general principles apply to both.

Executing a range query on either type of structure is straightforward. The structure is traversed from the top, for each child node we determine whether its content can or cannot be within the required range and then either process it or discard it. All photons in the processed nodes are exam- ined and if they are within the query distance they are put into the output set.

The k-NN queries are slightly more complicated. The process works in three stages and uses a priority queue over photons, sorted by their distance from the query point. In the first stage, the query point is traversed down the tree into a leaf that would contain it, if it was a photon. All nodes that were not visited during the traversal, i.e., child nodes that did not contain the query point are put onto a stack. The photon contained in the leaf node is put into the priority queue. In the second stage the previously unvisited nodes from the stack are traversed. When a choice can be made which child to visit, the child closer to the query point is visited. All photons encountered in this stage are also put into the queue, until the queue contains k photons. After that, only nodes that are closer than the farthest photon

in the queue are visited, as only these can contain photons that are nearest than our current set. After all valid nodes have been visited, the queue contains the k nearest photons.

Uniform (Hash) Grid. Under certain conditions, uniform grids can efficiently accelerate range queries, with build times that are significantly faster than for the kd-tree. When the photons are stored within a grid with cubic cells of size a3 and the range query has a diameter 2r ≤ a, the query can be limited to only 8 cells.

Figure 2.18: 2D point Uniform Grid. Uniform grids can efficiently execute range queries when the ra- dius is equal or slightly less then half the length of a cell side. Such queries (green) require examining photons in only 8 cells (4 cell in 2D case). Queries with significantly smaller ra- dius (red) still return correct result, but the acceleration is significantly less efficient. If the radius is signifi- cantly

The 2D example in Figure 2.18 (green query) gives the intuition why. For all queries with radius r ≤ a, valid photons can obviously lie only in the direct neigh- borhood of the cell containing the query. If we further limit the radius to r ≤ a2, we observe that when the query lies in the left ride of the cell, the radius can- not extend to any of the cells neighboring on the right side and the same rules apply to the other directions. However, if the radius is significantly smaller than a2 (the red query in our example), the efficiency of the acceleration structure drops, as many photons well outside the range have to be examined. Therefore, uniform grids can be a good choice when we have an apriori knowledge of the maximum query radius and do not expect many queries with a radius significantly smaller than that.

The basic build algorithm, i.e., sorting points into the uniform grid, is extremely straightforward and will not be described here. The only challenge is that for the typical relative size of the query radius and the scene, the resulting grid has an enormous number of cells, most of which are actually always empty as they do not contain any surfaces for which photons could even be generated. The solution proposed by Hachisuka et al. [2008] is to use a Hash Grid. In this approach the original, full grid, is never explicitly constructed and each photon is instead stored in a much smaller array at a position determined by a hash of its cell index in the full grid. When a query is made, the required cell indexes are again hashed and all photons stored at the resulting positions are examined. Due to hash collisions it is possible that the query will examine photons from cells that are out of the query’s range. While in some pathological cases this make lookup in the grid almost linear with the number of photons, in practice it is not an issue.