44

Click here to load reader

CS 354 Acceleration Structures

Embed Size (px)

DESCRIPTION

April 24, 2012; CS 354 Computer Graphics; University of Texas at Austin

Citation preview

Page 1: CS 354 Acceleration Structures

CS 354Acceleration Structures

Mark KilgardUniversity of TexasApril 24, 2012

Page 2: CS 354 Acceleration Structures

CS 354 2

Today’s material

In-class quiz On global illumination lecture

Lecture topic Project 4 Acceleration structures

Page 3: CS 354 Acceleration Structures

CS 354 3

My Office Hours

Tuesday, before class Painter (PAI) 5.35 8:45 a.m. to 9:15

Thursday, after class ACE 6.302 11:00 a.m. to 12

Randy’s office hours Monday & Wednesday 11 a.m. to 12:00 Painter (PAI) 5.33

Page 4: CS 354 Acceleration Structures

CS 354 4

Last time, this time

Last lecture, we discussed Global illumination

This lecture Acceleration structures

Projects Project 4 on ray tracing on Piazza

Due May 2, 2012 Get started!

Page 5: CS 354 Acceleration Structures

CS 354 5

Daily Quiz1. Multiple choice: In the Russian

Roulette approach to termination of tracing recursive rays, termination occurs

a) after a fixed number of ray traces

b) after a random number of ray casts between 1 and a fixed constant

c) when an analytic solution can be reached

d) every trace has a random chance of being terminated

2. True or False: A bidirectional reflectance distribution function returns a negative value approximately 50% of the time.

3. Multiple choice: Modeling the influence of participating media simulates a) motion blur

b) fog

c) smoke

d) a., b., and c.

e) b. and c.

4. True of False: Classic Radiosity assume the Bidirectional Reflectance Distribution Function of all surfaces in the scene are Lambertian.

On a sheet of paper• Write your EID, name, and date• Write #1, #2, #3, #4 followed by its answer

Page 6: CS 354 Acceleration Structures

CS 354 6

Project 4 Provides ray tracing framework

Use FLTK toolkit for user interface Includes sample scenes—.ray files

dragon.ray

Page 7: CS 354 Acceleration Structures

CS 354 7

Sample File: sphere.ray

SBT-raytracer 1.0

camera {position = (0,0,-4);viewdir = (0,0,1);aspectratio = 1;updir = (0,1,0);

}

directional_light {direction = (0, 0, 1);colour = (0.2, 0.2, 0.2);

}

point_light {position = (-2, 2, -2);colour = (1, 0.3, 0.3);constant_attenuation_coeff= 0.25;linear_attenuation_coeff = 0.003372407;quadratic_attenuation_coeff = 0.000045492;

}

material = { diffuse = (0.4,0.8,0.2);specular = (1,1,0);shininess = 64;

}

scale(1.5,sphere { })

scale(2,sphere{});

Page 8: CS 354 Acceleration Structures

CS 354 8

What You Must Implement

Blinn-Phong lighting model Ambient, diffuse, specular Modify scene/material.cpp

Point light distance attenuation Inverse squared distance

fall-off Modify scene/light.cpp

Implement reflection and refraction rays Modify most

RayTracer.cpp

Implement shadow ray Modify most

RayTracer.cpp Implement triangle mesh

intersection Including normal

interpolation Modify

SceneObjects/trimesh.cpp

Page 9: CS 354 Acceleration Structures

CS 354 9

Extra Credit Embellishments

Spatial data structures Speed up the ray traces

Texture mapping Anti-aliasing

Cast multiple rays per pixel Lighting effects

Normal mapping, bump mapping, environment mapping

Page 10: CS 354 Acceleration Structures

CS 354 10

Other Project 4 Scenes

recursive_depth.ray turtle.ray hitchcook.ray

cone.ray spheres.ray

Page 11: CS 354 Acceleration Structures

CS 354 11

Debugging Display

Page 12: CS 354 Acceleration Structures

CS 354 12

o

Two Versions ofRendering Equation

dtLtf

tLtL

ir

e

