Accelerating Ray-Tracing

Similar documents
Intro to Ray-Tracing & Ray-Surface Acceleration

Ray Intersection Acceleration

Accelerating Geometric Queries. Computer Graphics CMU /15-662, Fall 2016

Acceleration Data Structures

Computer Graphics. - Spatial Index Structures - Philipp Slusallek

Computer Graphics. - Ray-Tracing II - Hendrik Lensch. Computer Graphics WS07/08 Ray Tracing II

Accelerated Raytracing

Ray Tracing I: Basics

Ray Tracing. Computer Graphics CMU /15-662, Fall 2016

Intersection Acceleration

Anti-aliased and accelerated ray tracing. University of Texas at Austin CS384G - Computer Graphics Fall 2010 Don Fussell

Ray Tracing Acceleration. CS 4620 Lecture 20

Ray Tracing III. Wen-Chieh (Steve) Lin National Chiao-Tung University

Ray Intersection Acceleration

Spatial Data Structures

Computer Graphics. Bing-Yu Chen National Taiwan University The University of Tokyo

Computer Graphics. Bing-Yu Chen National Taiwan University

Spatial Data Structures

Computer Graphics (CS 543) Lecture 13b Ray Tracing (Part 1) Prof Emmanuel Agu. Computer Science Dept. Worcester Polytechnic Institute (WPI)

Parallel Physically Based Path-tracing and Shading Part 3 of 2. CIS565 Fall 2012 University of Pennsylvania by Yining Karl Li

Spatial Data Structures

Anti-aliased and accelerated ray tracing. University of Texas at Austin CS384G - Computer Graphics

INFOGR Computer Graphics. J. Bikker - April-July Lecture 11: Acceleration. Welcome!

Spatial Data Structures

Spatial Data Structures

Ray Tracing Acceleration Data Structures

CS580: Ray Tracing. Sung-Eui Yoon ( 윤성의 ) Course URL:

CS354 Computer Graphics Ray Tracing. Qixing Huang Januray 24th 2017

Topics. Ray Tracing II. Intersecting transformed objects. Transforming objects

Ray Tracing. Cornell CS4620/5620 Fall 2012 Lecture Kavita Bala 1 (with previous instructors James/Marschner)

Real Time Ray Tracing

Lecture 11: Ray tracing (cont.)

Ray Tracing Acceleration. CS 4620 Lecture 22

Ray Casting. Outline in Code. Outline. Finding Ray Direction. Heckbert s Business Card Ray Tracer. Foundations of Computer Graphics (Fall 2012)

Topics. Ray Tracing II. Transforming objects. Intersecting transformed objects

Ray Casting. To Do. Outline. Outline in Code. Foundations of Computer Graphics (Spring 2012) Heckbert s Business Card Ray Tracer

Announcements. Written Assignment2 is out, due March 8 Graded Programming Assignment2 next Tuesday

Chapter 11 Global Illumination. Part 1 Ray Tracing. Reading: Angel s Interactive Computer Graphics (6 th ed.) Sections 11.1, 11.2, 11.

Sung-Eui Yoon ( 윤성의 )

Spatial Data Structures and Speed-Up Techniques. Tomas Akenine-Möller Department of Computer Engineering Chalmers University of Technology

CPSC / Sonny Chan - University of Calgary. Collision Detection II

SPATIAL DATA STRUCTURES. Jon McCaffrey CIS 565

Effects needed for Realism. Computer Graphics (Fall 2008) Ray Tracing. Ray Tracing: History. Outline

Spatial Data Structures. Steve Rotenberg CSE168: Rendering Algorithms UCSD, Spring 2017

Point Cloud Filtering using Ray Casting by Eric Jensen 2012 The Basic Methodology

The Traditional Graphics Pipeline

Effects needed for Realism. Ray Tracing. Ray Tracing: History. Outline. Foundations of Computer Graphics (Spring 2012)

The Traditional Graphics Pipeline

Ray Tracing with Spatial Hierarchies. Jeff Mahovsky & Brian Wyvill CSC 305

Lecture 2 - Acceleration Structures

11 - Spatial Data Structures

Ray Tracing Performance

Speeding Up Ray Tracing. Optimisations. Ray Tracing Acceleration

