last time fundamentals of rendering - radiometry /...
TRANSCRIPT
© Machiraju/Zhang/Möller
Last Time
Fundamentals of Rendering - Radiometry / Photometry
1
© Lastra/Machiraju/Möller/Weiskopf
Radiometry
• Science of measuring light• Analogous science called photometry is
based on human perception.
© Lastra/Machiraju/Möller/Weiskopf
Radiometry - Quantities• Energy Q• Power Φ - J/s or W
– Energy per time (radiant power or flux)• Irradiance E and Radiosity B - W/m2
– Power per area
• Intensity I - W/sr– Power per solid angle
• Radiance L - W/sr/m2
– Power per projected area and solid angle
© Lastra/Machiraju/Möller/Weiskopf
Radiant Energy - Q
• Think of photon as carrying quantum of energy hc/λ = hf (photoelectric effect)– c is speed of light– h is Planck’s constant– f is frequency of radiation
• Wave packets• Total energy, Q, is then energy of the
total number of photons• Units - joules or eV
© Lastra/Machiraju/Möller/Weiskopf
Power / Flux - Φ
• Flow of energy (important for transport)• Also - radiant power or flux.• Energy per unit time (joules/s = eV/s)• Unit: W - watts• Φ = dQ/dt
© Lastra/Machiraju/Möller/Weiskopf
€
I =dΦdω
Intensity I
• Flux density per unit solid angle
• Units – watts per steradian• “intensity” is heavily overloaded. Why?
– Power of light source– Perceived brightness
© Lastra/Machiraju/Möller/Weiskopf
€
u =dΦdA
dA
Radiant Flux Area Density
• Area density of flux (W/m2)• u = Energy arriving/leaving a surface per
unit time interval per unit area• dA can be any 2D surface in space
© Lastra/Machiraju/Möller/Weiskopf
Irradiance E
• Power per unit area incident on a surface
€
E =dΦdA
© Lastra/Machiraju/Möller/Weiskopf
Radiosity or Radiant Exitance B
• Power per unit area leaving surface• Also known as Radiosity• Same unit as irradiance, just direction
changes
€
B =dΦdA
© Lastra/Machiraju/Möller/Weiskopf
€
L =d2Φ
dAp dω
€
L =d2Φ
dAcosθdω
Radiance L
• Power per unit projected area per unit solid angle.
• Units – watts per (steradian m2)• We have now introduced projected area,
a cosine term.
© Lastra/Machiraju/Möller/Weiskopf11
Radiometric QuantitiesPhysicaldescription
Definition Symbol Units Radiometric quantity (also “spectral *” [*/m])
Energy Qe [J=Ws] Joule Radiant energy
Power / flux dQ/dt Φe [W=J/s] Radiant power / flux
Flux density dQ/dAdt Ee [W/m2] Irradiance
Flux density dQ/dAdt Me= Be [W/m2] Radiosity
Angular flux density
dQ/dAdωdt Lv [W/m2sr] Radiance
Intensity dQ/dωdt Iv [W/sr] Radiant intensity
© Lastra/Machiraju/Möller/Weiskopf12
Photometric Quantities
Quantities weighted by luminous efficiency function
Physicaldescription
Definition Symbol Units Photometric quantity (also “spectral *” [*/m])
Energy Qv [talbot] Luminous energy
Power / flux dQ/dt Φv [lm (lumens) = talbot/s]
Luminous power / flux
Flux density dQ/dAdt Ev [lux= lm/m2] Illuminance
Flux density dQ/dAdt [Mv=] Bv [lux] Luminosity
Angular flux density
dQ/dAΦdωdt Lv [lm/m2sr] Luminance
Intensity dQ/dωdt Iv [cd (candela)
= lm/sr]
Radiant / luminous intensity
© Machiraju/Möller
Ray Intersection AccelerationImage Synthesis
Mike Phillips Torsten Möller
© Machiraju/Möller
Reading
• “Physically Based Rendering” by Pharr&Humphreys– Chapter 2 - rays and transformations– Chapter 3 - shapes – Chapter 4 - intersections and acceleration
• “An Introduction to Ray tracing” by Glassner
© Machiraju/Möller
Topics today
• Review of ray-tracing• acceleration approaches
– pbrt– Object-space– World-space
15
© Machiraju/Möller
Review of ray-tracing
16
© Machiraju/Zhang/Möller17
First imaging algorithm• Directly derived from the synthetic
camera model– Follow rays of light from a point light
source – Determine which rays enter
the lens of the camera through the imaging window
– Compute color of projection• Why is this not a good idea?
© Machiraju/Zhang/Möller18
Ray tracing
• When following light from a light source, many (reflected) rays do not intersect the image window and do not contribute to the scene
Reverse the process Cast one ray per pixel from the eye and shoot it into the scene
raysreflected ray shadow
ray
refracted ray
Image plane
eye pixel
© Machiraju/Zhang/Möller19
Ray tracing: the basics• A point on an object may be illuminated
by– Light source directly – through shadow ray– Light reflected off an object – through
reflected ray– Light transmitted through a transparent
object – through refracted ray reflected ray shadow
ray
refracted ray
Image plane
eye pixel
© Machiraju/Zhang/Möller20
Ray tracing: the algorithmfor each pixel on screen determine ray from eye through pixel if ray shoots into infinity, return a background color if ray shoots into light source, return light color appropriately find closest intersection of ray with an object cast off shadow ray (towards light sources) if shadow ray hits a light source, compute light contribution according to some illumination model cast reflected and refracted ray, recursively calculate pixel color contribution return pixel color after some absorption
Most expensive
© Machiraju/Möller
• Shoot a ray through each pixel;• Find first object intersected by ray
• Compute ray. (More linear algebra.)• Compute ray-object intersection.• Spawn more rays for reflection and refraction
Image plane
Eye
Ray Tracing
© Machiraju/Möller
pbrt acceleration architecture
22
© Machiraju/Möller
Ray Tracing Architecture
Shape
Scene
Camera
Image
Material
Lights
intersect
Parse
Shadow, reflection, refraction rays
Eye raysRays
Surf
Primitives
Sample Generator
Film
Integrator
LRT
Radiance
TIFF
© Machiraju/Möller
Optimizing Ray Tracing• Main computation load is ray-object
intersection• 50-90% of run time when profiled• Test for possible intersection before
committing to computing intersections
© Machiraju/Möller25
Acceleration Strategies• Fast/efficient intersection computation (single ray-
single object)– Not much leeway for acceleration
• Test fewer rays– Trace fewer primary rays– Fewer secondary rays– Fewer intersection computations
• Intersection with “thick” rays– Cone tracing– Beam tracing
• Avoid computations with far away objects– Space partitioning– Direction partitioning
© Machiraju/Möller
Shape
Material
Lights
Primitives
Pbrt and Intersections• Primitive base class
• Shapes are subclasses of primitive
• Methods– WorldBound– CanIntersect– Intersect– IntersectP– Refine
• First four return Intersection structures
• Last returns Primitives
© Machiraju/Möller
Intersection Geometry• Shape independent representation for
intersections• DifferentialGeometry Intersection::dg
– Point P– Normal N– Parametric (u,v)– Partial derivatives
Tangents: dpdu, dpdv change in normal: dndu, dndv
© Machiraju/Möller
Object-Based Acceleration
• Reduce the intersection time for individual objects
• Objects can be complex!– must intersect all triangles
• But… we can quickly estimate if a ray could intersect the object
28
© Machiraju/Möller
Reduce ray path
Bounding Volumes• Surround object with a simple volume• Test ray against volume first• Test object-space or world-space bound? (pros and
cons)• Cost model - N*cb + pi*N*co – N (number of rays) is given
pi – fraction of rays intersecting bounding volume– Minimize cb (cost of intersecting bounding volume) and co
(cost of intersecting object)– Reduce ray path
• Bounding sphere– Difficult to compute good one– Easy to test for intersection
• Bounding box– Easy to compute for given object– More difficult to intersect
© Machiraju/Möller
Pbrt’s Bounding Boxes• Virtual BBox ObjectBound() const=0;• Virtual BBox WorldBound() const {
return ObjectToWorld(ObjectBound()); }
• Bool BBox::IntersectP(const Ray &ray, float *hitt0, float *hitt1) const { }
© Machiraju/Möller
Bounding Box• Compute min/max for x,y,z• 3 options
– Compute in world space• Chance of ill fitting b-box
– Compute in object space and transform w/ object• Object space b-box probably better fit than world space• Need to intersect ray with arbitrary hexagon in world sp.
– Compute in object space and test in object space• Inverse transform ray into object space
© Machiraju/Möller
Bounding Box
• Treat BB as three perpendicular slabs• Clip the ray against each slab
– if the clipped region is valid, then intersection!
32
© Machiraju/Möller
Bounding Box
• Find tnear and tfar for each pair of parallel planes. See PBRT p.194.
33
© Machiraju/Möller
Bounding Sphere
• Find min/max points in x,y,z -> 3 pairs• Use maximally separated pair to define
initial sphere• For each point
– If point is outside of current sphere, increase old sphere to just include new point
© Machiraju/Möller
P
P
C
R
rad P
P
newC
R
newrad
P
P
C
R
rad
newrad = (R+rad)/2
P
P
C
RnewC
newrad
newC = P+(newrad/R)(C-P)
© Machiraju/Möller
Bounding Sphere
• Intersection is very fast!– Does not need to be axis aligned
36
http://www.scratchapixel.com/lessons/3d-basic-rendering/minimal-ray-tracer-rendering-simple-shapes/ray-sphere-intersection
© Machiraju/Möller
Bounding Slabs• More complex to compute• Better fit of object• Use multiple pairs of parallel planes to bound object• Can add more slabs to get tighter fit
© 2004 Pharr, Humphreys
© Machiraju/Möller
Bounding Slabs
• Intersection is a generalization of the bounding box computation.
• Axis-aligned optimizations aren’t possible.• Potentially more slabs• In practice, rarely used
38
© Machiraju/Möller
More effort to compute, better fit
Approximate Convex Hull• Find highest vertex• Find plane through vertex parallel to ground plane• Find second vertex that makes minimum angle with first
vertex and up vector• Find third vertex that makes plane whose normal makes
minimum angle with up vector
© 1989 Glassner
© Machiraju/Möller
Convex Hull
• Intersection is fairly complex• Use a sidedness test for all planes• Rarely useful
40
© Machiraju/Möller
Bounding Volume Hierarchies• Create tree of bounding volumes• Children are contained within parent• Creation preprocess
– From model hierarchy– Automatic clustering
• Each object only appears in one leaf volume.
© Machiraju/Möller
Tree Organization
BVH - Issues
• Subtrees overlap• Does not contain all objects it overlaps • Balance
© Machiraju/Möller
BVH - Construction
• Take the bounding volume of the scene (or complex object)
• If too many primitive exist in the volume, create child volumes (split the volume)
• Recurse until the end criteria is met
43
© Machiraju/Möller
Splitting strategies• Choose the axis, that has
the largest spread of midpoints– Split based on the midpoint
of the centroids of one axis– Split in equal amounts
• Problem - overlaps
44
© Machiraju/Möller
The Surface Area Heuristic
• cost of intersecting all N primitives:
• cost of splitting into groups NA+NB = N
• ttrav - traversal time of node• pA / pB - prob that ray passes through
each child node45
NX
i=1
tisect(i)
© Machiraju/Möller
The Surface Area Heuristic
• assume, that tisect(i) is the same for all primitives• for convex objects A contained in B, the
probability of a ray intersecting A if it intersects B is:
• find the axis with the minimal SAH cost
46
p(A|B) =sAsB
© Machiraju/Möller47
© Machiraju/Möller
BVH• Intersection
intersect(node,ray,hits) { if( intersectp(node->bound,ray) if( leaf(node) ) intersect(nodeprims,ray,hits) else for each child intersect(child,ray,hits) } Return the closest of all hits !
48
© Machiraju/Möller
Spatial Subdivision
• Subdivide world space• Intersectable objects are place in spatial
“voxels”• A ray is traversed through the subdivisions
in the order of near to far• No overlapping voxels• …but objects may be in multiple voxels
49
© Machiraju/Möller
Uniform Grids
• Simplest spatial subdivision• Very easy to create and traverse• Good, but not optimal performance
– much better than brute force
50
© Machiraju/Möller
Uniform Grids • Preprocess scene• Find bounding box
© Machiraju/Möller
Uniform Grids• Preprocess scene• Find bounding box• Determine grid
resolution
© Machiraju/Möller
Uniform Grids• Preprocess scene• Find bounding box• Determine grid
resolution• Place object in cell
if its bounding box overlaps the cell
© Machiraju/Möller
AABB/Voxel Intersection• Easy to compute• Compute which voxel contains each vertex• All voxels between the min and max voxels
contain the AABB
54
© Machiraju/Möller
Uniform Grids• Preprocess scene• Find bounding box• Determine grid
resolution• Place object in cell
if its bounding box overlaps the cell
• Check that object overlaps cell (expensive!)
© Machiraju/Möller
Triangle/Voxel overlapSearch for a separating axis.1. [3 tests] e0 = (1, 0, 0), e1 = (0, 1, 0), e2 = (0, 0, 1) (the normals of the AABB). Test the AABB against the minimal AABB around the triangle.2. [1 test] n, the normal of ∆. We use a fast plane/AABB overlap test [5, 6], which only tests the two diagonal vertices, whose direction is most closely aligned to the normal of the triangle.3. [9 tests] aij = ei × fj , i, j ∈ {0, 1, 2}, where f0 = v1 − v0, f1 = v2 − v1, and f2 = v0 − v2. These tests are very similar and we will only show the derivation of the case where i = 0 and j = 0 (see below).
56
Tomas Akenine-Möller. 2005. Fast 3D triangle-box overlap testing. In ACM SIGGRAPH 2005 Courses (SIGGRAPH '05), John Fujii (Ed.). ACM, New York, NY, USA, , Article 8 . DOI=http://dx.doi.org/10.1145/1198555.1198747
© Machiraju/Möller
Add Sorting• If objects/voxels/cells are processed in
front-to-back sorted order along the ray, stop processing when first intersection is detected
© Machiraju/Möller
Spatial Subdivision
• Identifying voxels hit is like a line drawing algorithm
© Machiraju/Möller
Uniform Grids• Preprocess scene• Traverse grid
– 3D line = 3D-DDA
© Machiraju/Möller
Amanatides & Woo Algorithm
• J. Amanatides and A. Woo, "A Fast Voxel Traversal Algorithm for Ray Tracing", Proc. Eurographics '87, Amsterdam, The Netherlands, August 1987, pp 1-10.
© Machiraju/Möller
A&W AlgorithmX/Y/Z: Current voxel number.
stepX/Y/Z: 1 or -1. Is the slope +/-?
tMaxX/Y/Z: distance to cross next vert/horiz/depth plane.
tDeltaX/Y/Z: distance along ray to travel one whole width/height/depth of a voxel
Uniform Grid
Shirley P., Marschner S. “Fundamentals of Computer Graphics”
© Machiraju/Möller
A&W Algorithm Results
• Rendering time for different levels of subdivision
© Machiraju/Möller
Objects Across Multiple Voxels• Mailboxes
– mailboxes eliminate redundant intersection tests– objects have mailboxes – mailbox contains ID of last ray that intersected it– check ray against objects last tested ray ID
• Object splitting– Split objects at voxel
boundaries– Sub-objects only appear
in one voxel
© 1989 Glassner
© Machiraju/Möller
Uniform Grid• Complexity?• Problems?
65
© Machiraju/Möller
Uniform Grid
• Increase resolution– Increases traversal cost– May only need higher resolution in a small area
66
© Machiraju/Möller
Hierarchical Data structures
67
http://www.keithlantz.net/2013/04/kd-tree-construction-using-the-surface-area-heuristic-stack-based-traversal-and-the-hyperplane-separation-theorem/
© Machiraju/Möller
Comparison
Scheme Spheres (time)
Rings (time)
Tree (time)
Uniform grid D=1 244 129 1517
D=20 38 83 781
Hierarchical grid 34 116 34
• See “A Proposal for Standard Graphics Environments”, IEEE Computer Graphics and Applications, vol. 7, no. 11, November 1987, pp. 3-5
© Machiraju/Möller
Hierarchical Spatial Subdivision• Recursive subdivision of space• 1-1 Relationship between scene points and leaf nodes• Solves the lack-of-adaptivity problem• DDA works• Effective in practice
140.129.20.249/~jmchen/compg/slides/Octree%20Traversal.ppt
© Machiraju/Möller
Creating Spatial Hierarchiesinsert(node,prim) { if( overlap(node->bound,prim) )
if( leaf(node) ) {
if( node->nprims > MAXPRIMS && node->depth < MAXDEPTH ) {
subdivide(node); foreach child in node
insert(child,prim)
} else list_insert(node->prims,prim);
} else
foreach child in node
insert(child,prim) }
The interesting bit
Oct-Tree
Hughes J., et al. “Computer Graphics Principles and Practice”
© Machiraju/Möller
Oct-tree• Similar to a binary tree• Each node has 8 children• Always split the node in the middle of each axis• Allows fast skipping of empty space• Better efficiency than uniform grid, but still not
the best• Traversal is still relatively easy• Complexity?
72
© Machiraju/Möller
Oct-tree• Traversal can be implemented similar to 3D-DDA
– Use smallest voxel as a basis, and skip multiple while inside an internal node
• Top-down approach– Intersect root and find intersected children
recursively– http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.29.987
• Bottom-up approach– Find first leaf voxel intersected. Use neighbour
finding to find next voxels
73
© Machiraju/Möller
Binary Space Partitioning (BSP)
• General case uses arbitrary splitting planes• Space is partitioned into “half spaces”• All “bins” are convex• Difficult to build, traversal isn’t too bad• Generally not used for rendering (maybe for
physics simulation)• See: T. Ize, I. Wald and S. G. Parker, "Ray tracing with the BSP tree," Interactive
Ray Tracing, 2008. RT 2008. IEEE Symposium on, Los Angeles, CA, 2008, pp. 159-166. doi: 10.1109/RT.2008.4634637
74
© Machiraju/Möller KD tree
Octree
BSP tree
© Machiraju/Möller
KD-Tree
• A binary tree in K dimensions• Split one dimension at a time• Each node may only have 2 children• Easy to build and traverse• How to choose which dimension to split?• How to choose where to split?
76
© Machiraju/Möller
KD-tree
77
© Machiraju/Möller
KD-tree
78
• Use SAH to choose the split location. Same as BVH
© Machiraju/Möller
KD-tree
79
© Machiraju/Möller
KD-tree
• Traversal (stack) intersect with scene bounding box while no intersection && in the scene if node is a leaf intersect with all contained primitives else compute near and far child intersect with near child, push far child to a stack if no intersection, then pop a node from the stack continue until intersection, or exit the scene
80
© Machiraju/Möller81
© Machiraju/Möller
KD-tree• Other traversal cases:
– ray traverses the children in reverse order– ray starts inside the node– ray only intersects one child
• Fast traversal is very important– it will happen frequently– recursive is possible, but directly using a stack
can be faster• Complexity?
82
© Machiraju/Möller
KD-tree
• Possible improvements?• Stackless traversal!
– each voxel contains pointers to it’s neighbours– traverse the tree directly, without using a stack– avoid moving up and down the tree
unnecessarily– costs additional memory and precompute time– very good for highly parallel (GPU)
implementations83
© Machiraju/Möller
KD-tree
84
Popov, S., Günther, J., Seidel, H.-P. and Slusallek, P. (2007), Stackless KD-Tree Traversal for High Performance GPU Ray Tracing. Computer Graphics Forum, 26: 415–424. doi:10.1111/j.1467-8659.2007.01064.x
© Machiraju/Möller
Final Thoughts
• Acceleration structures have a HUGE influence on performance
• In practice BVH and KD-tree have similar performance
• Optimizations exist for both• Memory organization can have a big
performance impact. Especially for parallel computing
85
© Machiraju/Möller86
http://www.keithlantz.net/2013/04/kd-tree-construction-using-the-surface-area-heuristic-stack-based-traversal-and-the-hyperplane-separation-theorem/