wick3d introduction + Gouraud shading

Since some time, I’ve been working (off and on, and more off than on) on a rudimentary 3D engine in ActionScript 3, code name Wick3d (hah, I know, rediculous!). Not to become the next Papervision, since there are plenty of engines doing a much better job (just check Papervision, Away3D, Sandy or Alternativa3D and keep a tissue close in case of droolage). Anyway, I’m just interested in 3D algebra and whenever I see something cool, I want to know how it works, and if it results in stuff like this, I’m having tons of fun as well :)

It’s surprisingly easy to get messy code while adding functionalities, so I had to start from scratch a couple of times. I also had to throw out some work such as coloured light sources, which were killing cpu when used with textures, and to be honest, no one really wants to use untextured objects so I might as well streamline it to be the same for all types of surfaces. This weekend, I reworked the lighting calculations according to Lambert’s cosine law for diffuse lighting and added support for specular highlights. Finally, I also added a Gouraud shader (I have to admit I had a grin on my face when it finally worked). Basically, it’s using a linear gradient image map and defining uv-coordinates on it based on the lighting per vertex normal. After that, it’s drawn the same as any affine texture map.

The code is not public (yet), coz it really needs a lot of cleaning up, and well… It can’t do much right now (apart from creating cubes and spheres). Of course, if there’s people who want to look at it out of interest, I can always clean up the mess I made in there and put it online.

Check the demo if you want, as you can see the frame rate isn’t all that high :( And apart from that, something is wrong with my UV-mapping. I’m not sure if it’s an error in the texture mapping or the calculations for the spherical coordinates (I suspect the latter…).

One thought on “wick3d introduction + Gouraud shading

Leave a Reply

Your email address will not be published. Required fields are marked *