Slide 1

Slide 1 text

Web Graphics of the present time,
 and the near future Presented by Akihiro Oyamada (@yomotsu) 
 at WCAN on 11th Apr, 2015

Slide 2

Slide 2 text

@yomotsu 小山田 晃浩

Slide 3

Slide 3 text

Can we use these?

Slide 4

Slide 4 text

SVG 9+ 3+ Canvas2D 9+ WebGL 11+ 8+ 8+ 37+

Slide 5

Slide 5 text

No content

Slide 6

Slide 6 text

https://support.microsoft.com/gp/microsoft-internet-explorer

Slide 7

Slide 7 text

Windows Vista IE 9 - Windows 7 IE 11 - Windows 8.1 IE 11 - Windows 10 Spartan ( IE11 )

Slide 8

Slide 8 text

8 → 11

Slide 9

Slide 9 text

1. SVG with SnapSVG 2. Canvas with EaselJS 3. WebGL with pixi.js and three.js 4. WebVR

Slide 10

Slide 10 text

No content

Slide 11

Slide 11 text

http://pbskids.org/

Slide 12

Slide 12 text

http://yourpower.panda.org/

Slide 13

Slide 13 text

http://altspace.com/

Slide 14

Slide 14 text

http://alkopedia.dareville.com/

Slide 15

Slide 15 text

http://www.albinotonnina.com/

Slide 16

Slide 16 text

Snap.svg

Slide 17

Slide 17 text

path animation http://localhost:8000/snapsvg_1_pathAnimation.html

Slide 18

Slide 18 text

=^.^= ! Animate it! !

Slide 19

Slide 19 text

! Animate it! ! ! ! class attribute guide path moving object

Slide 20

Slide 20 text

