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

[GREE Tech Talk #08] You Don't Know WebGL

[GREE Tech Talk #08] You Don't Know WebGL

「You Don't Know WebGL」Guangyao Liu / 劉光耀(グリー株式会社)

※GREE Tech Talk #08「WebGL」での登壇資料です。
http://techtalk.labs.gree.jp/08/

gree_tech

June 19, 2015
Tweet

More Decks by gree_tech

Other Decks in Technology

Transcript

  1. MM Team Kuu Miyazaki @miyazaqui, github:@kuu Jason Parrott +JasonParrott, github:@Moncader

    Guangyao Liu @brilliun, github:@brilliun Daijiro Wachi @watilde, github:@watilde
  2. WebGL Misconceptions • WebGL === 3D? • WebGL === Super

    fast? • WebGL === Another new “magic”?
  3. WebGL Misconceptions • WebGL === 3D? • WebGL === Super

    fast? • WebGL === Another new “magic”?
  4. This work is a derivative of a photo by Paranoidray,

    used under CC BY-SA. It is licensed under CC BY-SA by GREE, Inc.
  5. This work is a derivative of a photo by Mr

    mr ben, used under CC BY-SA. It is licensed under CC BY-SA by GREE, Inc.
  6. What About 2D Contents • Lots of 2D contents on

    the web • WebGL used for 2D in serious applications?
  7. Canvas 2D API The 2D graphics API works in <canvas>

    element ctx.beginPath(); ctx.moveTo(x1, y1); ctx.lineTo(x2, y2); ctx.quadraticCurveTo( x3, y3, x4, y4 ); ctx.stroke(); ctx.fill(); ctx.drawImage( img, srcX, srcY, srcWidth, srcHeight, x, y, width, height ); Vector graphics Raster graphics
  8. WebGL API gl.drawArrays(mode, first, count); gl.drawElements(mode, count, type, offset); mode:

    gl.POINTS gl.LINES gl.LINE_LOOP gl.LINE_STRIP gl.TRIANGLES gl.TRIANGLE_STRIP gl.TRIANGLE_FAN Triangles Lines
  9. Vector Graphics • Resolution independant • Small data size •

    Existing assets This work is a derivative of a photo by Darth Stabro, used under CC BY-SA. It is licensed under CC BY-SA by GREE, Inc.
  10. Pixi.js Drawing filled polygons using stencil buffer • Extra rendering

    cost http://www.cs.sun.ac.za/~lvzijl/courses/rw778/grafika/OpenGLtuts/Big/graphicsnotes014.html
  11. Vector in Theatrical • We do triangulation • With almost

    no restrictions • Produce resolution independent curves
  12. WebGL Misconceptions • WebGL === 3D? • WebGL === Super

    fast? • WebGL === Another new “magic”?
  13. WebGL Performance • Performance boosts not ONLY because we use

    WebGL • It is the way how we use it that matters
  14. WebGL Performance • Draw calls ◦ drawElements/drawArrays • Texture updates

    • Shader operations ◦ especially Fragment Shader
  15. WebGL Performance • Otherwise, easy to get bad performance. •

    Not to mention WebGL on mobile ◦ weaker hardware ◦ restricted GL features & extensions
  16. WebGL Misconceptions • WebGL === 3D? • WebGL === Super

    fast? • WebGL === Another new “magic”?
  17. Magic In Browser • A lot of “magic” going on

    in browser ◦ Canvas 2D API ◦ <video> • Doing complex tasks silently in C++ w/o letting web developers know how
  18. WebGL is New Magic? • WebGL is a new API

    • WebGL brings plug-in free 3D into browser • WebGL is complex
  19. WebGL is New Magic? var canvas2D = canvas.getContext(‘2d’); // Existing

    magic var webgl = canvas.getContext(‘webgl’); // Aha! New magic!!!
  20. Extensible Web • New low-level capabilities should be exposed to

    Javascript • Existing high-level capabilities should be explained in terms of Javascript
  21. Extensible Web • New low-level capabilities should be exposed to

    Javascript • Existing high-level capabilities should be explained in terms of Javascript
  22. Low-level Capabilities With WebGL, we can • Write and execute

    GLSL programs on GPU • Trigger GL/Direct3D commands through browser
  23. Extensible Web • New low-level capabilities should be exposed to

    Javascript • Existing high-level capabilities should be explained in terms of Javascript
  24. High-level Capabilities • Hardware acceleration used to be a black

    box to web developers • Relying on browser vendors to gift us with performance improvement
  25. Hardware Acceleration “truly hardware accelerating graphics on the web means

    giving developers access to a programmable 3D graphics pipeline with WebGL” -- Chrome blog