Ray Tracing. Outline. Ray Tracing: History

Last Time: Acceleration Data Structures for Ray Tracing. Schedule. Today. Shadows & Light Sources. Shadows

Questions from Last Week? Extra rays needed for these effects. Shadows Motivation

CS 431/636 Advanced Rendering Techniques

Advanced Ray Tracing

CPSC GLOBAL ILLUMINATION

SUMMARY. CS380: Introduction to Computer Graphics Ray tracing Chapter 20. Min H. Kim KAIST School of Computing 18/05/29. Modeling

Computer Graphics Ray Casting. Matthias Teschner

EFFICIENT BVH CONSTRUCTION AGGLOMERATIVE CLUSTERING VIA APPROXIMATE. Yan Gu, Yong He, Kayvon Fatahalian, Guy Blelloch Carnegie Mellon University

Acceleration. Digital Image Synthesis Yung-Yu Chuang 10/11/2007. with slides by Mario Costa Sousa, Gordon Stoll and Pat Hanrahan

Lighting. To do. Course Outline. This Lecture. Continue to work on ray programming assignment Start thinking about final project

The Traditional Graphics Pipeline

Other Rendering Techniques CSE 872 Fall Intro You have seen Scanline converter (+z-buffer) Painter s algorithm Radiosity CSE 872 Fall

Speeding up your game

CS 563 Advanced Topics in Computer Graphics Culling and Acceleration Techniques Part 1 by Mark Vessella

Graphics 2009/2010, period 1. Lecture 8: ray tracing

Advanced 3D-Data Structures

COMP 4801 Final Year Project. Ray Tracing for Computer Graphics. Final Project Report FYP Runjing Liu. Advised by. Dr. L.Y.

CS348B Lecture 2 Pat Hanrahan, Spring Greeks: Do light rays proceed from the eye to the light, or from the light to the eye?

Motivation. Sampling and Reconstruction of Visual Appearance. Effects needed for Realism. Ray Tracing. Outline

Acceleration Structures. CS 6965 Fall 2011

Today. Acceleration Data Structures for Ray Tracing. Cool results from Assignment 2. Last Week: Questions? Schedule

Accelerating Ray Tracing

Computing Visibility. Backface Culling for General Visibility. One More Trick with Planes. BSP Trees Ray Casting Depth Buffering Quiz

Logistics. CS 586/480 Computer Graphics II. Questions from Last Week? Slide Credits

COMPUTER GRAPHICS COURSE. Ray Tracing

Recall: Inside Triangle Test

Acceleration Data Structures. Michael Doggett Department of Computer Science Lund university

EDAN30 Photorealistic Computer Graphics. Seminar 2, Bounding Volume Hierarchy. Magnus Andersson, PhD student

6.837 Introduction to Computer Graphics Final Exam Tuesday, December 20, :05-12pm Two hand-written sheet of notes (4 pages) allowed 1 SSD [ /17]

Bounding Volume Hierarchies. CS 6965 Fall 2011

Lecture 25 of 41. Spatial Sorting: Binary Space Partitioning Quadtrees & Octrees

VIII. Visibility algorithms (II)

improving raytracing speed

Reading Ray Intersection Chapter 2: Geometry and Transformations Acceleration Covers basic math and PBRT implementation: read on your own

CS535 Fall Department of Computer Science Purdue University

Rendering. Converting a 3D scene to a 2D image. Camera. Light. Rendering. View Plane

Ray Casting of Trimmed NURBS Surfaces on the GPU

graphics pipeline computer graphics graphics pipeline 2009 fabio pellacini 1

graphics pipeline computer graphics graphics pipeline 2009 fabio pellacini 1

TDA362/DIT223 Computer Graphics EXAM (Same exam for both CTH- and GU students)

Review for Ray-tracing Algorithm and Hardware

Scene Management. Video Game Technologies 11498: MSc in Computer Science and Engineering 11156: MSc in Game Design and Development

MSBVH: An Efficient Acceleration Data Structure for Ray Traced Motion Blur

Enhancing Traditional Rasterization Graphics with Ray Tracing. October 2015

B-KD Trees for Hardware Accelerated Ray Tracing of Dynamic Scenes

Ray Tracing. CPSC 453 Fall 2018 Sonny Chan

