Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Painting with Light

Painting with Light

Learn how to render beautiful images like Pixar and Disney using a simple algorithm called path tracing.
In this talk, we’ll trace the paths of billions of photons with Go on cheap cloud hardware.
Together, we’ll explore concurrency, the behavior of light, and the future of computer graphics.

hunterloftis

June 01, 2018
Tweet

More Decks by hunterloftis

Other Decks in Programming

Transcript

  1. @hunterloftis “There are more PhDs working on this film than

    any other in movie history.” - Steve Jobs, Pixar, 1995
  2. @hunterloftis Building a path tracer with Go In plain English

    ...with as little math as possible ...and just a touch of physics.
  3. @hunterloftis The physics have been done for us! Metals
 microfacet

    BRDF Non-metals
 microfacet + Oren-Nayar BRDFs Transparent materials
 microfacet BTDF + Beer's law ...car paint, hair, thin films, clouds, skin...
  4. @hunterloftis “Monte Carlo integration” Sample a bunch of values randomly.

    Add them all up and average them. That’s probably close to the real answer.
  5. @hunterloftis pprof.StartCPUProfile() File: pbr Type: cpu Time: May 31, 2018

    at 6:54pm (GMT) Duration: 7.08s, Total samples = 17.55s (248.00%) Showing nodes accounting for 16.94s, 96.52% of 17.55s total Dropped 58 nodes (cum <= 0.09s) github com/hunterloftis/pbr/surface (*Triangle) Intersect 8.03s (45.75%) of 12.91s (73.56%) github com/hunterloftis/pbr/surface (*Box) Check 5.11s (29.12%) 4.88s github com/hunterloftis/pbr (*sampler) tracePrimary 0.67s (3.82%) of 16.56s (94.36%) github com/hunterloftis/pbr (*Scene) Intersect 0.01s (0.057%) of 14.47s (82.45%) 1.57s github com/hunterloftis/pbr (*sampler) traceIndirect 0.17s (0.97%) of 13.65s (77.78%) 13.65s runtime newobject 0 of 0.80s (4.56%) 0.39s github com/hunterloftis/pbr/material (*Sample) Bsdf 0.02s (0.11%) of 0.23s (1.31%) 0.18s github com/hunterloftis/pbr/surface (*Triangle) At 0.01s (0.057%) of 0.43s (2.45%) 0.06s github com/hunterloftis/pbr (*sampler) start func1 0 of 16.56s (94.36%) 16.56s github com/hunterloftis/pbr/surface (*Tree) Intersect 0.14s (0.8%) of 14.46s (82.39%) 14.46s github com/hunterloftis/pbr/surface (*Tree) IntersectSurfaces 1.18s (6.72%) of 14.09s (80.28%) 12.91s 12.90s 0.13s 0.05s 0.37s 0.23s 14.09s runtime systemstack 0 of 1.07s (6.10%) runtime (*mcache) nextFree func1 0 of 0.79s (4.50%) 0.79s runtime entersyscallblock_handoff 0 of 0.12s (0.68%) 0.12s runtime gcBgMarkWorker func2 0 of 0.12s (0.68%) 0.12s runtime (*mheap) allocSpanLocked 0.68s (3.87%) of 0.70s (3.99%) runtime mallocgc 0 of 0.92s (5.24%) 0.80s runtime (*mcache) nextFree 0 of 0.79s (4.50%) 0.79s runtime profilealloc 0 of 0.12s (0.68%) 0.12s runtime main 0 of 0.69s (3.93%) main main 0 of 0.69s (3.93%) 0.69s github com/hunterloftis/pbr/surface newBranch 0 of 0.63s (3.59%) github com/hunterloftis/pbr/surface median 0.01s (0.057%) of 0.33s (1.88%) 0.33s github com/hunterloftis/pbr/surface overlaps 0.06s (0.34%) of 0.30s (1.71%) 0.30s runtime growslice 0 of 0.33s (1.88%) 0.12s runtime memmove 0.18s (1.03%) 0.15s math/rand (*Rand) Float64 0.04s (0.23%) of 0.09s (0.51%) 0.05s github com/hunterloftis/pbr/material (*Sample) diffuse 0 of 0.11s (0.63%) 0.11s github com/hunterloftis/pbr/material (*Map) At 0.14s (0.8%) of 0.41s (2.34%) 0.26s 0.09s sort Float64s 0 of 0.23s (1.31%) 0.23s 0.41s sort (*Float64Slice) Less 0.14s (0.8%) 0.24s runtime mach_semaphore_signal 0.12s (0.68%) runtime stkbucket 0.11s (0.63%) sort doPivot 0.04s (0.23%) of 0.22s (1.25%) 0.14s runtime scanobject 0.06s (0.34%) of 0.09s (0.51%) runtime timerproc 0 of 0.14s (0.8%) runtime notetsleepg 0 of 0.14s (0.8%) 0.14s github com/hunterloftis/pbr/surface NewTree 0 of 0.68s (3.87%) 0.02s 0.63s github com/hunterloftis/pbr/geom Direction RandHemiCos 0.01s (0.057%) of 0.11s (0.63%) 0.02s github com/hunterloftis/pbr/geom RandDirection 0 of 0.11s (0.63%) 0.08s runtime gcBgMarkWorker 0 of 0.13s (0.74%) 0.13s runtime gcDrain 0 of 0.12s (0.68%) 0.03s 0.09s 0.02s runtime entersyscallblock 0 of 0.12s (0.68%) 0.12s runtime mProf_Malloc 0.01s (0.057%) of 0.12s (0.68%) 0.11s github com/hunterloftis/pbr (*Render) Start 0 of 0.69s (3.93%) github com/hunterloftis/pbr (*Scene) prepare 0 of 0.69s (3.93%) 0.69s 0.68s 0.11s main iterativeRender 0 of 0.69s (3.93%) 0.69s main run 0 of 0.69s (3.93%) 0.69s 0.69s 0.79s runtime (*mcache) refill 0 of 0.79s (4.50%) 0.79s runtime (*mcentral) cacheSpan 0 of 0.79s (4.50%) 0.79s runtime (*mcentral) grow 0 of 0.79s (4.50%) 0.79s runtime (*mheap) alloc 0 of 0.76s (4.33%) 0.76s runtime (*mheap) alloc func1 0 of 0.74s (4.22%) 0.74s runtime (*mheap) alloc_m 0 of 0.74s (4.22%) 0.74s 0.70s 0.12s runtime handoffp 0 of 0.12s (0.68%) 0.12s 0.12s runtime startm 0 of 0.12s (0.68%) 0.12s runtime mach_semrelease 0 of 0.12s (0.68%) 0.12s runtime notewakeup 0 of 0.12s (0.68%) runtime semawakeup 0 of 0.12s (0.68%) 0.12s 0.12s 0.12s 0.12s sort Sort 0 of 0.23s (1.31%) 0.23s sort quickSort 0 of 0.23s (1.31%) 0.23s 0.22s github com/hunterloftis/pbr/surface (*Triangle) Intersect 8.03s (45.75%) of 12.91s (73.56%) github com/hunterloftis/pbr/surface (*Box) Check 5.11s (29.12%) 4.88s runtime newobject 0 of 0.80s (4.56%) github com/hunterloftis/pbr/surface (*Tree) IntersectSurfaces 1.18s (6.72%) of 14.09s (80.28%) 12.91s 0.23s 14.09s runtime systemstack 0 of 1.07s (6.10%) runtime mallocgc 0 of 0.92s (5.24%) 0.80s runtime (*mcache) nextFree 0 of 0.79s (4.50%) 0.79s runtime profilealloc 0 of 0.12s (0.68%) 0.12s runtime growslice 0 of 0.33s (1.88%) 0.12s 0.15s math/rand (*Rand) Float64 0.04s (0.23%) of 0.09s (0.51%) 0.05s 0.26s 0.09s 31%) 0.23s 0.24s %) 5%) runtime timerproc 0 of 0.14s (0.8%) runtime notetsleepg 0 of 0.14s (0.8%) 0.14s github com/hunterloftis/pbr/geom Direction RandHemiCos 0.01s (0.057%) of 0.11s (0.63%) 0.02s github com/hunterloftis/pbr/geom RandDirection 0 of 0.11s (0.63%) 0.08s runtime gcBgMarkWorker 0 of 0.13s (0.74%) 0.13s 0.02s runtime entersyscallblock 0 of 0.12s (0.68%) 0.12s runtime mProf_Malloc 0.01s (0.057%) of 0.12s (0.68%) 0.11s 0.79s 0.12s 0.12s 1%) 23s 1%) 23s 22s
  6. @hunterloftis An exciting, emerging field Research that hasn't been implemented

    yet "Embarrassingly parallel" algorithm Dominated by C++
  7. @hunterloftis I would love your help! Roadmap distributed concurrency glTF

    files, normal/displacement maps motion, participating media, subsurface scattering performance, better idiomatic Go, GPU support beautiful example scenes!