Quiz: tracing fast
Before this unit: Shadows, mirrors and glass (previous unit); Day 52: 3D graphics.
See also: Day 46: Colour; Day 5: Deconvolution; Day 55: How GPUs work.
Short questions to test your understanding. Try each on paper first, then open the answer.
Q1. A scene has 10^6 triangles. Roughly how many tests does one ray need with brute force, and with a good bounding-volume hierarchy?
A balanced binary tree over N leaves has depth \log_2 N.
Brute force: 10^6 triangle tests. A good BVH: about 2\log_2 10^6 \approx 40 box tests plus a few triangle tests. The tree must be built first, once, in about N\log N steps.
Q2. The ray from (-1, 0.5) along (1, 0.25) and the box [0, 2] \times [0, 1]: give the t-interval in each slab and decide whether the ray hits the box.
t = (\text{plane} - o_k)/d_k for the two planes of each slab.
x: t \in [(0 + 1)/1, (2 + 1)/1] = [1, 3]. y: t \in [(0 - 0.5)/0.25, (1 - 0.5)/0.25] = [-2, 2]. Overlap [1, 2], not empty and in front of the origin: a hit, entering at t = 1 (the point (0, 0.75)) and leaving at t = 2 (the point (1, 1)).
Q3. During BVH traversal, the ray has already hit an object at t = 5. The next box on the stack starts at t = 7. What does the traversal do, and why is that safe?
Where can objects inside that box be hit?
It skips the box. Everything inside the box can only be hit at t \ge 7, farther than the hit already found at t = 5, so nothing in it can be the nearest hit. Visiting the nearer child first makes such early exits frequent.
Q4. Why does a uniform grid work badly for a small, detailed object in a large, otherwise empty scene (“a teapot in a stadium”)?
How are the objects distributed over the cells?
The cell size is the same everywhere. Cells big enough to keep the grid small put the whole teapot into one or a few cells, so a ray into it tests almost all of its triangles; cells small enough for the teapot make the stadium a huge number of empty cells to walk through. A BVH (or an octree) adapts to the content.
Q5. The surface area heuristic compares split A (cost 6.4) with split B (cost 8.4) and a leaf (cost 12). What do these numbers estimate, and which does it choose?
Expected number of tests for a random ray that reaches the node.
The expected cost (box tests plus object tests) of a random ray that hits this node, under each option. The cost weights each child’s object count by the probability that the ray also hits that child, its surface area relative to the parent’s. Split A is cheapest and is chosen.
Q6. For each, rasterise or ray-trace? (a) a game at 60 frames per second; (b) a room full of mirrors; (c) a fast preview of a CT isosurface while rotating it; (d) a physically correct image of a glass of water.
Primary visibility only, or light that bounces?
- Rasterise (perhaps with a few traced rays for shadows and reflections: hybrid). (b) Ray-trace: mirrors need reflected rays, many bounces deep. (c) Rasterise: only primary visibility and simple shading are needed, at interactive speed. (d) Ray-trace (path trace): refraction, reflection and caustics.
Q7. What do the ray-tracing units of a modern GPU accelerate, and why do scattered secondary rays still run slower than primary rays?
GPUs run groups of threads in lock-step and like neighbouring memory accesses.
They do the BVH box tests during traversal and the ray–triangle tests in fixed-function hardware. Primary rays from neighbouring pixels go in nearly the same direction and visit the same nodes; bounced rays scatter, so threads that run together want different nodes and different memory: branch divergence and incoherent memory access.
Q8. (math) A ray is parallel to the x-slab of a box (d_x = 0) and its origin has o_x inside the slab. Show that the IEEE rules 1/0 = +\infty and a\cdot\infty = \pm\infty give the slab interval (-\infty, \infty), and that an origin outside the slab gives an empty interval.
Compute (\min_x - o_x)\cdot(1/d_x) and (\max_x - o_x)\cdot(1/d_x); mind the signs.
1/d_x = +\infty. Inside: \min_x - o_x < 0 and \max_x - o_x > 0, giving -\infty and +\infty: the interval (-\infty, \infty), which does not restrict the other slabs. Outside, say o_x < \min_x: both differences are positive, both products +\infty, the interval [\infty, \infty], so t_\text{near} = \infty > t_\text{far} of any other slab: a miss. (With d_x = -0 the signs flip but the result is the same.)