This is a technical article explaining how to code a light source into your Papervision 3D scene. Papervision is an open source 3d library for the Flash platform.
Lighting in Papervision is a very useful tool. It helps add realism to your 3D project. Often times, you will have a scene or 3D objects that have textures on them using bitmaps. You can easily add lighting effects to these textures.
First you’ll need to add the following import statements:
Phong Shading is a set of 3D rendering techniques which includes a model for reflecting light onto surfaces. It was invented by Bui Tuong Phong at the University of Utah, who published them in his 1973 Ph.D. dissertation.
Where you set up your scene, just create a light source
light = new PointLight3D();
In the part where you create your 3D objects that you want to light, you will create a PhongShader based on the light source and a ShadedMaterial based on your BitmapMaterial and your PhongShader. Please note that it HAS to be a BitmapMaterial and not a BitmapFileMaterial.
var earthBitmap:Bitmap = new earthAsset() as Bitmap;
var mat:BitmapMaterial = new BitmapMaterial(earthBitmap.bitmapData, true);
// create a shader using the light source
var phongShader:PhongShader = new PhongShader(light, 0xFFFFFF, 0x000000, 10);
// create the material based on the Phong shader
var phongShaderMat:ShadedMaterial = new ShadedMaterial(mat, phongShader);
globe = new Sphere(phongShaderMat, 200, 20, 20);
view.scene.addChild( globe );
The project source code is available for download here.
Popularity: 13% [?]