Refracon of a Causc

• Monte‐Carlo handles all paths of light: L(D|S)*E, but not equally well • Has difficulty sampling LS*DS*E paths, Photon Mapping e.g. refracon of a causc • would need a very lucky first hit • Bidireconal ray tracing can find Jan Kautz causc, but reflecon of causc sll needs lucky first hit during path tracing

Featuring images swiped from Henrik Wann Jensen

Photon Mapping Why Map Photons?

• Jensen EGRW 95, 96 • High variance in Monte‐Carlo • Simulates the transport of individual renderings results in noise photons • Collecon of deposited photons • Photons emied from light sources into a “photon map” (a 3‐D • Photons bounce off of specular spaal data structure) provides a surfaces flux density esmate The scene above contains glossy surfaces, and was rendered in 50 • Photons deposited on diffuse surfaces • Flux samples filtered easier than – Held in a 3‐D spaal data structure minutes using photon mapping. The path samples, resulng in error at same scene took 6 hours for render – Surfaces need not be parameterized lower frequencies with Radiance, a rendering system that • Photons collected by path tracing from used radiosity for diffuse reflecon and eye • Error is a result of bias, which decreases as the number of path tracing for glossy reflecon. samples increase • And, oh yeah, it’s a lot faster

What is a Photon? Sources

ωp • A photon p is a parcle of light • Point source that carries flux ΔΦp(xp, ωp) – Photons emied uniformly in all – Power: ΔΦp – magnitude (in direcons Was) and color of the flux it • ΔΦp Power of source (W) distributed carries, stored as an RGB triple evenly among photons – Posion: xp – locaon of the • photon xp Flux of each photon equal to source power divided by total # of photons – Direcon: ω – the incident p • direcon ωi used to compute For example, a 60W light bulb would irradiance send out a total of 100K photons, • Photons vs. rays each carrying a flux ΔΦ of 0.6 mW – Photons propogate flux • Photons sent out once per simulaon, – Rays gather radiance not connuously as in radiosity

1 Mixed Surfaces Russian Roulee ? • Surfaces have specular and • Arvo & Kirk, S90

diffuse components ρd = 50% • Reflected flux only a fracon of = 30% incident flux – ρ – diffuse reflectance ρs d • Aer several reflecons, spending – ρs – specular reflectance a lot of me keeping track of very – ρd + ρs < 1 (conservaon of lile flux energy) • Instead, completely absorb some • Let ζ be a uniform random value photons and completely reflect from 0 to 1 others at full power • Spend me tracing fewer full • If ζ < ρd then reflect diffuse power photons • Else if ζ < ρd + ρs then reflect • Probability of reflectance is the specular reflectance ρ. ρ = 60% • Otherwise absorb • Probability of absorpon is 1 – ρ.

Storing Photons K‐D Tree

• Uses a kd‐tree – a sequence of axis‐ aligned parons • Given a large number of points p1,…,pn in 3D – 2‐D parons are lines space we want to classify them and be able to – 3‐D parons are planes • Axis of parons alternates wrt make fast queries: depth of the tree – • Average access me is O(log n) Find all the points within a cuboid • Worst case O(n) when tree is – Find all the points within a neighbourhood of a severely lopsided • Need to maintain a balanced tree, given point which can be done in O(n log n) • These points are photon posions on surfaces. • Can find k nearest neighbors in O(k + log n) me using a heap

K‐D Tree K‐D Tree

• • A K‐D tree is just an axis aligned BSP tree. Write pi = (x1i, x2i, x3i) • Let xj* be the median of the values of the jth coordinate • Each node of the tree stores a separang (j=1,2,3). • Start with x1* which will paron the original set of points plane, defined by the median value along one into two sets (divided along the X axis). of the coordinates. • Now apply the same procedure to each of the le‐ and right‐ sets, except now subdivide on x2* • The leaves of the tree contain the original data • Now apply the same procedure recursively to each of these points. subsets except now subdivide on x3* • Keep applying this recursively unl each leaf of the tree contains a data point.

2 K‐D Tree 2D Example K‐D Tree 2D Example

K‐D Tree 2D Example K‐D Tree Code

KDTree makeKDTree(int n, point_kd p[], int depth) /*returns a kd-tree for the n 3-dimensional points in p - assume all indices start from 1*/ { if n==1 return a leaf containing p[1]; /*base case*/

x = median of values of (depth mod 3) coordinate in the points; pLeft is the set of points to the left of x and pRight is the set to the right;

leftNode = makeKDTree(n/2,pLeft,depth+1); rightNode = makeKDTree(n/2,pRight,depth+1); /*assumes that the median splits the points exactly in two*/

/*compose a new node and return*/ return compose(leftNode,x,rightNode); }

K‐D Tree Advantages Reflected Radiance

• Using a K‐D tree soluon does not depend on • Recall the reflected radiance equaon the providing a mesh on the surfaces – the ΔA = πr2 distribuon of the photons is maintained independently of the representaon of the • Convert incident radiance into incident flux surfaces • The method does not rely on ‘regular’ surfaces • Reflected radiance in terms of incident flux such as polygons, but could equally well apply to fractal type surfaces. • Numerically

3 How Many Photons? Filtering

• How big is the disk radius r? • Too few photons cause blurry • Large enough that the disk results surrounds the n nearest • Simple averaging produces a box photons. Radiance esmate using 50 photons filtering of photons • The number of photons used for • Photons nearer to the sample a radiance esmate n is usually between 50 and 500. should be weighted more heavily • Results in a cone filtering of photons

ΔA = πr2 Radiance esmate using 500 photons

Mulple Photon Maps Rendering

• Global L(S|D)*D photon map • Rendered by glossy‐surface distributed ray tracing – Photon scks to diffuse surface and bounces to next surface (if • When ray hits first diffuse it survives Russian roulee) surface… – Compute direct illuminaon – Photons don’t sck to specular map Global map – Compute reflected radiance surfaces photons photons of causc map photons First diffuse intersecon. Use global – Ignore global map photons Return radiance of causc map • Causc LSS*D photon map map photons here, but – Importance sample BRDF f photons to – High resoluon r ignore global map photons return as usual radiance – Light source usually emits – Use global photon map to when photons only in direcons that importance sample incident evaluang hit the thing creang the causc radiance funcon Li Li at first – Evaluate reflectance integral diffuse by casng rays and intersecon accumulang radiances from . global photon map

www.bennolan.com www.bennolan.com Examples Examples

Direct Illuminaon Global Photon Map

4 www.bennolan.com www.bennolan.com Examples Examples

Indirect Illuminaon Final Rendering

Photon Map Example Photon Map Example

http://www.vrayrender.com/stuff/PMapTutorial/ http://www.vrayrender.com/stuff/PMapTutorial/

Photon Mapping

• One of the recent of the established global illuminaon soluons • Has a pre‐rendering phase to esmate global illuminaon • A path tracing phase for the final rendering (final gathering) • It is significantly faster than path tracing (minutes compared to hours), and the pre‐rendering phase only has to be done once. • Most me goes into the final rendering phase, and in parcular in esmang the radiance from nearby photons.

5