-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathpresentation.html
executable file
·490 lines (481 loc) · 19.2 KB
/
presentation.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
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
<!DOCTYPE HTML>
<html lang="en">
<head>
<title>Safari in Safari</title>
<meta charset="utf-8">
<meta name="viewport" content="width=792, user-scalable=no">
<meta http-equiv="x-ua-compatible" content="ie=edge">
<link rel="stylesheet" href="shower/themes/ribbon/styles/screen.css">
<style>
.slide .right, .slide.cover .right {
height: 100%;
width: 25%;
top: 0;
left: auto;
right: 0;
position: absolute;
}
.threejs-container {
color: grey;
font-size: 10pt;
position: absolute;
right: 0;
bottom: 0;
height: 100%;
width: 100%;
}
.threejs-container canvas {
background: black;
position: absolute;
left: 0;
top: 0;
right: 0;
}
.tiny {
position: absolute;
right: 2%;
bottom: 3%;
height: 200px;
width: 200px;
box-shadow: 2px 2px 10px black;
}
.tiny-top {
position: absolute;
right: 2%;
top: 3%;
height: 200px;
width: 200px;
box-shadow: 2px 2px 10px black;
}
.small {
position: absolute;
right: 2%;
bottom: 3%;
height: 40%;
width: 40%;
box-shadow: 2px 2px 10px black;
}
.small-top {
position: absolute;
right: 2%;
top: 3%;
height: 40%;
width: 40%;
box-shadow: 2px 2px 10px black;
}
.medium {
position: absolute;
right: 2%;
bottom: 3%;
height: 50%;
width: 96%;
box-shadow: 2px 2px 10px black;
}
.tiny, .tiny-top, .small-top, .small, .medium {
background-color: white;
}
.tiny:hover, .tiny-top:hover, .small-top:hover, .small:hover, .medium:hover {
position: absolute;
right: 2%;
bottom: 3%;
height: 94%;
width: 96%;
}
.slide code {
font-size: 16pt;
}
.fullscreen h2 {
margin:10px 0 0;
color:#FFF;
text-align:center;
font-size:80px;
text-shadow: 1px 1px 7px #000;
}
.fullscreen p {
margin:10px 0 0;
text-align:center;
color:#FFF;
font-style:italic;
font-size:30px;
text-shadow: 1px 1px 7px #000;
}
.fullscreen p a {
color:#FFF;
}
.fullscreen img {
height:100%;
}
</style>
</head>
<body class="list">
<header class="caption">
<h1>Safari in Safari - An Introduction to 3D content on the Web</h1>
<p>Felix Palmer | @pheeelicks | www.pheelicks.com</p>
</header>
<section class="slide cover fullscreen"><div>
<h2>Safari in Safari - An Introduction to 3D content on the Web</h2>
</br>
<p>Felix Palmer | @pheeelicks | www.pheelicks.com</p>
<p>Slides: <a href="http://felixpalmer.github.io/safari-webgl/presentation.html">felixpalmer.github.io/safari-webgl/presentation.html</a></p>
<p>Code: <a href="https://github.com/felixpalmer/safari-webgl">github.com/felixpalmer/safari-webgl</a></p>
<div id="threejs-container" class="threejs-container">Loading...</div>
</div></section>
<section class="slide"><div>
<h2>Overview</h2>
<ul>
<li>What is THREE.js?</li>
<li>How do I build this thing?</li>
<li>Bringing it to life</li>
<li>Under the hood</li>
</ul>
</br>
</br>
<p>Slides: <a href="http://felixpalmer.github.io/safari-webgl/presentation.html">felixpalmer.github.io/safari-webgl/presentation.html</a></p>
<div class="threejs-container small-top">Loading...</div>
</div></section>
<section class="slide"><div>
<h2>Why WebGL?</h2>
<ul>
<li>Accessible 3D for all</li>
<li>Excellent support across browsers now</li>
<li>Combination of JavaScript & GLSL very effective</li>
</ul>
<p>Some examples: <a href="http://threejs.org">http://threejs.org</a></p>
<img class="right" src="pictures/sidebar.png" alt="">
</div></section>
<section class="slide"><div>
<h2>THREE.js overview</h2>
<ul>
<li>High level library for rendering 3D content</li>
<li>Base class in 3D world is <strong>Object3D</strong></li>
<li>Most of the time we use a <strong>Mesh</strong></li>
<li>A <strong>Mesh</strong> is defined by a:</li>
<ul>
<li><strong>Geometry</strong> - a collection of vertices defining the shape</li>
<li><strong>Material</strong> - defines how the surface is to be drawn</li>
</ul>
</ul>
<div class="threejs-container small-top">Loading...</div>
</div></section>
<section class="slide"><div>
<h2>Scene graph</h2>
<ul>
<li><strong>Meshes</strong> can be positioned, rotated, scaled etc</li>
<li><strong>Meshes</strong> can be grouped by adding them to an <strong>Object3D</strong></li>
<li>To actually display <strong>Object3Ds</strong>, we add them to a <strong>Scene</strong></li>
</ul>
<img class="right" src="pictures/sidebar.png" alt="">
</div></section>
<section class="slide"><div>
<h2>Rendering a Scene</h2>
<ul>
<li>To actually show something on screen, need a:</li>
<ul>
<li><strong>Camera</strong> to view the <strong>Scene</strong> through</li>
<li><strong>Renderer</strong> to render into a canvas in the DOM</li>
</ul>
</ul>
<img class="right" src="pictures/sidebar.png" alt="">
</div></section>
<section class="slide"><div>
<h2>Hello (3D) World</h2>
<code>var geom = new THREE.PlaneGeometry( 600, 600 );</code></br>
<code>var material = new THREE.MeshBasicMaterial();</code></br>
<code>var mesh = new THREE.Mesh( geom, material );</code></br>
<code>scene.add( mesh );</code></br>
</br>
<code>var camera = new THREE.PerspectiveCamera( 70 );</code></br>
<code>scene.add( camera );</code></br>
<code>var renderer = new THREE.WebGLRenderer();</code></br>
<img class="right" src="pictures/sidebar.png" alt="">
</div></section>
<section class="slide"><div>
<h2>THREE.js - The macro and the micro</h2>
<ul>
<li>3D graphics is pretty involved. THREE.js lets you:</li>
<ul>
<li>focus on the high level content (JavaScript land)</li>
<li>...with the access to the low level function (GLSL land)</li>
<li>...while handling all the fiddly bits in between</li>
</ul>
</ul>
<img class="right" src="pictures/sidebar.png" alt="">
</div></section>
<section class="slide"><div>
<h2>How do I build this thing?</h2>
<ul>
<li><strong>Geometries</strong></li>
<li><strong>Materials</strong></li>
</ul>
<div class="threejs-container medium">Loading...</div>
</div></section>
<section class="slide"><div>
<h2>Geometry</h2>
<ul>
<li><strong>Scene</strong> is composed of a collection of <strong>Meshes</strong></li>
<li>Each has a <strong>Geometry</strong></li>
<li>Can be shared, e.g. needle is actually 2 <strong>Meshes</strong> with same <strong>Geometry</strong></li>
</ul>
<div class="threejs-container small">Loading...</div>
</div></section>
<section class="slide"><div>
<h2>Geometry - Sphere</h2>
<code>new THREE.SphereGeometry( 1, 32, 32 );</code></br>
<div class="threejs-container medium">Loading...</div>
</div></section>
<section class="slide"><div>
<h2>Geometry - Torus</h2>
<code>new THREE.TorusGeometry( 1.3, 0.1, 16, 32 );</code></br>
<div class="threejs-container medium">Loading...</div>
</div></section>
<section class="slide"><div>
<h2>Geometry - Lathe</h2>
<code>var flatRingRadius = 3.33;</code></br>
<code>var flatRingPoints = [</code></br>
<code> new THREE.Vector3( flatRingRadius + 0.1, 0, 0 ),</code></br>
<code> new THREE.Vector3( flatRingRadius - 0.1, 0, 0 )</code></br>
<code>];</code></br>
<code>var flatRing = new THREE.LatheGeometry( flatRingPoints, 64 );</code></br>
<div class="threejs-container small-top">Loading...</div>
</div></section>
<section class="slide"><div>
<h2>Geometry - Path-based</h2>
<code>var path = new THREE.Path();</code></br>
<code>ringPath.moveTo( 0, 0 );</code></br>
<code>ringPath.lineTo( 1, 0 );</code></br>
<code>ringPath.absarc( 1, 0, 1, 0, Math.PI, true )</code></br>
<code>...</code></br>
<code>var points = ringPath.getPoints( 24, true );</code></br>
<code>var ring = new THREE.LatheGeometry( vectors, 128 );</code></br>
<div class="threejs-container small-top">Loading...</div>
</div></section>
<section class="slide"><div>
<h2>Geometry - Text</h2>
<code>new THREE.TextGeometry( "E", { size: 2, height: 0.04 } );</code></br>
<div class="threejs-container medium">Loading...</div>
</div></section>
<section class="slide"><div>
<h2>Material</h2>
<ul>
<li>Each <strong>Mesh</strong> in the <strong>Scene</strong> also has a <strong>Material</strong></li>
<li>As with <strong>Geometries</strong>, <strong>Materials</strong> can be shared</li>
</ul>
<div class="threejs-container small">Loading...</div>
</div></section>
<section class="slide"><div>
<h2>Material - Wireframe</h2>
<code>wire = new THREE.MeshBasicMaterial( { wireframe: true } )</code></br>
<div class="threejs-container medium">Loading...</div>
</div></section>
<section class="slide"><div>
<h2>Material - Basic</h2>
<code>basic = new THREE.MeshBasicMaterial( { color: "#00ff00" } )</code></br>
<div class="threejs-container medium">Loading...</div>
</div></section>
<section class="slide"><div>
<h2>MeshPhongMaterial</h2>
<code>new THREE.MeshPhongMaterial( {</code></br>
<code> color: new THREE.Color( "#1557fb" ),</code></br>
<code> emissive: new THREE.Color( "#232323" ),</code></br>
<code> specular: new THREE.Color( "#ccccff" ),</code></br>
<code> shininess: 40</code></br>
<code>} );</code></br>
<div class="threejs-container small-top">Loading...</div>
</div></section>
<section class="slide"><div>
<h2>MeshStandardMaterial</h2>
<code>new THREE.MeshStandardMaterial( {</code></br>
<code> color: new THREE.Color( "#1557fb" ),</code></br>
<code> emissive: new THREE.Color( "#232323" ),</code></br>
<code> metalness: 1.0,</code></br>
<code> roughness: 0.6</code></br>
<code>} );</code></br>
<div class="threejs-container small-top">Loading...</div>
</div></section>
<section class="slide"><div>
<h2>Textured Materials</h2>
<code>new THREE.MeshPhongMaterial( {</code></br>
<code> map: texture.wood,</code></br>
<code> ...</code></br>
<code>} ),</code></br>
<div class="threejs-container small-top">Loading...</div>
<img class="tiny" src="js/textures/wood.jpg">
</div></section>
<section class="slide"><div>
<h2>Environment maps</h2>
<ul>
<li>Used for reflective objects</li>
<li>Acts like mirror onto environment map</li>
</ul>
<code>new THREE.MeshPhongMaterial( {</code></br>
<code> envMap: texture.sky,</code></br>
<code> ...</code></br>
<code>} ),</code></br>
<div class="threejs-container small-top">Loading...</div>
<img class="tiny" src="js/textures/sky.jpg">
</div></section>
<section class="slide"><div>
<h2>Bump maps</h2>
<ul>
<li>For adding small-scale deformations</li>
<li>Bump scale determines roughness</li>
<li>Bump map texture describes deformation of surface</li>
</ul>
<code>new THREE.MeshPhongMaterial( {</code></br>
<code> bumpMap: texture.brushed,</code></br>
<code> bumpScale: 0.003,</code></br>
<code> ...</code></br>
<code>} ),</code></br>
<div class="threejs-container small-top">Loading...</div>
<img class="tiny" src="js/textures/brushed.png">
</div></section>
<section class="slide"><div>
<h2>Transparency - Blending</h2>
<code>new THREE.MeshPhongMaterial( {</code></br>
<code> transparent: true,</code></br>
<code> opacity: 0.95,</code></br>
<code> blending: THREE.AdditiveBlending,</code></br>
<code> combine: THREE.MixOperation,</code></br>
<code> envMap: texture.sky,</code></br>
<code> reflectivity: 0.29,</code></br>
<code> ...</code></br>
<div class="threejs-container small">Loading...</div>
</div></section>
<section class="slide"><div>
<h2>Bringing it to life</h2>
<ul>
<li>Lights & shadows</li>
<li>Camera & interactivity</li>
</ul>
<div class="threejs-container medium">Loading...</div>
</div></section>
<section class="slide"><div>
<h2>Lights</h2>
<ul>
<li>Just like adding any other object to scene</li>
<li>Use SpotLight to cast shadows</li>
<li>Interacts with Materials</li>
</ul>
<code>var light = new THREE.SpotLight( 0xffffff, 1, 0 );</code></br>
<code>light.position.set( 25, -20, 20 );</code></br>
<code>light.target.position.set( 0, 0, 0 );</code></br>
<code>light.castShadow = true;</code></br>
<div class="threejs-container small-top">Loading...</div>
</div></section>
<section class="slide"><div>
<h2>Interactivity</h2>
<ul>
<li>Periodically change something, and re-render scene</li>
<li>Use <code>requestAnimationFrame</code> rather than <code>setTimeout</code></li>
</ul>
<code>app.tick = function() {</code></br>
<code> app.render();</code></br>
<code> window.requestAnimationFrame( app.tick );</code></br>
<code>}</code></br>
<code>app.tick();</code></br>
<img class="right" src="pictures/sidebar.png" alt="">
</div></section>
<section class="slide"><div>
<h2>Moving the <strong>Camera</strong></h2>
<ul>
<li><strong>Camera</strong> is also an <strong>Object3D</strong>, and can be moved/rotated</li>
<li>Code below zooms <strong>Camera</strong> in and out</li>
</ul>
<code>app.clock = new THREE.Clock( true );</code></br>
<code>app.render = function() {</code></br>
<code> var t = 0.2 * app.clock.getElapsedTime();</code></br>
<code> var r = 15.0 + 12.0 * Math.cos( 0.3 * t );</code></br>
<code> camera.position = new THREE.Vector3( 0, 0, r );</code></br>
<code> ...</code></br>
<img class="right" src="pictures/sidebar.png" alt="">
</div></section>
<section class="slide"><div>
<h2>Looking at Objects</h2>
<ul>
<li>Simplest way set correct <strong>Camera</strong> orientation</li>
</ul>
<code>app.render = function() {</code></br>
<code> ...</code></br>
<code> camera.position = camPosition;</code></br>
<code> camera.up = new THREE.Vector3( 0, 0, 1 );</code></br>
<code> camera.lookAt( new THREE.Vector3( 1, 2, 3 ) );</code></br>
<code>};</code></br>
<img class="right" src="pictures/sidebar.png" alt="">
</div></section>
<section class="slide"><div>
<h2>Camera Orbiting</h2>
<ul>
<li>Orbital motion with changing height</li>
</ul>
<code>var r = 15.0 + 12.0 * Math.cos( 0.3 * t );</code></br>
<code>camera.position = new THREE.Vector3(</code></br>
<code> r * Math.sin( t ), // Orbital motion</code></br>
<code> r * Math.cos( t ), // Orbital motion</code></br>
<code> 12.0 + 5.0 * Math.cos( 1.3 * t ) // Height</code></br>
<code>);</code></br>
<div class="threejs-container small-top">Loading...</div>
</div></section>
<section class="slide"><div>
<h2>User Input</h2>
<ul>
<li>Hook into mouse/keyboard events</li>
<li>Can move any <strong>Object3D</strong> instances on stage in same way</li>
</ul>
<div class="threejs-container medium">Loading...</div>
</div></section>
<section class="slide"><div>
<h2>Under the hood</h2>
<ul>
<li>Vertex shaders (geometry)</li>
<li>Fragment shaders (material)</li>
<li>Graphics pipeline</li>
</ul>
<img class="right" src="pictures/sidebar.png" alt="">
</div></section>
<section class="slide"><div>
<h2>Vertex shader</h2>
<code>attribute vec2 aCoordinate;</code></br>
<code>varying vec2 vCoordinate;</code></br>
<code>void main() {</code></br>
<code> vCoordinate = aCoordinate;</code></br>
<code> gl_Position = vec4( aCoordinate, 0, 1 );</code></br>
<code>}</code></br>
<img class="tiny" src="pictures/vertex.svg">
</div></section>
<section class="slide"><div>
<h2>Fragment shader</h2>
<code>varying vec2 vCoordinate;</code></br>
<code>void main() {</code></br>
<code> gl_FragColor = vec4( vCoordinate, 0.0, 1.0 );</code></br>
<code>}</code></br>
<img class="small" src="pictures/fragment.svg">
</div></section>
<section class="slide"><div>
<h2>Pipeline</h2>
<ul>
<li>3 types of variables to pass around data:</li>
<ol>
<li><code>uniform</code> global information</li>
<li><code>varying</code> flow from vertex to fragment shader, interpolated</li>
<li><code>attribute</code> per vertex information</li>
</ol>
</ul>
<img class="small" src="pictures/pipeline.svg">
</div></section>
<section class="slide shout"><div>
<h2>DEMO</h2>
</div></section>
<section class="slide cover fullscreen" id="Thanks"><div>
<h2>Thanks</h2>
</br>
<p>Felix Palmer | @pheeelicks | www.pheelicks.com</p>
<p>Slides: <a href="http://felixpalmer.github.io/safari-webgl/presentation.html">felixpalmer.github.io/safari-webgl/presentation.html</a></p>
<p>Code: <a href="https://github.com/felixpalmer/safari-webgl">github.com/felixpalmer/safari-webgl</a></p>
<div id="threejs-container" class="threejs-container">Loading...</div>
</div></section>
<div class="progress"></div>
<script src="shower/shower.min.js"></script>
<script src="js/config.js"></script>
<script data-main="../presentation" src="js/require.js"></script>
</body>
</html>