You’ll need Flash Player 10 for these demos to show corrently …
Doing a diffuse shading with graphics.drawTriangles(): the principle is to connect two shapes,
one with normally wrapped texture and one with shading:

To get the actual shading I’m using a bitmap-stripe with different shade values as the texture:

The u-coordinate for shading mapping is defined by the dot-product, = cosine of the between-angle, of the vertex normal and vector of light direction, from values near 0.0 in the dark parts to 1.0 on the brighter areas. Similar to Gouraud-shading, the color from the vertices is interpolated over the triangle by drawTriangles(). Using a bitmap as some kind of lookup-table also allows easy control of brightness, contrast and light color. Notice that I’ve used a very dark blue at the darkest parts to simulate ambient light and give the shape some extra depth (Africa in the image below).
and here’s the resulting image – and demo, two layers combined with blendmode ‘hardlight’ :

… for comparing an earlier demo of a rotating globe with pixel bender
Ok, rotating cubes and spheres, seen it: let’s have some more advanced shapes, the classic Stanford Bunny with 500 vertices and mesh of 1000 triangles – in fact the smallest I could find on the net, the texture mapping may not be the best possible, the model had no uv-data, so I applied a simple sphere-mapping:

An Eagle with a mesh of 1500 triangles – hope it’s not after the bunny:

Update October 9, 2008:
Things are getting funnier, and the bunny’s getting bunnier: it’s gained some more weight, 2500 vertices with 5k triangles currently, and still keeps on rolling – this time with only the shading layer, but it does process through all the 2.5k vertices and normals and update the shading each frame :






wow!
By: felix on October 8, 2008
at 10:09 pm
“hope it’s not after the bunny”, LOL thx for sharing ;D
By: katopz on October 9, 2008
at 4:30 am
This is great! Keep it up!
By: Mr.doob on October 9, 2008
at 1:58 pm
Hi,
Sweet demos! The rabbit plays really smooth on my MBP. Is this a custom engine and/or something you’ll release?
J
PS: Make sure you have FP10 RC installed or you’ll only see this:
http://www.flashgamer.com/a/bunny.png
By: Jensa on October 14, 2008
at 1:24 pm
Thanks everyone for your comments !
Jensa: these demos are more like separate studies on the possibilities of FP10, some ideas that keep popping to my mind. Although I love playing with 3D maths, [at least currently] I don’t think I would write a whole 3D-engine …
The reason for Bunny appearing totally flat in Jensa’s pic was the Matrix3D bug, scaling by 0.05, in the earlier releases of the player …
By: pixelero on October 14, 2008
at 3:21 pm
Nice demos, thank u for the ideas, it will be helpful in my studies.
By: Flug on October 27, 2008
at 3:35 pm
Oi. Insane!
By: Kasper on October 27, 2008
at 8:22 pm
Maybe a stupid question:
How can I run this code?
When I paste it in Adobe Flex Builder, it doesn’t work…
By: Ajanz on October 29, 2008
at 9:54 am
Ajanz:
try with this – opens in Flex Builder as an archive : file/import/flex project…
… or is it just this code or any with FP10-content ? in case you need to check the settings: http://opensource.adobe.com/wiki/display/flexsdk/Targeting+Flash+Player+10+Beta
By: pixelero on October 31, 2008
at 11:47 am
Thanks so much for your work – I was able to create a super primitive with a little recoding.
Demo http://www.professionalpapervision.com/demos/web/superprimitive/
Source
http://flex3cookbook2.googlecode.com/files/superPrim.zip
Blog Post
http://professionalpapervision.wordpress.com/
After creating a million custom primitives in Papervision3D, I have always wanted to create just one that did it all using parametric equations. But many of the algorithms used to generate the basic primitives in Papervision3D (Away3D is a little better) are so complicated that its hard to bring them altogether under one roof.
It’s something you need to do from the start. And with many thanks to Petri Leskinen (and a little recoding on my part) we can now do that as shown in the demo above.
By: Mike Lively on January 21, 2009
at 3:54 am
thank you great article.
However i have a question about the bunny
How did you import it ? did you type the vertex one by one ?
By: v3n3 on March 25, 2009
at 5:31 am