o )(),,,(),,,,(

),,,(),,,( nxx

xx

yyxyx

xx

yx

y

yx dGtLtf

tLtL

r

e

o ),(),,,(),,,,(

),,,(),,,(

Integrate over hemisphere Integrate over all surface points

Occlusion (G) is zero

Page 13: CS 354 Acceleration Structures

CS 354 13

Photon Mapping

Two-pass global illumination algorithm Developed by Henrick Jensen (1996) Two passes

Randomly distribute photons around the scene Called “photon map construction”

Render treating photons as mini-light sources

Capable of efficiently generating otherwise very expensive effects Caustics Diffuse inter-reflections, such as color bleed Sub-surface scattering

Page 14: CS 354 Acceleration Structures

CS 354 14

Light Tracing Trace rays from the light

Contribution rays accumulate image samples

Page 15: CS 354 Acceleration Structures

CS 354 15

Photon Mapping Examples

caustics

diffuse interreflection

without diffuseinterreflection

photo mapvisualization

sub-surface scattering

Page 16: CS 354 Acceleration Structures

CS 354 16

Global Illumination Often Gated by Ray Tracing Speed

Shooting rays tends to be the bottleneck Why?

Lots of rays cast for quality Shadow rays, lots for soft shadows Reflection and refraction rays

Speeding up global illumination generally means speeding up tracing of rays Shading operations can be expensive too But rays involve data structure traversal

Page 17: CS 354 Acceleration Structures

CS 354 17

Recursive Rays

Reflections and refractions can spawn lots of rays

17

More bounces

Fewer bounces

Page 18: CS 354 Acceleration Structures

CS 354 18

Sufficient Shadow Ray Sampling

Page 19: CS 354 Acceleration Structures

CS 354 19

Distribution Ray Tracing

Soft shadows Distribute shadow rays over light source region

All shadow rayshit light source,fully illuminated

No shadow rayshit light source,fully shadowed

Some shadow rayshit light source,

partially shadowed

Page 20: CS 354 Acceleration Structures

CS 354 20

Distribution Ray Tracing

Motion blur Distribute rays over time

Pool BallsTom PorterRenderMan

Page 21: CS 354 Acceleration Structures

CS 354 21

Distribution Ray Tracing Depth of field

Distribute rays across a discrete camera aperture

No depth-of-field

Jittereddepth-of-field

More rays

Even more raysMore images for depth-of-field

Page 22: CS 354 Acceleration Structures

CS 354 22

Acceleration Techniques

Ray Tracing Acceleration Techniques

FastIntersections

FewerRays

GeneralizedRays

Fasterray-object

intersections

Fewerray-object

intersections

Object boundingvolumes

Bounding volumehierarchies

Statisticaloptimizationsfor illuminationconvergence

Beam tracing

Cone tracing

Pencil tracing

Page 23: CS 354 Acceleration Structures

CS 354 23

Accelerating Ray Trace Intersection Operations

Two key optimizations

1. Exploit binary searching Rather than linear searches

2. Group objects spatially Discard hierarchically Use quick-and-coarse tests… …to avoid slow-and-exact intersection tests

Page 24: CS 354 Acceleration Structures

CS 354 24

Acceleration Structures:Bounding Volume Hierarchies

Build hierarchy of bounding volumes Bounding volume of interior node has its children

Page 25: CS 354 Acceleration Structures

CS 354 25

Accelerate Ray Intersections Traverse hierarchy to accelerate ray

intersections Intersect node content

only if ray hits thebounding volume

Skip intersection A, D, E, and F

Page 26: CS 354 Acceleration Structures

CS 354 26

Accelerate Ray Intersection Algorithm

Sort hits and detect early termination

FindIntersection( Ray ray, Node node ){ // Find intersections with child node bounding volumes … // Sort intersections closest to farthest … // Process intersections, checking for early termination min_t = infinity; for each intersected child i { if (min_t < bv_t[i]) break; shape_t = FindIntersection(ray, child); if (shape_t < min_t) { min_t = shape_t; } } return min_t; // closest intersection}

Page 27: CS 354 Acceleration Structures

CS 354 27

Bounding Volumes

Axis-Aligned Bounding Boxes (AABB) min (x,y,z) & max(x,y,z) Trivial plane equations

Bounding spheres Point and radius Ray and sphere intersection is easy

Solving a quadratic equation

Oriented Bounding Box Might have tighter bounds than AABB

Convex Polyhedron (Polytope)

Page 28: CS 354 Acceleration Structures

CS 354 28

Spatial Hierarchy

Uniform grid Quadtree (2D) and Octree (3D)

Exactly four or eight children Equal area/volume for each children

KD Tree Two children, splitting in X, Y, or Z Axis aligned splitting planes

Not necessarily equal area/volume

Binary Space Partitioning (BSP) Tree Arbitrary splitting planes Just two children

Page 29: CS 354 Acceleration Structures

CS 354 29

Space Subdivision Approaches

Uniform grid OctreeQuadtree

KD TreeBinarySpacePartitioningTree

Page 30: CS 354 Acceleration Structures

CS 354 30

Uniform Grid Construction

Preprocess scene

1. Find bounding box

2. Determine grid resolution

Page 31: CS 354 Acceleration Structures

CS 354 31

Uniform Grid Construction

Preprocess scene

1. Find bounding box

2. Determine grid resolution

3. Place object in cell if its bounding box overlaps the cell

Page 32: CS 354 Acceleration Structures

CS 354 32

Uniform Grid Construction

Preprocess scene

1. Find bounding box

2. Determine grid resolution

3. Place object in cell if its bounding box overlaps the cell

4. Check that object overlaps cell

Page 33: CS 354 Acceleration Structures

CS 354 33

Uniform Grid Traversal

After processing…Traverse grid 3D line = 3D-DDADigital Differential Analyzer

AdvantagesSimple constructionSimple traversal

DisadvantagePoor at sparse or huge scenes

Page 34: CS 354 Acceleration Structures

CS 354 34

Binary Space Partitioning Tree

2D view of BSP

Page 35: CS 354 Acceleration Structures

CS 354 35

Binary Space Partitioning Trees

Recursive search Partitioning plane has two nodes

FindIntersection( Ray ray, Node node ){ if node is leaf { intersect ray with each object in node return closest object (or nil) } near = child of node in half space containing ray’s origin far = the other child hit = FindIntersection( ray, near ) if hit is null and ray intersections plane defined by node { hit = FindIntersection( ray, far ) } return hit;}

Page 36: CS 354 Acceleration Structures

CS 354 36

BSP Intersection with a Ray

Page 37: CS 354 Acceleration Structures

CS 354 37

Optimizing Bounding Hierarchies

Complex meshes need to be partitioned into bounding hierarchy

[Saut, Sidobre, 2012]

Page 38: CS 354 Acceleration Structures

CS 354 38

Octree Building

Building octree from boundary representation

Page 39: CS 354 Acceleration Structures

CS 354 39

KD-tree Like an Octree

But dividing planes aren’t necessarily in even octo squares

Tighter bounds

[Mahmoud Zidan]

Page 40: CS 354 Acceleration Structures

CS 354 40

Close Cousin of Ray Tracing:Volume Rendering

Common task: visualization of volumetric data Data arranged in 3D “voxel” grid

Voxel = volume element

Applications: medical, oil & gas exploration

Page 41: CS 354 Acceleration Structures

CS 354 41

Simple Case of Ray Casting

Rays are all coherent GPU-oriented Volume rendering

Draw 3D textured polygons slicing through a 3D texture Apply transfer function Blend in ray order—use framebuffer blending

Page 42: CS 354 Acceleration Structures

CS 354 42

Transfer Function Give viewer control of how volumetric data

maps to color & opacity Transfer functions enable visualization of

otherwise difficult-to-understand mass of data

Page 43: CS 354 Acceleration Structures

CS 354 43

Volume Rendering Examples

Liver tumor

Head with clip planes

Page 44: CS 354 Acceleration Structures

CS 354 44

Next Class

Next lecture Performance analysis Considerations for tuning interactive graphics

applications

Reading Chapter 8, 455-460 Chapter 11, 578-601

Project 4 Project 4 is a simple ray tracer Due Wednesday, May 2, 2012