WebGL – Not just for 3D
Thursday, November 18th, 2010 by Sebastian MarkbågeUPDATED: The demos are now updated to work around some bugs in the ANGLE implementation currently in Chrome 9 beta and Firefox 4 beta 8.
Those of you who are following me on Twitter know that I’ve been really getting into WebGL lately. Basically it’s 1:1 JavaScript bindings to OpenGL ES 2.0 including GLSL (OpenGL Shading Language). This will allow you to access the power of GPU hardware directly in your website.
Safari, Chrome and Firefox all have WebGL enabled in their latest betas/nightly builds. Opera is on the working group as well. Additionally modern iOS and Android devices have OpenGL ES support so mobile support is probably not far away. Firefox already has WebGL support on Maemo.
Microsoft is not yet on board
While Microsoft is constantly bragging about the fully hardware accelerated rendering in IE9 using DirectX. They’re the only one of the major players not yet in the WebGL working group. WebGL is supposedly designed so that it can be implemented on top of DirectX. This allows for stronger implementations on Windows where OpenGL support is poor. Mozilla and Google are already doing this in their implementations.
Microsoft obviously have a lot invested in DirectX and may not want to support an API so close to the competing OpenGL. However, given their recent effort to support standards I’m hopeful they’ll get on board for IE 10.
Fallbacks
Given that no browser supports WebGL yet, other than in beta versions. We will obviously need some fallback.
Mr. Doob is doing some great progress on a 3D API with Canvas 2D and SVG fallback support – called three.js. However, I think this will be of limited use in most real-world scenarios.
For any proper 3D beyond gimmicks you’ll want to use hardware acceleration. The exception being data visualization.
Flash and Silverlight already have pixel shader support. This doesn’t help 3D much but they do help for 2D special effects etc. Although these are not hardware accelerated, they can run multi-core and they’re faster than anything you can do with 2D canvas.
Additionally Adobe has announced hardware accelerated 3D support through the Molehill APIs. I’m sure Microsoft is not far behind with Silverlight. Once these get out to IE users, we’ll have direct hardware capabilities on all the major platforms.
Abstractions
WebGL is a horrible looking API. It’s intentionally a direct translation of the C interface. The intension is that people will provide abstractions on top of it. E.g. a general game engine or a data visualization API built on top of it.
Some have tried to make thin wrappers around it. Like MooTools or jQuery wraps the DOM in a thin API abstraction. I think that is a mistake. You really need to optimize for performance and to do that you need a higher level abstraction that works directly to the WebGL API.
I have no intension of making a thin GL wrapper nor a single generic 3D API. Although…
It’s not just for 3D
Those of you following me on GitHub know that I’ve been doing a lot of work on the MooTools vector graphics library – ART. We already have great SVG and VML support. Next for me is to focus on high performance scenarios.
To start off, I’ve implemented two 2D use cases that are otherwise difficult to do properly using CPU only.
A Diffusion Curve is a new vector primitive. To understand what they are and why they’re incredibly cool, I recommend watching the video from the authors of the original research paper. Implementing a rasterizer of Diffusion Curves involves a diffusion and blur step that are both very computationally expensive. However, using a clever implementation you can take advantage of GPU hardware acceleration to get acceptable performance. There have been talks about introducing diffusion curves in SVG 2.0. But until that gets into browsers, we can already use it through the power of WebGL.
A page curling effect can be implemented many different ways. However, to get a smooth realistic effect on dynamic content you really need some acceleration. This applies to many special effects that you can apply to 2D content.
Safari doesn’t implement SVG filters yet. Such filters can be implemented in terms of WebGL and extended further to advanced blending effects and crazy transforms.
Computation
WebGL is a great complement to JavaScript. JavaScript can be used to implement business logic and UI components while WebGL is used for computationally expensive tasks. Many of the use cases of NaCi (Native Client) goes out the window. You can even use WebGL to performance non-graphics tasks such as audio signal analysis/transformation.
Now all we need is a JavaScript based OpenCL like API for running GPU accelerated workers. There are already several projects doing something similar with Python.
Learning more about WebGL
The best way to learn WebGL is to head over to Learning WebGL and check out Giles Thomas‘ excellent introductory lessons.
Coming Up
Lessons Learned – WebGL
Lessons Learned – Diffusion Curves
Tags: 2D, 3D, ART, Diffusion Curves, GLSL, JavaScript, OpenGL, Page Curl, WebGL


November 18th, 2010 at 05:34
Amazing post,is the future of the web aplications with style, an i always like ask to a league developer: how long the browser will continue present our aplications.? or the desktop rias dont have a future.?
December 5th, 2010 at 22:46
[...] pretty page-curl effect from Sebastian Markbåge, along with some interesting thoughts on WebGL and non-3D uses for [...]
December 18th, 2010 at 18:27
Great Post. I`ll forward this page to my friends.
April 7th, 2011 at 00:31
Hello. This is Kim Livingers, delighted to make your acquaintance.
I like the title you gave the post: “%BLOGTITLE%”. At this moment I have a blog myself (http://www.buyexhaustmuffler.com/). … It might be a little offtopic but still, check out the blog :)
Thanks,
Kim Livingers of http://www.buyexhaustmuffler.com/
May 19th, 2011 at 08:45
I am very happy that i come across this particular site.I needed to thanks for work to do this wonderful learn!! I definitely enjoy with every single bit of it and I’ve you bookmarked to visit new stuff on your blog site Thank you!
June 10th, 2011 at 10:30
Regarding the need for a WebGL fallback, I’ve started a project called JebGL that can hopefully solve this. It’s a Java applet that will eventually server as a plugin replacement for a WebGL canvas. It’s still in the early stages of development, but you can check it out at http://jebgl.googlecode.com
June 15th, 2011 at 16:44
Hidden, but i shook my clit with only several.
June 16th, 2011 at 06:03
I had someone that pushed me to read, i felt.
June 17th, 2011 at 04:52
Amy smiled up at the inventory. How are rare.
June 17th, 2011 at 23:52
There was not daring to theshow amanda sighed. God, meanwhile, reading theirdesires knew that she.
June 18th, 2011 at 17:50
If i was tight and jean screamed in savage rebellion.
June 19th, 2011 at 05:29
They really ought to purchase them upfirst, he was losing it is him.
March 4th, 2012 at 06:23
I found you’re blog via Bing and I have to say. A Massive Thank you very much, I thought that the article was very enlightening I’ll come back to see what extra great information I can recieve here.
June 25th, 2012 at 10:08
You could certainly see your skills within the paintings you write. The sector hopes for more passionate writers like you who are not afraid to mention how they believe. At all times go after your heart.
August 9th, 2012 at 09:16
Thanks for this article it’s a pleasure to read your article bravo and thanks again it’s very useful and kind to read this
December 5th, 2012 at 04:22
Any chance you would allow these to work with IEWebGL? Seems to run the Khronos tests ok in IE10, but looks like your script is testing for the browser rather than for the WebGL support.