Use the mouse to position the lightsource. This demo’s normal map was made by following an excellent tutorial on producing normal maps from photographs by Ryan Clark. The shader is of my own design but is nothing special at all, and I think it’s slightly buggy still working correctly.
On my machine this runs at a capped 50fps, whilst trying to do the exact same pixel calculations ‘manually’ with bitmapData methods manages 2 to 3 fps. I would post a SWF of the manual version too but it has a decent chance of timing out the flash plugin.
This is all thanks to the magic and wonder of Pixel Bender, which lets you write your own shaders/filters/blendmodes for use in a range of Adobe’s products – including Flash. Basically it lets you write an operation that will be executed on every pixel in a given image. The good bit is that the execution of that operation will take advantage of the parallel nature of the task and split its operation into threads, so showing a huge increase in performance from the single-thread bound Flash Player. You may also read about how Pixel Bender pushes its calculations on to the GPU, but it actually doesn’t do that when executing in Flash.
Sadly a significant amount of its features are disabled for Flash, and there are still plenty of oddities and inconsistencies that even in my brief testing I’ve come up against. Despite that, I think it’s worthy of investigation simply because of the huge increase in performance it can give – it’s also free and works fine without needing to use the Flash IDE.
Once I’m a little more certain that I’m doing things right I’ll write up an introduction tutorial for using Pixel Bender in Flash projects.
Edit: Here it is.