Real Time Ray Tracing Programação 3D para Simulação de Jogos Vasco Costa
Ray tracing? Why? How? P3DSJ Real Time Ray Tracing Vasco Costa 2
Real time ray tracing : example Source: NVIDIA P3DSJ Real Time Ray Tracing Vasco Costa 3
Exploiting vector parallelism exploit ray coherence for ray triangle intersections P3DSJ Real Time Ray Tracing Vasco Costa 4
Ray packets / Triangle packets (summary) exploit ray coherence for ray triangle intersections Pros common subexpressions for intersections with same ray origin are eliminated. better cache coherence. Cons mostly useful for primary rays (ray packets). useful only if there are enough triangles in the scene (triangle packets). Due to fine granularity usually employed in combination with vector parallelism. P3DSJ Real Time Ray Tracing Vasco Costa 5
Exploiting thread parallelism Task to be divided should have large enough granularity. Ray scene intersection is usually divided among threads: a 1024x1024 display needs tracing of over 1 million rays How to divide the ray workload? P3DSJ Real Time Ray Tracing Vasco Costa 6
Ray generation & distribution Thread workload division matters. Simple chequerboard distribution (left) scales well in pratice. Other ray generation schemes (e.g. Z order) are sometimes used. P3DSJ Real Time Ray Tracing Vasco Costa 7
Z order ray generation Idea is that neighbouring display areas have similar complexity. Better cache coherence during tracing. Source: Wikipedia P3DSJ Real Time Ray Tracing Vasco Costa 8
Adaptive supersampling Instead of tracing rays for every pixel, the display is coarsely sampled first. More rays are traced in areas where there is more variability and detail. May introduce rendering errors, worsen cache coherency, imbalance thread distribution. P3DSJ Real Time Ray Tracing Vasco Costa 9
Spatial subdivision (1) Ray tracing algorithm is easy to paralelize. However number of ray triangle intersections is still huge so some sort of spatial subdivision is required to accelerate rayscene queries for scenes with many triangles. There is no optimum spatial subdivision scheme for all scenes: is geometry static? locally static? or dynamic? is scene triangle density regular? or irregular? Commonly used spatial subdivision schemes include: bounding volume hierarchies (BVH), KD trees, grids. P3DSJ Real Time Ray Tracing Vasco Costa 10
Spatial subdivision (2) BVH fast updates (for rigid bodies), medium memory consumption, expensive traversal, ok to parallelize (recursive, variable branching factor). KD tree slow updates, low memory consumption, cheap traversal, hard to paralellize (recursive, low branching factor). Grid fast updates (for dynamic geometry), high memory consumption, hard to predict rendering performance, easy to parallelize (non recursive). P3DSJ Real Time Ray Tracing Vasco Costa 11
Spatial subdivision (3) Implementation details can cause a high performance impact: Grids and BVHs compress better than KD trees. In the case of grids using compression for empty cells can reduce memory consumption so that it is lower than uncompressed KD trees. Some KD tree implementations have faster updates for rigid bodies. BVHs and KD trees have better performance than grids for static scenes with non regular geometry. This is due to the use of Surface Area Heuristics (SAH) for calculating the split boxes/planes. How to compute the splits for spatial subdivision? P3DSJ Real Time Ray Tracing Vasco Costa 12
Grid heuristics The goal of traditional grid heuristics is to reduce memory consumption. Hence an heuristic that strives to have linear memory consumption versus the number of primitives is commonly employed. Example: dim[ x, y, z] = density 3 numtriangles where density is some fixed value. P3DSJ Real Time Ray Tracing Vasco Costa 13
KD tree / BVH heuristics A top down split method is usually employed. Examples: split axis : splitting along the middle of the largest extent. split location : splitting by the median of the triangle geometry. surface area heuristic (SAH) : greedy search which tries to minimize a cost function. Heuristic selection can markedly impact performance. Surface Area Heuristics are state of the art and can improve render time performance over 100% at the cost of construction time. Surface Area Heuristic (SAH) example: Cost(cell) = = Ctrav + ProbHit(L) x Cost(L) + ProbHit(R) x Cost(R) = Ctrav + SA(L) x NumTriangles(L) + SA(R) x NumTriangles(R) P3DSJ Real Time Ray Tracing Vasco Costa 14
KD tree heuristics : test scene Source: Ray Tracing Performance, Gordon Stoll, SIGGRAPH 2006 P3DSJ Real Time Ray Tracing Vasco Costa 15
KD tree heuristics : split axis Source: Ray Tracing Performance, Gordon Stoll, SIGGRAPH 2006 P3DSJ Real Time Ray Tracing Vasco Costa 16
KD tree heuristics : split location Source: Ray Tracing Performance, Gordon Stoll, SIGGRAPH 2006 P3DSJ Real Time Ray Tracing Vasco Costa 17
KD tree heuristics : SAH Source: Ray Tracing Performance, Gordon Stoll, SIGGRAPH 2006 P3DSJ Real Time Ray Tracing Vasco Costa 18
Quake Wars : Ray Traced (real time ray tracing) Source: Intel P3DSJ Real Time Ray Tracing Vasco Costa 19
Aurora (real time ray tracing with primary rays only, interactive with secondary rays) P3DSJ Real Time Ray Tracing Vasco Costa 20
NVIDIA Fermi Demo (real time ray tracing & interactive path tracing) Source: NVIDIA P3DSJ Real Time Ray Tracing Vasco Costa 21
Mental Images iray (interactive ray tracing & global illumination) Source: CGArchitect.com P3DSJ Real Time Ray Tracing Vasco Costa 22
References State of the Art in Ray Tracing Animated Scenes Ingo Wald, William Mark, Johannes Günther, Solomon Boulos, Thiago Ize, Warren Hunt, Steven Parker, and Peter Shirley Eurographics (2007) Real time Ray Tracing through the Eyes of a Game Developer Jacco Bikker IEEE/Eurographics Symposium on Interactive Ray Tracing (2007) Physically Based Rendering: From Theory to Implementation Matt Pharr, Greg Humphreys Morgan Kaufmann (2004) P3DSJ Real Time Ray Tracing Vasco Costa 23