UnitZeroOne

Avatar

A blog written by Ralph Hauwert, freelance front-end developer, specialized in rich internet applications, games and visualisation.

Papervision3D Shaders / Bumpmap example sourcecode for CS3

Bumpmapped planet

This demo / source file is one which was used during the Papervision3D Workshop in Amsterdam, during the fantastic FITC Amsterdam 2008 event. These are the modified final sources for the example I did at the end of the day. Although quite simple, I think they are very useful at illustrating on how to use shaders. Download the sources here.

Digg, StumbleUpon, Slash and others: These icons link to social bookmarking sites where readers can share and discover new web pages.
  • Digg
  • del.icio.us
  • DZone
  • StumbleUpon
  • Slashdot
  • Technorati
  • blogmarks
  • BlogMemes
  • Ma.gnolia

Flash 9 Example : 3d Landscapes (Voxel Engine)

This is something I’ve been wanting to put online for a long, long time. In fact; this is almost the exact same version as I had during the Flex 2 beta’s; it’s been that long (almost a year now!!!! damn). I’ve been wanting to put alot of work in this, but basically, I don’t have the time, and don’t really see enough time to work on it. Besides, I’ve joined the FC64 team, and as soon as I get some real time, myself and Martin Wood hopefully get some progress on doing SID emulation… (it’s commodore, it’s sound, it’s AS3, it’s oldskool; what do you want more for a hobby project ;-) ). Next to that, I’m turning in a Flex 2 fanboy, and finally recently started loving Flex 2 data services more and more too…busy, busy, busy. Anyway, let’s get back to this thing.

When I first got my hands on AS3, the most obvious thing I could do was doing al these ’seemingly processor intensive’ effects, like you’ve seen coming by here earlier, or stuff I showed at presentations. Voxels where one of the first things I started to do, and had a fun time doing them. Just never got to finish this…..

So, what’s this ? The technical incorrect name for the effect is a Voxel engine. The history of more high quality voxel engines probably started with ‘Comanche Maximum Overkill’, a pc game which in it’s time had some amazing 3d visuals. Later on the game “Outcast” used a heavily ‘pimped’ voxel engine to produce some amazing graphics for the year 1999. This year the legendary Amiga demo group “The Black Lotus” released a demo called “Ocean Machine”, showing of some real, real hardcore voxel work, running amazing graphics on an Amiga with no 3d graphics acceleration, and a CPU running at 50Mhz. Have a look at the youtube video here. So, the power of voxels is established.

Although one might call this demo a Voxel Engine, it isn’t entirely, since a real voxel engine would represent volume in 3d space, while this type of engine usually has a limited freedom of vision and motion because of it’s inherent 2d nature. Where as a voxel should represent volume in a 3d space, this type of engine represents 2d in a semi 3d engine; confused yet ? Actually, the maximum amount of freedom this type of engines is very restricted; but it gives something we still need; raw speed. Although the algorithm is relatively heavy, it can be optimized pretty easy; implemenations of Voxel engines have been done on mobile devices, calculators and of course, the good old c64.

This engine on itself does the generation of a 2d image based on a perlin noise image it uses for a heightmap (that what actually represents the height), and textures an image based on those heights (and doesn’t really do such a good job at the moment). Then it goes to the drawing phase, where it draws a part of the map based on a virtual position of a viewer and it’s view angle and field of view, and draws columns very much similar in a way to what a raycasting engine would do. Of course the master of raycasting in Flash is Andre Michelle, so go and have a look there.

This demo should have had a lot more, but for now it already has some pretty nice tricks; LOD (level-of-detail), implemented in 3 different ways, for speed, although buggy, there’s a lot of clipping going on, and that what is clipped doesn’t always seem to connect with the rest. Bilinear texture filtering, and ofcourse a procedural texure generator. I’ll get back at doing the real work on it, one day…..one day…..one day…..
For now it’s more a proof of concept, although this concept really didn’t need the proof, it just needed execution.

voxel_screen.jpg
See the engine in action, make sure you have Flash 9 player.

Digg, StumbleUpon, Slash and others: These icons link to social bookmarking sites where readers can share and discover new web pages.
  • Digg
  • del.icio.us
  • DZone
  • StumbleUpon
  • Slashdot
  • Technorati
  • blogmarks
  • BlogMemes
  • Ma.gnolia

Flash 8 Example : “3d” BumpMapping using Filters. (source included)

Another oldskool effect! This technique is called bumpmapping and produces lightened heightmapped and textured images. I’m very happy about how this one looks, but even more on how I got to this. I needed to generate a static bumpmap for another thing I’m working on, and got kind of distracted doing it. I thought it would be a cool thing to do in Flash 8.5, and maybe build myself a little Flex 2 interface along the way.

While coding this in 8.5, it started out as a very mathematically correct (and thus non optimized) version of the basic 2d BumpMapping algorithm. Slowly I noticed that I could maybe do it per pixel, and fast enough to run frame by frame. While optimizing it to run faster, (Miko also put in some effort here) I came to the conclusion that the optimized routine looked amazingly much like a Convolution Filter creating displacement lookups. And what do you know; it is. So I ended up being able to creatie this 8 version of the effect The algorithm itself is very well documented, so I won’t go into that.

The 8.5 per-pixel version takes about 50% CPU (I’m still struggling with some perfomance issues I have with beta 2, how can it be that one (bitshifting) array lookup is slower then 4 getpixels?). Although it is to be expected that that can be reduced, it will never reacht he 5% load this thing gives on my CPU, producing the exact same result. Filters are sooo much fun.

The example shows 2 different combinations of lightmaps, bumpmaps and texture maps (UnitZeroOne and V for Vendetta). It’s the most basic implementation of what the thing could look like. Imagine using animated bump and light maps….

Here’s the example.
[UPDATE]
I’ve taken the sources offline until a reach my workstation again, since I made an error while exporting the project out of FDT. Sorry. Will post them again as soon as possible. Thank you Jens for the tip.
[UPDATE2]
And the sources are available, this time correct.

Preview picture of the now pimped & bumpmapped uzo icon :
Preview picture of a bumpmapped unitzeroone logo

(You will need the Flash 8 plugin!)

Digg, StumbleUpon, Slash and others: These icons link to social bookmarking sites where readers can share and discover new web pages.
  • Digg
  • del.icio.us
  • DZone
  • StumbleUpon
  • Slashdot
  • Technorati
  • blogmarks
  • BlogMemes
  • Ma.gnolia

Search

Projects & Work

A selection of current work

Advertising