the unity web player
TRANSCRIPT
![Page 1: The Unity Web Player](https://reader034.vdocuments.site/reader034/viewer/2022042800/58707a991a28ab92488bae16/html5/thumbnails/1.jpg)
The Future of Web Deployment in Unityjonas echterhoff | [email protected]!Computer Programmer at Unity Technologies
![Page 2: The Unity Web Player](https://reader034.vdocuments.site/reader034/viewer/2022042800/58707a991a28ab92488bae16/html5/thumbnails/2.jpg)
A quick look at the current state of Web Deployment in Unity
Uberstrike, a popular Unity Web Player FPS MMO on Facebook
![Page 3: The Unity Web Player](https://reader034.vdocuments.site/reader034/viewer/2022042800/58707a991a28ab92488bae16/html5/thumbnails/3.jpg)
The Unity Web Player
• A browser plugin to run Unity content in any supported web browser.!
• Has been part of Unity since Unity 1.0 in 2005.!
• Delivers the highest quality gaming experience possible on the web.
![Page 4: The Unity Web Player](https://reader034.vdocuments.site/reader034/viewer/2022042800/58707a991a28ab92488bae16/html5/thumbnails/4.jpg)
The Unity Web Player
• Bundled with Qihoo 360 Browser in China!
• Integrated by Facebook using custom Facebook SDK.!
• 347 Million installs and counting.!
• Heaviest Growth in Asia, with 42% of current web player users in Asia.
![Page 5: The Unity Web Player](https://reader034.vdocuments.site/reader034/viewer/2022042800/58707a991a28ab92488bae16/html5/thumbnails/5.jpg)
The Web is evolving
• For a long time, plug-ins were the only way to deploy advanced content formats.!
• HTML5 has made more and more of such formats possible without the need for plugins.!
• Browser vendors are starting to steer away from plugins.!
• Google has announced that they plan to discontinue support for NPAPI plug-ins in Chrome.
![Page 6: The Unity Web Player](https://reader034.vdocuments.site/reader034/viewer/2022042800/58707a991a28ab92488bae16/html5/thumbnails/6.jpg)
Now let’s take a look at the new Web Deployment Technology we announced for Unity 5.0
![Page 7: The Unity Web Player](https://reader034.vdocuments.site/reader034/viewer/2022042800/58707a991a28ab92488bae16/html5/thumbnails/7.jpg)
Now let’s take a look at the new Web Deployment Technology we announced for Unity 5.0
![Page 8: The Unity Web Player](https://reader034.vdocuments.site/reader034/viewer/2022042800/58707a991a28ab92488bae16/html5/thumbnails/8.jpg)
WebGL
• Hardware-accelerated 3D rendering in the browser, without the need to install a plug-in, using JavaScript!
• API is based on OpenGL ES 2.0.!
• Open web standard.!
• Currently implemented in Firefox, Chrome, Internet Explorer and Opera.
![Page 9: The Unity Web Player](https://reader034.vdocuments.site/reader034/viewer/2022042800/58707a991a28ab92488bae16/html5/thumbnails/9.jpg)
WebGL & Unity
• Perfect fit for Unity on the web.!
• We started experimenting with it at a HackWeek two years ago.!
• Mozilla sent an engineering team to our HackWeeks to join the fun.!
• Over the course of a few HackWeeks, we began to see some real potential for this, and started full production.
![Page 10: The Unity Web Player](https://reader034.vdocuments.site/reader034/viewer/2022042800/58707a991a28ab92488bae16/html5/thumbnails/10.jpg)
WebGL & Unity
Unity developers watching presentations at HackWeek
![Page 11: The Unity Web Player](https://reader034.vdocuments.site/reader034/viewer/2022042800/58707a991a28ab92488bae16/html5/thumbnails/11.jpg)
WebGL & Unity
• Now, we are finally ready to show some results!
![Page 12: The Unity Web Player](https://reader034.vdocuments.site/reader034/viewer/2022042800/58707a991a28ab92488bae16/html5/thumbnails/12.jpg)
WebGL & Unity
![Page 13: The Unity Web Player](https://reader034.vdocuments.site/reader034/viewer/2022042800/58707a991a28ab92488bae16/html5/thumbnails/13.jpg)
So, how does this work?
• WebGL is a JavaScript API. To use it all our code needs to be in JavaScript.!
• We need to somehow convert all our code to JavaScript.!
• Unity Engine code, written in C/C++.!
• User scripts, written in C# or UnityScript.
![Page 14: The Unity Web Player](https://reader034.vdocuments.site/reader034/viewer/2022042800/58707a991a28ab92488bae16/html5/thumbnails/14.jpg)
Introducing: emscripten
![Page 15: The Unity Web Player](https://reader034.vdocuments.site/reader034/viewer/2022042800/58707a991a28ab92488bae16/html5/thumbnails/15.jpg)
Introducing: emscripten
• emscripten is a C++ to JavaScript cross-compilation toolchain !
• Uses clang to compile C++ code to LLVM bitcode, and then provides a custom LLVM backend to emit JavaScript as a result.!
• Open-source project started by Alon Zakai from Mozilla.!
• Provides wrappers for common Web APIs.!
• We use emscripten to cross-compile our Unity engine code to asm.js JavaScript.
![Page 16: The Unity Web Player](https://reader034.vdocuments.site/reader034/viewer/2022042800/58707a991a28ab92488bae16/html5/thumbnails/16.jpg)
Introducing: asm.js
• JavaScript is typically JIT-compiled by the browser’s JavaScript engine.!
• The nature of the JavaScript language can make it hard for the JS JIT engine to make the best guesses on optimizations.!
• asm.js is a statically-typed subset of JavaScript, designed to allow a JavaScript engine to AOT compile asm.js code into well-optimized native code.!
• asm.js retains full compatibility with classic JIT JS engines.!
• asm.js has been invented by Luke Wagner at Mozilla.!
• asm.js is currently enabled in Firefox.
![Page 17: The Unity Web Player](https://reader034.vdocuments.site/reader034/viewer/2022042800/58707a991a28ab92488bae16/html5/thumbnails/17.jpg)
Introducing: IL2CPP
• emscripten let’s us compile our engine to JS, but what about user scripts (C#/UnityScript)?!
• Over the course of the past two years, our scripting team has been developing a new code compilation technology codenamed IL2CPP.!
• IL2CPP takes .NET Bytecode (CIL) and generates corresponding C++ source files.!
• These generated C++ source files can then by cross-compiled to JS (with asm.js) by emscripten.
![Page 18: The Unity Web Player](https://reader034.vdocuments.site/reader034/viewer/2022042800/58707a991a28ab92488bae16/html5/thumbnails/18.jpg)
Let’s look at the code conversion process with an example C# script:
![Page 19: The Unity Web Player](https://reader034.vdocuments.site/reader034/viewer/2022042800/58707a991a28ab92488bae16/html5/thumbnails/19.jpg)
That gets compiled into CIL bytecode by mcs:
![Page 20: The Unity Web Player](https://reader034.vdocuments.site/reader034/viewer/2022042800/58707a991a28ab92488bae16/html5/thumbnails/20.jpg)
That gets compiled into C++ code by IL2CPP:
![Page 21: The Unity Web Player](https://reader034.vdocuments.site/reader034/viewer/2022042800/58707a991a28ab92488bae16/html5/thumbnails/21.jpg)
That gets compiled into LLVM Bitcode using clang:
![Page 22: The Unity Web Player](https://reader034.vdocuments.site/reader034/viewer/2022042800/58707a991a28ab92488bae16/html5/thumbnails/22.jpg)
That gets compiled into JavaScript with asm.js by emscripten:
![Page 23: The Unity Web Player](https://reader034.vdocuments.site/reader034/viewer/2022042800/58707a991a28ab92488bae16/html5/thumbnails/23.jpg)
Finally, emscripten will run an optimization and minifcation pass on the JavaScript code.!!The result looks like this:
![Page 24: The Unity Web Player](https://reader034.vdocuments.site/reader034/viewer/2022042800/58707a991a28ab92488bae16/html5/thumbnails/24.jpg)
Unity WebGL add-on early-access in Unity 5.0
![Page 25: The Unity Web Player](https://reader034.vdocuments.site/reader034/viewer/2022042800/58707a991a28ab92488bae16/html5/thumbnails/25.jpg)
Unity WebGL add-on early-access in Unity 5.0
• Early-access version of the WebGL add-on will be available for purchase for Unity 5.0.!
• Will allow you to deploy Unity content to WebGL, but will have some feature limitations.!
• Will only support the desktop versions of Firefox and Chrome for now, though other browsers may already work as well.
![Page 26: The Unity Web Player](https://reader034.vdocuments.site/reader034/viewer/2022042800/58707a991a28ab92488bae16/html5/thumbnails/26.jpg)
Unity WebGL add-on early-access in Unity 5.0
• Features not supported by WebGL in 5.0 include:!
• Video!
• Runtime Substance generation!
• Networking (WWW class is supported, but no .NET sockets)!
• Microphones and WebCams!
• Script debugging!
• Exception support!
• Threads!
• Scripting will be limited to AOT compilation
![Page 27: The Unity Web Player](https://reader034.vdocuments.site/reader034/viewer/2022042800/58707a991a28ab92488bae16/html5/thumbnails/27.jpg)
Unity WebGL add-on early-access in Unity 5.0
• Performance will generally not be as fast as native code running in the Web Player.
WebGL running Basemark X benchmark suite
![Page 28: The Unity Web Player](https://reader034.vdocuments.site/reader034/viewer/2022042800/58707a991a28ab92488bae16/html5/thumbnails/28.jpg)
Unity WebGL add-on early-access in Unity 5.0
• Performance will generally not be as fast as native code running in the Web Player.!
• How much slower it is depends on the situation. !
• JavaScript has neither SIMD nor Multithreading capabilities yet.!
• Overall frame rates for content we have tested in WebGL running in Firefox already at least 50% of what they are in the Web Player.!
• You can use the profiler to optimize performance for WebGL just as in any other Unity platform.
![Page 29: The Unity Web Player](https://reader034.vdocuments.site/reader034/viewer/2022042800/58707a991a28ab92488bae16/html5/thumbnails/29.jpg)
Plugin support in WebGL
• You can just write a plugin directly in JavaScript and call functions from that from your C# scripts.!
• You can also just add C++ source files to your project, and call functions from them from your game scripts.!
• You can use Application.ExternalCall or Application.ExternalEval,like you would do in the Web Player.
![Page 30: The Unity Web Player](https://reader034.vdocuments.site/reader034/viewer/2022042800/58707a991a28ab92488bae16/html5/thumbnails/30.jpg)
Unity 5.x and beyond
• We plan to make WebGL a fully supported platform in Unity during the 5.x release cycle. Then we will drop the “early-access” label.!
• We expect to have most of the feature limitations resolved during the 5.x cycle.!
• We also expect that more browsers will support the needed feature set to run Unity WebGL content nicely in the future.
![Page 31: The Unity Web Player](https://reader034.vdocuments.site/reader034/viewer/2022042800/58707a991a28ab92488bae16/html5/thumbnails/31.jpg)
Unity 5.x and beyond
• Unity Web Player is still the most powerful and most widely support solution for deploying Unity content on the web.!
• We plan to keep supporting both the Unity Web Player and WebGL for the future (for at least the 5.x release cycle)!
• Deploy your content using both delivery methods to get the widest possible reach.!
• Longer term, we expect that browser vendors will drop support for plugins and that the Unity Web Player will then become obsolete.
![Page 32: The Unity Web Player](https://reader034.vdocuments.site/reader034/viewer/2022042800/58707a991a28ab92488bae16/html5/thumbnails/32.jpg)
Unity 5.x and beyond
![Page 33: The Unity Web Player](https://reader034.vdocuments.site/reader034/viewer/2022042800/58707a991a28ab92488bae16/html5/thumbnails/33.jpg)
Unity 5.x and beyond
• Microsoft and Apple are working on making WebGL available in Internet Explorer and Safari.!
• WebGL 2.0 is expected in the course of this year, and will have a feature set matching OpenGL ES 3.0.!
• Both SIMD and Multithreading extensions for JavaScript are currently being discussed by browser vendors.
![Page 34: The Unity Web Player](https://reader034.vdocuments.site/reader034/viewer/2022042800/58707a991a28ab92488bae16/html5/thumbnails/34.jpg)
Thanks to the WebGL Team at Unity for their hard work on this:
Jonathan Chambers, Jonas Echterhoff, Gabriele Farina, Ralph Hauwert, Tomas Jakubauskas
Also to the Team at Mozilla for being a great help, and for pushing the technology which makes this possible:
Martin Best, Jukka Jylänki, Vladimir Vukicevic, Luke Wagner, Alon Zakai