Fireship · @fireship

WebGL 3D Graphics Explained in 100 Seconds

Uploaded May 12, 2021 · Length 2:07

WebGL 3D Graphics Explained in 100 Seconds

Summary

webgl 3d graphics explained in 100 seconds, including rendering pipeline and gpu acceleration.

  • webgl
  • 3d graphics
  • gpu acceleration
  • javascript api
  • opengl
  • 3js

Transcript preview

The first 2 minutes of the transcript. Select a timestamp to watch that moment on YouTube.

  1. 0:00

    web graphics library is a javascript api

  2. 0:02

    for implementing

  3. 0:04

    interactive 2d and 3d vector graphics in

  4. 0:06

    the browser

  5. 0:07

    it allows developers to run hardware

  6. 0:09

    accelerated graphics with the client's

  7. 0:10

    gpu

  8. 0:11

    directly inside an html canvas without

  9. 0:13

    the need for external plugins it opens

  10. 0:15

    the door to 3d web design

  11. 0:17

    interactive games data vis physics

  12. 0:19

    simulations and most importantly

  13. 0:21

    beautiful artwork

  14. 0:22

    webgl is used to render graphics in

  15. 0:24

    everyday tools like google maps and by

  16. 0:26

    the unity engine to make web-based games

  17. 0:28

    to understand how it works it helps to

  18. 0:30

    first understand basic 3d theory

  19. 0:32

    and the rendering pipeline in a 3d scene

  20. 0:35

    every point is a vertex

  21. 0:36

    identified by its x y and z coordinates

  22. 0:39

    the vertices are then connected together

  23. 0:41

    to form a bunch of little triangles

  24. 0:43

    known as primitives

  25. 0:44

    then a light source bounces off of them

  26. 0:46

    to create the appearance of shadows and

  27. 0:48

    depth perception they're then rasterized

  28. 0:50

    to convert

  29. 0:50

    a 3d vector graphic into a projection of

  30. 0:53

    a 2d pixel

  31. 0:54

    which tricks our brains into seeing a 3d

  32. 0:56

    object on a 2-dimensional computer

  33. 0:58

    screen

  34. 0:58

    this pipeline can be customized by

  35. 1:00

    writing shaders which are just functions

  36. 1:02

    that tell the computer how to draw

  37. 1:04

    pixels on the screen

  38. 1:05

    shading requires the computer to perform

  39. 1:07

    a ton of linear algebra or matrix

  40. 1:09

    multiplication

  41. 1:10

    to render graphics smoothly at 60fps

  42. 1:13

    it's often too much for the cpu to

  43. 1:14

    handle by itself which is why we have

  44. 1:16

    gpus to distribute the calculations more

  45. 1:18

    efficiently webgl

  46. 1:20

    allows us to process graphics on the gpu

  47. 1:22

    and is based on a library that's been

  48. 1:24

    around since 1992 called opengl

  49. 1:26

    to get started you just need to grab an

  50. 1:28

    html canvas in the dom

  51. 1:30

    then get its webgl contacts to start

  52. 1:32

    drawing the main program code is written

  53. 1:34

    in javascript

  54. 1:35

    but shaders are written in the opengl es

  55. 1:38

    shading language

  56. 1:39

    a shader will take information about a

  57. 1:41

    vertex or fragment and use the gpu to

  58. 1:43

    calculate the data required to render it

  59. 1:45

    as a pixel on the screen

  60. 1:47

    luckily you don't need to write shaders

  61. 1:48

    by hand to start adding 3d graphics to

  62. 1:51

    your website you can use libraries like

  63. 1:52

    3js or tools like spline to quickly

  64. 1:55

    design 3d experiences without much

  65. 1:57

    underlying knowledge of webgl

  66. 1:59

    stay tuned for a full 3js tutorial make