-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathraytracing.html
206 lines (194 loc) · 11.1 KB
/
raytracing.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
<!DOCTYPE html>
<html>
<head>
<link rel="canonical" href="https://hardmath123.github.io/raytracing.html"/>
<link rel="stylesheet" type="text/css" href="/static/base.css"/>
<title>They do it with Mirrors - Comfortably Numbered</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<meta charset="utf-8"/>
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
<link rel="alternate" type="application/rss+xml" title="Comfortably Numbered" href="/feed.xml" />
<!--
<script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.1/MathJax.js?config=TeX-AMS-MML_HTMLorMML"></script>
<script>
MathJax.Hub.Config({
tex2jax: {inlineMath: [['$','$']]}
});
</script>
-->
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/katex.min.css" integrity="sha384-Um5gpz1odJg5Z4HAmzPtgZKdTBHZdw8S29IecapCSB31ligYPhHQZMIlWLYQGVoc" crossorigin="anonymous">
<script defer src="https://cdn.jsdelivr.net/npm/[email protected]/dist/katex.min.js" integrity="sha384-YNHdsYkH6gMx9y3mRkmcJ2mFUjTd0qNQQvY9VYZgQd7DcN7env35GzlmFaZ23JGp" crossorigin="anonymous"></script>
<script defer src="https://cdn.jsdelivr.net/npm/[email protected]/dist/contrib/auto-render.min.js" integrity="sha384-vZTG03m+2yp6N6BNi5iM4rW4oIwk5DfcNdFfxkk9ZWpDriOkXX8voJBFrAO7MpVl" crossorigin="anonymous"></script>
<script>
document.addEventListener("DOMContentLoaded", function() {
renderMathInElement(document.body, {
// customised options
// • auto-render specific keys, e.g.:
delimiters: [
{left: '$$', right: '$$', display: true},
{left: '$', right: '$', display: false},
{left: '\\begin{align}', right: '\\end{align}', display: true},
{left: '\\(', right: '\\)', display: false},
{left: '\\[', right: '\\]', display: true}
],
// • rendering keys, e.g.:
throwOnError : false
});
});
</script>
</head>
<body>
<header id="header">
<script src="static/main.js"></script>
<div>
<a href="/"><span class="left-word">Comfortably</span> <span class="right-word">Numbered</span></a>
</div>
</header>
<article id="postcontent" class="centered">
<section>
<h1>They do it with Mirrors</h1>
<center><em><p>An idealized transcript of a talk I gave.</p>
</em></center>
<h4>Monday, June 1, 2015 · 4 min read</h4>
<blockquote>
<p>This is an idealized transcript of a talk I gave a couple weeks ago at our
school’s “Engineering Night”, an event where students are invited to speak
and get others excited about engineering. I’m putting this up here because
it makes a great blog post, and because I want to be able to come back and
find these ideas in the future.</p>
</blockquote>
<hr>
<p>When I was five, my parents took me to go see <em>Finding Nemo</em>. It’s an amazing
movie, except when you’re five, all you really process are terrifying scenes
like this one.</p>
<p><img src="static/slides/shark.jpg" alt=" "></p>
<p>So we didn’t really go out for many movies after that.</p>
<p>The next one I remember seeing was in the fifth grade, actually, with my best
friend. We went to see <em>Cloudy With a Chance of Meatballs</em>.</p>
<p><img src="static/slides/cloudy.jpg" alt=" "></p>
<p>I loved it. Not just the story—the pictures. I loved how everything was so
realistic. I mean, I was told that these movies are computer-generated, but I
felt that I could reach out and touch those hair, or poke the huge mound of
Jell-O.</p>
<p>So when I got back, I wondered “how do you do it?” and like any fifth grader, I
came up with an explanation. I’d been watching NOVA, so I had heard of these
things called “photons” which are like tiny golf balls. And so my explanation
was that computers shoot these golf balls into a 3D model just like how you can
shoot bullets in Halo and Counter-Strike. And by knowing how these golf balls
bounced around, you could figure out what things looked like.</p>
<p>Yeah, it’s silly. But when I was in fifth grade, I also thought I could stick
out my hand under the sun and catch some photons like rain, and if I collected
enough I could drink them like any other liquid. I tried this, and it didn’t
work, and when I asked my teachers they told me I was watching too much NOVA.</p>
<p>And I don’t mind. I had an idea, I tested it, it didn’t work, and I wondered
why. As far as I’m concerned, that’s as close as I’ve ever gotten to the
“scientific method” that they teach you at school.</p>
<p>In any case, I ended up getting really lucky. Out science teacher used to order
these Scholastic magazines. They were mostly advertisements for books, but some
of them had short articles about new science.</p>
<p><img src="static/slides/scholastic.jpg" alt=" "></p>
<p>That week’s magazine actually had an article about <em>Cloudy With a Chance of
Meatballs</em>. And it explained… nothing, actually. It was a thinly veiled
advertisement. But it <em>did</em> have a link to a website called Scratch.</p>
<p>Scratch might be one of the best things to ever happen to me. It’s a website
that’s sort of analogous to YouTube, except instead of videos, you can upload
small programming projects, like Flash games. Scratch comes with its own really
simple programming language, and some of you in the audience might have already
used it if you took a CS class here.</p>
<p><img src="static/slides/14scratch.png" alt=" "></p>
<p>I loved Scratch. Over then next two years, I made games, stories, and—most
importantly—friends I still talk to today.</p>
<p>I, of course, forgot this whole 3D movie thing completely.</p>
<hr>
<p>…until one day, <em>Ratatouille</em> was on, and I remembered again.</p>
<p><img src="static/slides/ratatouille.jpg" alt=" "></p>
<p>Look at the water splashing next to Remy’s head. You can see the wall through
it. But it distorts the wall a bit. It’s called “refraction”.</p>
<p>If you asked me to draw this, I would have no idea how the water distorted the
wall. But when I look at this, it looks right. Somehow, the computers know how
this all works.</p>
<p>At this point, I was old enough to find things out for myself. So I Googled it.</p>
<p>It turns out that to make these movies, computers fire these tiny little balls,
like golf balls, into a 3D model. By seeing how the balls bounce, they can
figure out how the model looks.</p>
<p>It’s called “raytracing”, and it’s a serious academic subject, not a silly idea
a fifth grader came up with in the shower.</p>
<p><img src="static/slides/raytrace.png" alt=" "></p>
<p>So of course I wanted to know more. The first thing I learned was that when
they say “computer-generated movie”, what they mean is “supercomputer-generated
movie”. This is the supercomputer that rendered <em>Cars</em>. <em>Cars</em> has a running
time just short of two hours and was rendered at 25 frames per second.</p>
<p>Guess how long it took to render a frame?</p>
<p><img src="static/slides/farm.jpg" alt=" "></p>
<p>Seven hours.</p>
<p>As technology improves, it takes us <em>longer</em> to render movies because we’re
getting so focused on detail. We’re simulating individual particles in an
ocean, and individual strands of hair.</p>
<hr>
<p>So I was entranced. I wanted to know more. And at this point, the only way to
learn more was to do it myself. So I did.</p>
<p><img src="static/slides/shiny.png" alt=" "></p>
<p>I’m so proud of this picture. It represents so much to me.</p>
<hr>
<p>Of course, my story didn’t end there. It ended in math class this year,
battling this monster.</p>
<p><img src="static/slides/cross.gif" alt=" "></p>
<p>This is the “cross product”. If you haven’t touched it yet, you’re lucky. It’s
the determinant of a matrix, except, some of its entries aren’t even numbers,
they’re vectors. And if you’re <em>really</em> lucky, you get <em>two</em> possible answers.</p>
<p>And to guess which one is right, you need to make gang signs. This is the
“right-hand rule”, and basically, everyone looks really funny doing this when
taking a test.</p>
<p><img src="static/slides/rhrule.png" alt=" "></p>
<hr>
<p>Something about this bothered me. And when I got home, I finally realized it.</p>
<p>These lines of code are—unaltered—from my raytracer.</p>
<p><img src="static/slides/direction.png" alt=" "></p>
<p>Looks familiar? It’s the cross product!</p>
<p>I wrote those lines of code in seventh grade. I had no idea what a vector was.
I don’t know how I got those equations—I just remember doing lots of algebra
on paper and somehow getting them.</p>
<p>And suddenly it all made sense to me. All this math we’re learning? It’s
<em>useful</em>. You know why the cross product has two answers? Well, the cross
product essentially says “if the ground is sloped this way, which direction
points away from the ground?”. You use it to say “which way should a photon
bounce when it’s bouncing away from a surface”.</p>
<p>Well, there are <em>two</em> directions away from the ground! You can go up into the
sky or you can drill down into the Earth. And so the two answers just point in
opposite directions. It makes sense!</p>
<hr>
<p>What I’m trying to say is, you don’t need to take 10th grade math to make
something cool. Every single one of you in the audience here is completely
capable of creating something incredible. So what are you waiting for? Taking
that Stanford course on fluid dynamics someday? You don’t need it.</p>
<p>Every single one of you has so much knowledge right in front of you: the
Internet, libraries, and brilliant teachers everywhere. So stop waiting until
you’re “ready”, and go build something.</p>
</section>
<div id="comment-breaker">◊ ◊ ◊</div>
</article>
<footer id="footer">
<div>
<ul>
<li><a href="https://github.com/kach">
Github</a></li>
<li><a href="feed.xml">
Subscribe (RSS feed)</a></li>
<li><a href="https://twitter.com/hardmath123">
Twitter</a></li>
<li><a href="https://creativecommons.org/licenses/by-nc/3.0/deed.en_US">
CC BY-NC 3.0</a></li>
</ul>
</div>
<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-46120535-1', 'hardmath123.github.io');
ga('require', 'displayfeatures');
ga('send', 'pageview');
</script>
</footer>
</body>
</html>