! ! ! var pathAnim = Snap( '.pathAnim2' ); var path = pathAnim.select( 'path' ); var truck = pathAnim.select( 'image' ); var pathLength = path.getTotalLength(); var duration = 5000; ! var playAnim = function () { ! Snap.animate( 0, 1, function( progress ) { ! var movePoint = path.getPointAtLength( pathLength * progress ); ! truck.transform( 't' + ( movePoint.x - 64 ) + ',' +

Slide 21

Slide 21 text

var pathLength = path.getTotalLength(); var duration = 5000; ! var playAnim = function () { ! Snap.animate( 0, 1, function( progress ) { ! var movePoint = path.getPointAtLength( pathLength * progress ); ! truck.transform( 't' + ( movePoint.x - 64 ) + ',' + ( movePoint.y - 64 ) + 'r' + ( movePoint.alpha - 180 ) ); ! }, duration, mina.easeinout ); ! }; ! playAnim();

Slide 22

Slide 22 text

! playAnim(); ! var button = document.querySelector( 'button' ); button.addEventListener( 'click', playAnim ); ! !

Slide 23

Slide 23 text

morphing http://localhost:8000/snapsvg_2_morph.html

Slide 24

Slide 24 text

No content

Slide 25

Slide 25 text

No content

Slide 26

Slide 26 text

=^.^= ! ! ! ! !

Slide 27

Slide 27 text

! ! ! ! ! ! ! ! !

Slide 28

Slide 28 text

! ! ! ! var icon = Snap( document.querySelector( '.octoIcon' ) ); var pathMain =icon.select('.main'); var pathDefault=icon.select('.default').attr('d'); var pathHover =icon.select(‘.hover').attr('d'); ! pathMain.attr( 'd', pathDefault ); ! icon.node.addEventListener('mouseover',function(){ ! pathMain.animate( { d: pathHover

Slide 29

Slide 29 text

pathMain.attr( 'd', pathDefault ); ! icon.node.addEventListener('mouseover',function(){ ! pathMain.animate( { d: pathHover }, 500, mina.bounce ); ! }); ! icon.node.addEventListener('mouseout',function(){ ! pathMain.animate( { d: pathDefault }, 500, mina.bounce ); ! }); ! !

Slide 30

Slide 30 text

templating http://localhost:8000/snapsvg_3_graph.html

Slide 31

Slide 31 text

=^.^= ! ! ! // // snapsvg ʹ΋؆୯ͳςϯϓϨʔτߏจΛαϙʔτ͍ͯ͠Δ͕ػ ೳ͸͔ͳΓগͳ͍ //

Slide 32

Slide 32 text

=^.^= ! ! ! // // snapsvg ʹ΋؆୯ͳςϯϓϨʔτߏจΛαϙʔτ͍ͯ͠Δ͕ػ ೳ͸͔ͳΓগͳ͍ //

Slide 33

Slide 33 text

} ! var template = _.template( [ '<% var gridBottom = ( data.cellLength.y - 1 ) * data.cellSize.height + data.cellOffset.y; %>', '', ! // grid holizontal '<% for ( var i = 0, l = data.cellLength.y; i < l; i ++ ) { %>’, ! '<% var x1 = data.cellOffset.x - 20; %>', '<% var y1 = data.cellOffset.y + data.cellSize.height * i; %>', '<% var x2 = data.cellOffset.x + data.cellSize.width * ( data.cellLength.x - 1 ); %>', '<% var y2 = y1; %>', '', '

Slide 34

Slide 34 text

].join( '\n' ) ); ! ! ! var svgSource = template( { data: data } ); var svgDOM = Snap.parse( svgSource ); graph.append( svgDOM ); ! ! var point = graph.selectAll( '.point' ); var points = graph.selectAll( '.points' ); var surface = graph.select( '.surface' ); ! _.each( point, function ( el ) { ! var mat1 = new Snap.Matrix(); var mat2 = new Snap.Matrix(); ! mat1.translate( +el.attr( 'data-cx1' ), +el.attr( 'data-cy1' ) );

Slide 35

Slide 35 text

• K2VFSZͷΑ͏ͳ47(%0.ૢ࡞
 SVG DOM manipulation, like jQuery • Ξχϝʔγϣϯ
 Animations • ςϯϓϨʔτల։
 Templating • "KBYʹΑΔ֎෦47(ಡΈࠐΈ
 Import external SVG file with Ajax • 47(ಠࣗػೳͷαϙʔτ
 SVG features support, like masking, clipping, patterns etc...

Slide 36

Slide 36 text

http://snapsvg.io/

Slide 37

Slide 37 text

http://snapsvg.io/docs/

Slide 38

Slide 38 text

+ 8 Raphael.js

Slide 39

Slide 39 text

Slide 40

Slide 40 text

http://dreamplus.asia/en/

Slide 41

Slide 41 text

http://kato-hosp.jp/

Slide 42

Slide 42 text

http://wheel.dunlop.co.jp/simulator/2/

Slide 43

Slide 43 text

http://martin-h.com/

Slide 44

Slide 44 text

http://www.itsumokawaii.jp/en/

Slide 45

Slide 45 text

No content

Slide 46

Slide 46 text

make a stage

Slide 47

Slide 47 text

make display objects

Slide 48

Slide 48 text

add them to the stage

Slide 49

Slide 49 text

add them to the stage

Slide 50

Slide 50 text

add them to the stage

Slide 51

Slide 51 text

render the stage

Slide 52

Slide 52 text

http://localhost:8000/easeljs_0_basic.html

Slide 53

Slide 53 text

=^.^= ! ! ! var canvas = document.querySelector( '#myCanvas' ); var stage = new createjs.Stage( canvas ); !

Slide 54

Slide 54 text

=^.^= ! ! ! var canvas = document.querySelector( '#myCanvas' ); var stage = new createjs.Stage( canvas ); ! make a canvas element

Slide 55

Slide 55 text

=^.^= ! ! ! var canvas = document.querySelector( '#myCanvas' ); var stage = new createjs.Stage( canvas ); ! var robot = new createjs.Bitmap( './img/ craftybot.png' ); robot.set( { x: 200, y: 100 load create.js

Slide 56

Slide 56 text

! ! var canvas = document.querySelector( '#myCanvas' ); var stage = new createjs.Stage( canvas ); ! var robot = new createjs.Bitmap( './img/ craftybot.png' ); robot.set( { x: 200, y: 100 } ); stage.addChild( robot ); ! var update = function() { make a stage

Slide 57

Slide 57 text

! var canvas = document.querySelector( '#myCanvas' ); var stage = new createjs.Stage( canvas ); ! var robot = new createjs.Bitmap( './img/ craftybot.png' ); robot.set( { x: 200, y: 100 } ); stage.addChild( robot ); ! var update = function() { ! stage.update(); ! } make a display object

Slide 58

Slide 58 text

var canvas = document.querySelector( '#myCanvas' ); var stage = new createjs.Stage( canvas ); ! var robot = new createjs.Bitmap( './img/ craftybot.png' ); robot.set( { x: 200, y: 100 } ); stage.addChild( robot ); ! var update = function() { ! stage.update(); ! } ! createjs.Ticker.setFPS( 60 ); createjs.Ticker.addEventListener( 'tick', update ); add to the stage

Slide 59

Slide 59 text

craftybot.png' ); robot.set( { x: 200, y: 100 } ); stage.addChild( robot ); ! var update = function() { ! stage.update(); ! } ! createjs.Ticker.setFPS( 60 ); createjs.Ticker.addEventListener( 'tick', update ); !

Slide 60

Slide 60 text

No content

Slide 61

Slide 61 text

blend mode http://localhost:8000/easeljs_1_blend.html

Slide 62

Slide 62 text

sprite animations http://localhost:8000/easeljs_2_sprite.html

Slide 63

Slide 63 text

events http://localhost:8000/easeljs_3_event.html

Slide 64

Slide 64 text

• อ࣋Ϟʔυ"1*ͷΑ͏ͳɺ
 ΦϒδΣΫτ؅ཧ
 Specific objects management, like retained mode APIs • 4QSJUF΍4QJOFͷΞχϝʔγϣϯ
 Sprite and Spine animations • ϐΫηϧૢ࡞΍جຊతͳϑΟϧλʔ
 Pixel manipulation and basic filters • Ϛ΢εͱλονΠϕϯτ
 Mouse and touch events

Slide 65

Slide 65 text

http://www.createjs.com/#!/EaselJS

Slide 66

Slide 66 text

http://www.createjs.com/Docs/EaselJS/modules/EaselJS.html

Slide 67

Slide 67 text

SVG vs Canvas

Slide 68

Slide 68 text

https://msdn.microsoft.com/en-us/library/ie/gg193983(v=vs.85).aspx#19graphicsInHtml5 canvas vs svg ύϑΥʔϚϯε

Slide 69

Slide 69 text

No content

Slide 70

Slide 70 text

No content

Slide 71

Slide 71 text

http://archive.revolutionsinsound.com/

Slide 72

Slide 72 text

http://www.wolverineunleashed.com/

Slide 73

Slide 73 text

http://kaatje.ketnet.be/html/

Slide 74

Slide 74 text

http://www.theboxtrolls.com/experience/the-cavern

Slide 75

Slide 75 text

http://www.goodboydigital.com/runpixierun/

Slide 76

Slide 76 text

http://localhost:8000/pixi_0_basic.html

Slide 77

Slide 77 text

=^.^= ! ! var renderer=new PIXI.autoDetectRenderer(640,360); document.body.appendChild( renderer.view ); ! var stage = new PIXI.Stage( 0xffffff ); ! var robot = new PIXI.Sprite.fromImage( './img/ craftybot.png' ); robot.position.set( 200, 100 );

Slide 78

Slide 78 text

=^.^= ! ! var renderer=new PIXI.autoDetectRenderer(640,360); document.body.appendChild( renderer.view ); ! var stage = new PIXI.Stage( 0xffffff ); ! var robot = new PIXI.Sprite.fromImage( './img/ craftybot.png' ); robot.position.set( 200, 100 ); stage.addChild( robot ); ! ( function animate() { load pixi.js

Slide 79

Slide 79 text

=^.^= ! ! var renderer=new PIXI.autoDetectRenderer(640,360); document.body.appendChild( renderer.view ); ! var stage = new PIXI.Stage( 0xffffff ); ! var robot = new PIXI.Sprite.fromImage( './img/ craftybot.png' ); robot.position.set( 200, 100 ); stage.addChild( robot ); ! ( function animate() { ! requestAnimationFrame( animate ); renderer.render( stage ); make a renderer canvas

Slide 80

Slide 80 text

! ! var renderer=new PIXI.autoDetectRenderer(640,360); document.body.appendChild( renderer.view ); ! var stage = new PIXI.Stage( 0xffffff ); ! var robot = new PIXI.Sprite.fromImage( './img/ craftybot.png' ); robot.position.set( 200, 100 ); stage.addChild( robot ); ! ( function animate() { ! requestAnimationFrame( animate ); renderer.render( stage ); ! } )(); ! make a stage

Slide 81

Slide 81 text

! var renderer=new PIXI.autoDetectRenderer(640,360); document.body.appendChild( renderer.view ); ! var stage = new PIXI.Stage( 0xffffff ); ! var robot = new PIXI.Sprite.fromImage( './img/ craftybot.png' ); robot.position.set( 200, 100 ); stage.addChild( robot ); ! ( function animate() { ! requestAnimationFrame( animate ); renderer.render( stage ); ! } )(); ! ! make a display object

Slide 82

Slide 82 text

document.body.appendChild( renderer.view ); ! var stage = new PIXI.Stage( 0xffffff ); ! var robot = new PIXI.Sprite.fromImage( './img/ craftybot.png' ); robot.position.set( 200, 100 ); stage.addChild( robot ); ! ( function animate() { ! requestAnimationFrame( animate ); renderer.render( stage ); ! } )(); ! !

Slide 83

Slide 83 text

var stage = new PIXI.Stage( 0xffffff ); ! var robot = new PIXI.Sprite.fromImage( './img/ craftybot.png' ); robot.position.set( 200, 100 ); stage.addChild( robot ); ! ( function animate() { ! requestAnimationFrame( animate ); renderer.render( stage ); ! } )(); ! !

Slide 84

Slide 84 text

No content

Slide 85

Slide 85 text

blend mode http://localhost:8000/pixi_1_blend.html

Slide 86

Slide 86 text

sprite animations http://localhost:8000/pixi_2_sprite.html

Slide 87

Slide 87 text

events http://localhost:8000/pixi_3_event.html

Slide 88

Slide 88 text

shaders http://localhost:8000/pixi_4_shader.html

Slide 89

Slide 89 text

custom shaders http://localhost:8000/pixi_5_shader2.html

Slide 90

Slide 90 text

=^.^= ! ! ! var MyFilter = ( function () { ! var MyFilter = function() { ! PIXI.AbstractFilter.call( this ); ! this.passes = [ this ]; !

Slide 91

Slide 91 text

! var MyFilter = ( function () { ! var MyFilter = function() { ! PIXI.AbstractFilter.call( this ); ! this.passes = [ this ]; ! // types // '1f': scalar // '2f': vec2 // '3f': vec3 // '4f': vec4 // 'mat4': mat4 this.uniforms = { size: { type: '1f', value:0.01 } }; ! // http://www.html5gamedevs.com/topic/10585-list- of-available-filter-shader-uniforms/ extend Filter class

Slide 92

Slide 92 text

// http://wp.applesandoranges.eu/?p=14 this.fragmentSrc = [ ! 'precision mediump float;', 'varying vec2 vTextureCoord;', 'varying vec4 vColor;', 'uniform sampler2D uSampler;', ! 'uniform float size;', ! 'void main( void ) {', ! 'vec4 sum = vec4( 0 );', ! 'for ( int i = -4; i < 4; i ++ ) {', ! 'for( int j = -4; j < 4; j++ ){', ! 'sum += texture2D( uSampler, vTextureCoord + vec2( j, i ) * size ) * 0.05;', ! '}', write your 
 fragment
 shader

Slide 93

Slide 93 text

'if ( alpha > 0.8 ) {', ! 'gl_FragColor = texColor;', ! '} else {', ! 'gl_FragColor = sum;', ! '}', ! '}' ! ]; ! }; ! MyFilter.prototype = Object.create( PIXI.AbstractFilter.prototype ); ! return MyFilter; ! } )();

Slide 94

Slide 94 text

• &BTFM+4ͱΑ͘ࣅͨ"1*
 Very similar APIs to EaselJS • 8FC(-Λར༻ͨ͠ߴ଎ॲཧ
 High speed pixel manipulation with WebGL • ಠࣗγΣʔμʔͷ௥Ճ
 Custom shaders

Slide 95

Slide 95 text

http://www.pixijs.com/

Slide 96

Slide 96 text

http://www.goodboydigital.com/pixijs/docs/

Slide 97

Slide 97 text

http://www.html5gamedevs.com/forum/15-pixijs/

Slide 98

Slide 98 text

three.js

Slide 99

Slide 99 text

http://www.apple.com/macbook/design/

Slide 100

Slide 100 text

http://gravitymovie.warnerbros.com/#/home

Slide 101

Slide 101 text

https://www.ana-flightconnections.com/

Slide 102

Slide 102 text

http://fr.special-t.com/media/ogreen/en/

Slide 103

Slide 103 text

https://yomotsu.github.io/walkthrough

Slide 104

Slide 104 text

make a scene

Slide 105

Slide 105 text

make a camera

Slide 106

Slide 106 text

add a light

Slide 107

Slide 107 text

add an object

Slide 108

Slide 108 text

http://localhost:8000/threejs_0_basic.html

Slide 109

Slide 109 text

=^.^= var width = window.innerWidth, height = window.innerHeight; ! var scene = new THREE.Scene(); ! var camera = new THREE.PerspectiveCamera( 40, width / height, 1, 1000 ); camera.position.set( 0, 0, 3 ); ! var renderer = new

Slide 110

Slide 110 text

var width = window.innerWidth, height = window.innerHeight; ! var scene = new THREE.Scene(); ! var camera = new THREE.PerspectiveCamera( 40, width / height, 1, 1000 ); camera.position.set( 0, 0, 3 ); ! var renderer = new THREE.WebGLRenderer( { antialias: true } ); renderer.setSize( width, height ); document.body.appendChild( renderer.domElement ); ! var directionalLight = new THREE.DirectionalLight( 0xffffff ); directionalLight.position.set( 0, 1, 1 ).normalize(); scene.add( directionalLight ); ! var box = new THREE.Mesh(

Slide 111

Slide 111 text

THREE.WebGLRenderer( { antialias: true } ); renderer.setSize( width, height ); document.body.appendChild( renderer.domElement ); ! var directionalLight = new THREE.DirectionalLight( 0xffffff ); directionalLight.position.set( 0, 1, 1 ).normalize(); scene.add( directionalLight ); ! var box = new THREE.Mesh( new THREE.BoxGeometry( 1, 1, 1 ), new THREE.MeshPhongMaterial( { color: 0xff0000 } ) ); scene.add( box ); ! ( function renderLoop () { ! requestAnimationFrame( renderLoop ); box.rotation.y += 0.01;

Slide 112

Slide 112 text

directionalLight.position.set( 0, 1, 1 ).normalize(); scene.add( directionalLight ); ! var box = new THREE.Mesh( new THREE.BoxGeometry( 1, 1, 1 ), new THREE.MeshPhongMaterial( { color: 0xff0000 } ) ); scene.add( box ); ! ( function renderLoop () { ! requestAnimationFrame( renderLoop ); box.rotation.y += 0.01; renderer.render( scene, camera ); ! } )(); !

Slide 113

Slide 113 text

new THREE.MeshPhongMaterial( { color: 0xff0000 } ) ); scene.add( box ); ! ( function renderLoop () { ! requestAnimationFrame( renderLoop ); box.rotation.y += 0.01; renderer.render( scene, camera ); ! } )(); !

Slide 114

Slide 114 text

3D Models http://localhost:8000/threejs_1_3dmodel.html

Slide 115

Slide 115 text

skeletal animation http://localhost:8000/threejs_2_bone.html

Slide 116

Slide 116 text

events http://localhost:8000/threejs_3_event.html

Slide 117

Slide 117 text

No content

Slide 118

Slide 118 text

custom shader http://localhost:8000/threejs_4_shader.html

Slide 119

Slide 119 text

No content

Slide 120

Slide 120 text

http://threejs.org/

Slide 121

Slide 121 text

http://threejs.org/docs/

Slide 122

Slide 122 text

• %ϞσϧಡΈࠐΈ
 Import 3D models • Ξχϝʔγϣϯ
 Animations • ܭࢉܥͷػೳ ϕΫτϧɺߦྻͳͲ 
 Math functions, like vector, matrix • ಠࣗγΣʔμʔͷ௥Ճ
 Custom shaders Post process, Debugging WebGL, Rapid update, BOENPSF

Slide 123

Slide 123 text

WebVR

Slide 124

Slide 124 text

https://www.youtube.com/watch?v=pMrhaLb6UeQ

Slide 125

Slide 125 text

d = navigator.
 getVRDevices()

Slide 126

Slide 126 text

• d[ i ].VRDevice (Type of the device) • d[ i ].VREyeParameters • FOV • eyeTranslation • d[ i ].VRPositionState • position • velocity • orientation • angularVelocity • othres… d = navigator.
 getVRDevices()

Slide 127

Slide 127 text

vrHMD.getEyeTranslation( ‘left' ); vrHMD.getEyeTranslation( 'right' ); vrHMD.getRecommendedEyeFieldOfView( 'left' ); vrHMD.getRecommendedEyeFieldOfView( 'right' );

Slide 128

Slide 128 text

Chromium WebVR Builds Firefox Nightly Builds WebVR Oculus Rift Enabler as of Apr, 2015

Slide 129

Slide 129 text

https://www.youtube.com/watch?v=cBvCS78ZC1c

Slide 130

Slide 130 text

Virtuix Omni Locomotion HMD Cyberith Virtualizer OCULUS Rift SONY Morpheus HTC Vine • Leap Motion • PrioVR • Control VR • Sixense Stem • Razer Hydra Others

Slide 131

Slide 131 text

https://www.youtube.com/watch?v=aTtfAQEeAJI

Slide 132

Slide 132 text

Drop-in Phone
 Viewers

Slide 133

Slide 133 text

Drop-in Phone
 Viewers • Different APIs
 (use DeviceOrientation API instead) • Limited performance
 (stereo rendering on mobile device)

Slide 134

Slide 134 text

No content

Slide 135

Slide 135 text

No content

Slide 136

Slide 136 text

for more info,
 visit http://webvr.info/

Slide 137

Slide 137 text

Conclusion

Slide 138

Slide 138 text

ύϥϥοΫεޮՌ͸
 ΋͸΍લ࣌୅ Parallax Effects are no longer cool

Slide 139

Slide 139 text

47(΍$BOWBTΛ
 ࢖ͬͯΈΑ͏ Time to start using SVG and Canvas

Slide 140

Slide 140 text

47(ʹ͸4OBQ47(
 $BOWBTʹ͸&BTFM+4 SnapSVG for SVG, EaselJS for Canvas

Slide 141

Slide 141 text

8FC(-͸͞Βʹύϫϑϧʂ
 QJYJKT΍UISFFKTΛ࢖͓͏ WebGL is more powerful! Use pixi.js and three.js

Slide 142

Slide 142 text

8FC73͕Մೳʹ͢Δ8FCͰͷ
 όʔνϟϧɾϦΞϦςΟʔ WebVR Brings Virtual Reality to the Web

Slide 143

Slide 143 text

Thanks! @yomotsu