The team from Turbulent in Montreal will go through the lessons learned building a large-scale WebGL project for Star Citizen. Anecdotes, stack & tech choices, the good and the bad.
Voted on by the Star Citizen Community Initial prototyping using Unity 3D Rewritten from scratch with WebGL ~3000 hours of work ~20K lines of code ~ 4 month production
drag & drop functionality. Go from artist to screen rapidly. Allow fast iteration of art assets before export from 3D tools Ensures the core work is done before artist can work Ensures WYSIWYG
Fragment Shader The Fragment Shader handles everything, including the animation and the 3D perspective view. No Bitmap! The Black Hole is entirely procedural. Complex shapes made simple
Maximize use of Fragment Shaders even for full 3D objects ThreeJS is not yet ready for full-on games development. GLSL Effects. Procedural textures. Noise formulas to avoid bitmaps. Billboards, Fragment shaders with simple geometry - Almost FREE Antialiasing & Animation Animation system and art pipeline not yet mature enough
system but later migrated to the CommonJS module system for usage with Webpack Makes it possible to use NPM as the package manager. Makes TypeScript autocompletion not as efficient Viewer compiled as a reusable JavaScript library, to be included by the main application Token replacement (dev-only code paths using the Define Plugin & UglifyJS’s dead- code elimination) Slower build time even when using incremental builds (Watcher) Allows multiple compilation targets (Standalone / Library) and environments (Development / Production) GLSL loader allows GLSL shaders in separate files. Less error prone, allows syntax highlighting and autocompletion.
was well designed but low level We created an ES6 Viewer API Defined a simple event-driven interface Layer between the viewer and the UI Easier communication Easier synchronization
Vendor locking (MS) Poor ES6 support (at the time) Symbols Generators for .. of Computed properties De-structuring Spread Operator ... Supports most interesting parts of ES6 Includes Polyfills Future-proof (ECMAScript 6 is the current JS Standard) Optional typing if required (ie using FB Flowtype) Previously used internally on smaller projects Other ES5 to 6 compilers were not as mature Last year!
unused elements, hiding the layers is not enough - Create necessary masks and clip paths - Move all the animatable elements to their animation start position.
SVGs exports from Illustrator manually : - Remove useless elements (SVG groups <g>, Comments) - Make sure that it contains no filter-created and unwanted base64-encoded rasterized pngs - Add classes/ids to elements to be animated
but JS has better support - Create path : - Set "stroke-dasharray" to its length - Animate its "stroke-dashoffset" - To get path length call SVGPathElement#getTotalLength() - Transformations - Point of origin at the top left of the element - Makes some transformations like rotation more painful to handle.
glitches What happened What we did Some SVG filters would not render properly in Firefox Use an object tag to embed the SVG and access its DOM using HTMLObjectElement#contentDocument
What happened What we did SVG animations cause layout trashing in Firefox Disable costly animations when Firefox is detected using **cough** user agent sniffing **cough**
happened What we did Collada model file parser blocks event loop for SVG + JS, freezing the animation for short periods of time. Could not move the parser to a web worker because of its reliance on DOM. Write a simpler CSS-only animation that would not be blocked by the event loop.
What happened What we did (proposed by a Mozilla Web Audio engineer) Using Shifty to do volume fadings would cause crackling noises. Use the combination of AudioParam#setValueAtTime and AudioParam#linearramptovalueattime to produce a linear fade in/out.
on the web. Ally the versatility of the web platform with the power of GL to elevate the user experience. Compile-time checks make huge difference in the workflow. Using web tools for UI allows fast iterations. Real-time 3D graphics on the web: Still not a walk in the park.