Transcription:

Lecture 9: Accelerating Ray-Tracing Computer Graphics and Imaging UC Berkeley CS184/284A, Spring 2016

Course Roadmap Rasterization Pipeline Core Concepts Sampling Antialiasing Transforms Geometric Modeling Core Concepts Subdivision Geometry processing as resampling Hierarchies for acceleration Rasterization Transforms & Projection Texture Mapping Visibility, Shading, Overall Pipeline Intro to Geometry Curves and Surfaces Geometry Processing Today: Ray-Tracing & Acceleration Lighting & Materials Cameras & Imaging

Basic Ray-Tracing Algorithm

Light Rays Three ideas about light rays 1. Light travels in straight lines (mostly) 2. Light rays do not interfere with each other if they cross (light is invisible!) 3. Light rays travel from the light sources to the eye (but the physics is invariant under path reversal - reciprocity).

Ray Casting Appel 1968 - Ray casting 1. Generate an image by casting one ray per pixel 2. Check for shadows by sending a ray to the light

Ray Casting Generating Eye Rays Ray origin (constant): viewpoint (pinhole of camera) Ray direction (varying): toward pixel position on viewing window viewpoint viewing window pixel position viewing ray

Recursive Ray Tracing An improved Illumination model for shaded display T. Whitted, CACM 1980 Time: VAX 11/780 (1979) 74m PC (2006) 6s GPU (2012) 1/30s Spheres and Checkerboard, T. Whitted, 1979

Recursive Ray Tracing Pinhole Camera secondary rays primary ray eye point image plane shadow rays light source

Ray-Surface Intersection (Quick Reminder)

Ray Intersection With Sphere Ray: r(t) =o + t d, 0 apple t<1 0 Sphere: p :(p c) 2 R 2 =0 (p R 2 c) Intersection: t = b ± p b 2 4ac 2a a = d d b = 2(o c) d c =(o c) (o c) R 2

Ray Intersection With Plane Ray equation: r(t) =o + t d, 0 apple t<1 0 Plane equation: p :(p p 0 ) N =0 p 0 ) Intersection: 0 0 t = (p0 o) N Check: 0 apple t<1 d N

Ray Intersection with Axis-Aligned Planes t = (p0 o) N d N =) t = p0 x o x d x

Ray Intersection With Triangle Triangle is in a plane Ray-plane intersection Test if hit point is inside triangle Many ways to optimize Möller-Trumbore algorithm

Accelerating Ray-Surface Intersection

Ray Tracing Performance Challenges Simple ray-scene intersection Exhaustively test ray-intersection with every object Problem: Exhaustive algorithm = #pixels #objects Very slow!

Ray Tracing Performance Challenges Jun Yan, Tracy Renderer San Miguel Scene, 10.7M triangles

Ray Tracing Performance Challenges Deussen et al; Pharr & Humphreys, PBRT Plant Ecosystem, 20M triangles

Discussion: Your Ideas To Make This Faster? Deussen et al; Pharr & Humphreys, PBRT

Bounding Volumes

Bounding Volumes Quick way to avoid intersections: bound complex object with a simple volume Object is fully contained in the volume If it doesn t hit the volume, it doesn t hit the object So test bvol first, then test object if it hits

Ray-Intersection With Box Could intersect with 6 faces individually Better way: box is the intersection of 3 slabs

Ray Intersection with Axis-Aligned Box 2D example; 3D is the same! Compute intersections with slabs and take intersection of t min /t max intervals y 1 t max y 1 t max y 1 t max t min t min o, d o, d o, d y 0 t min y 0 y 0 x 0 x 1 Note: t min < 0 x 0 x 1 x 0 x 1 Intersections with x planes Intersections with y planes Final intersection result How do we know when the ray misses the box?

Uniform Spatial Partitions (Grids)

Preprocess Build Acceleration Grid 1. Find bounding box

Preprocess Build Acceleration Grid 1. Find bounding box 2. Create grid

Preprocess Build Acceleration Grid 1. Find bounding box 2. Create grid 3. Store each object in overlapping cells

Ray-Scene Intersection Step through grid in ray traversal order (3D line - 3D DDA) For each grid cell Test intersection with all objects stored at that cell

Grid Resolution? One cell No speedup

Grid Resolution? Too many cells Inefficiency due to extraneous grid traversal

Grid Resolution? Heuristic: #cells = C * #objs C 27 in 3D

Careful! Objects Overlapping Multiple Cells What goes wrong here? First intersection found (red) is not the nearest! Solution? Check intersection point is inside cell Optimize Cache intersection to avoid re-testing (mailboxing)

Uniform Grids When They Work Well Deussen et al; Pharr & Humphreys, PBRT Grids work well on large collections of objects that are distributed evenly in size and space

Uniform Grids When They Fail Jun Yan, Tracy Renderer Teapot in a stadium problem

Non-Uniform Spatial Partitions Spatial Hierarchies

Spatial Hierarchies A A

Spatial Hierarchies A B B A

Spatial Hierarchies A 2 1 B 1 C B 2 C 4 D 3 D 3 4 5 5 A

Spatial Partitioning Variants KD-Tree Oct-Tree BSP-Tree

KD-Trees Internal nodes store split axis: x-, y-, or z-axis split position: coordinate of split plane along axis children: reference to child nodes Leaf nodes store list of objects mailbox information

KD-Tree Pre-Processing Find bounding box Recursively split cells, axis-aligned planes C B Until termination criteria met (e.g. max depth or min #objs) D Store obj references with each leaf node A

KD-Tree Pre-Processing A Root 2 1 B Internal Nodes 1 C B 2 C D 3 D A 4 5 3 4 5 Leaf Nodes Only leaf nodes store references to geometry

KD-Tree Pre-Processing Choosing the split plane Simple: midpoint, median split Ideal: split to minimize expected cost of ray intersection Termination criteria? Simple: common to prescribe maximum tree depth (empirical 8 + 1.3 log N, N = #objs) [PBRT] Ideal: stop when splitting does not reduce expected cost of ray intersection

Top-Down Recursive In-Order Traversal A 1 B C B 2 C D 3 D 4 5 A

Top-Down Recursive In-Order Traversal t min t split A 1 B C B 2 C D 3 D t max 4 5 Internal node: split A

Top-Down Recursive In-Order Traversal t min t max A 1 B C B 2 C D 3 D 4 5 Leaf node: intersect A all objects

Top-Down Recursive In-Order Traversal t min A 1 B C t split B 2 C D 3 D t max 4 5 Internal node: split A

Top-Down Recursive In-Order Traversal t min A 1 B C t max B 2 C D 3 D 4 5 Leaf node: intersect A all objects

Top-Down Recursive In-Order Traversal A 1 B t split C t min B 2 C D 3 D t max 4 5 Internal node: split A

Top-Down Recursive In-Order Traversal A 1 B C t min B 2 C D 3 D t max 4 5 Leaf node: intersect A all objects

Top-Down Recursive In-Order Traversal A 1 B C t hit B 2 C D 3 D 4 5 Intersection found A

KD-Trees Traversal Recursive Step W.L.O.G. consider x-axis split with ray moving right t split =(x split o x )/d x t split t split (x split t split

Object Partitions & Bounding Volume Hierarchy (BVH)

Spatial vs Object Partitions Spatial partition (e.g.kd-tree) Partition space into nonoverlapping regions Objects can be contained in multiple regions Object partition (e.g. BVH) Partition set of objects into disjoint subsets Sets may overlap in space

Bounding Volume Hierarchy (BVH) Root

Bounding Volume Hierarchy (BVH)

Bounding Volume Hierarchy (BVH)

Bounding Volume Hierarchy (BVH) C A B C D D B A

Bounding Volume Hierarchy (BVH) Internal nodes store Bounding box Children: reference to child nodes Leaf nodes store Bounding box List of objects Nodes represent subset of primitives in scene All objects in subtree

BVH Pre-Processing Find bounding box Recursively split set of objects in two subsets Stop when there are just a few objects in each set Store obj reference(s) in each leaf node

BVH Pre-Processing Choosing the set partition Choose a dimension to split or optimize over x,y,z Simple #1: Split objects around spatial midpoint Simple #2: Split at location of median object Ideal: split to minimize expected cost of ray intersection Termination criteria? Simple: stop when node contains few elements (e.g. 5) Ideal: stop when splitting does not reduce expected cost of ray intersection

BVH Recursive Traversal Intersect (Ray ray, BVH node) node if (ray misses node.bbox) return; if (node is a leaf node) test intersection with all objs; return closest intersection; hit1 = Intersect (ray, node.child1); hit2 = Intersect (ray, node.child2); return closer of hit1, hit2; child1 child2

Optimizing Hierarchical Partitions (How to Split?)

How to Split into Two Sets? (BVH)

How to Split into Two Sets? (BVH)

How to Split into Two Sets? (BVH) Split at median element Child nodes have equal numbers of elements

How to Split into Two Sets? (BVH) A better split? Smaller bounding boxes, avoid overlap and empty space

Which Hierarchy Is Fastest? Key insight: a good partition minimizes the average cost of tracing a ray

Which Hierarchy Is Fastest? What is the average cost of tracing a ray? For leaf node: Cost(node) = cost of intersecting all triangles = C_isect * TriCount(node) C_isect = cost of intersecting a triangle TriCount(node) = number of triangles in node

Which Hierarchy Is Fastest? What is the average cost of tracing a ray? For internal node: Cost(node) = C_trav + Prob(hit L)*Cost(L) + Prob(hit R)*Cost(R) C_trav = cost of traversing a cell Cost(L) = cost of traversing left child Cost(R) = cost of traversing right child

Estimating Cost with Surface Area Heuristic (SAH) Probabilities of ray intersecting a node If assume uniform ray distribution, no occlusions, then probability is proportional to node s surface area Cost of processing a node Common metric is #triangles in node Cost(cell) = C_trav + SA(L)*TriCount(L) + SA(R)*TriCount(R) SA(node) = surface area of bbox of node C_trav = ratio of cost to traverse vs. cost to intersect tri C_trav = 1:8 in PBRT [Pharr & Humphreys] C_trav = 1:1.5 in a highly optimized version

Ray Intersection Probability The probability of a random ray hitting a convex shape A enclosed by another convex shape B is the ratio of their surface areas, S A / S B. S B S A P (hita hitb) = S A S B

Partition Implementation Constrain search to axis-aligned spatial partitions Choose an axis Choose a split plane on that axis Partition objects into two halves by centroid 2N 2 candidate split planes for node with N primitives. (Why?)

Partition Implementation (Efficient) Efficient modern approximation: split spatial extent of primitives into B buckets (B is typically small: B < 32) b0 b1 b2 b3 b4 b5 b6 b7 For each axis: x,y,z: initialize buckets For each object p in node: b = compute_bucket(p.centroid) b.bbox.union(p.bbox); b.prim_count++; For each of the B 1 possible partitioning planes evaluate SAH Execute lowest cost partitioning found (or make node a leaf)

Cost-Optimization Applies to Spatial Partitions Too Discussed optimization of BVH construction But principles are general and apply to spatial partitions as well E.g. to optimize KD-Tree construction Goal is to minimize average cost of intersecting ray with tree Can still apply Surface Area Heuristic Note that surface areas and number of nodes in children differ from BVH

Things to Remember Linear vs logarithmic ray-intersection techniques Many techniques for accelerating ray-intersection Spatial partitions: Grids and KD-Trees Object partitions: Bounding Volume Hierarchies Optimize hierarchy construction based on minimizing cost of intersecting ray against hierarchy Leads to Surface Area Heuristic for best partition

Art Competition #1 Results

Art Competition #1 Honorable Mention Stormtrooper, Vincent Escueta UC Berkeley CS184/284A Spring 2016

Art Competition #1 Honorable Mention Go Bears! Keeyune Cho UC Berkeley CS184/284A Spring 2016

Art Competition #1 Honorable Mention Stochastic Tree, Hugh Chen UC Berkeley CS184/284A Spring 2016

Art Competition #1 Winner Delaunay Triangulation of Great Wave off Kanagawa Arissa Wongpanich UC Berkeley CS184/284A Spring 2016

Thank You Our Course GSIs Ben Mildenhall Weilun Sun UC Berkeley CS184/284A Spring 2016

Acknowledgments Thanks to Pat Hanrahan, Kayvon Fatahalian, Mark Pauly and Steve Marschner for lecture resources.