Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletter Hub
Free Learning
Arrow right icon
timer SALE ENDS IN
0 Days
:
00 Hours
:
00 Minutes
:
00 Seconds

Away3D 3.6: Applying Light and Pixel Bender materials

Save for later
  • 4 min read
  • 09 Mar 2011

article-image

 


Away3D 3.6 Essentials












away3d-36-applying-light-and-pixel-bender-materials-img-0

Take Flash to the next dimension by creating detailed, animated, and interactive 3D worlds with Away3D










        Read more about this book      

(For more resources on 3D, see here.)

The reader will comprehend this article better by referring the previous articles on:

Light materials

Light materials can be illuminated by an external light source. There are three different types of lights that can be applied to these materials: ambient, point, and directional. Also, remember that these materials will not necessarily recognize each type of light, or more than one light source. The table under the Lights and materials section lists which light sources can be applied to which materials.

WhiteShadingBitmapMaterial

The WhiteShadingBitmapMaterial class uses flat shading to apply lighting over a bitmap texture. As the class name suggests, the lighting is always white in color, ignoring the color of the source light.

protected function applyWhiteShadingBitmapMaterial():void
{
initSphere();
initPointLight();
materialText.text = "WhiteShadingBitmapMaterial";
var newMaterial:WhiteShadingBitmapMaterial =
new WhiteShadingBitmapMaterial(
Cast.bitmap(EarthDiffuse)
);
currentPrimitive.material = newMaterial;
}

away3d-36-applying-light-and-pixel-bender-materials-img-1

The WhiteShadingBitmapMaterial class extends the BitmapMaterial class. This means that in addition to those parameters in the following list, the init object parameters listed for the BitmapMaterial are also valid for the WhiteShadingBitmapMaterial.

away3d-36-applying-light-and-pixel-bender-materials-img-2

ShadingColorMaterial

The ShadingColorMaterial class uses flat shading to apply lighting over a solid base color.

protected function applyShadingColorMaterial():void
{
initSphere();
initPointLight();
materialText.text = "ShadingColorMaterial";
var newMaterial:ShadingColorMaterial =
new ShadingColorMaterial(
Cast.trycolor("deepskyblue")
);
currentPrimitive.material = newMaterial;
}

away3d-36-applying-light-and-pixel-bender-materials-img-3

The ShadingColorMaterial class extends the ColorMaterial class. This means that in addition to those parameters in the following list, the init object parameters listed for the ColorMaterial class are also valid for the ShadingColorMaterial class.

Unlock access to the largest independent learning library in Tech for FREE!
Get unlimited access to 7500+ expert-authored eBooks and video courses covering every tech area you can think of.
Renews at $19.99/month. Cancel anytime

The color parameter can accept an int or String value. However, due to a bug in the ColorMaterial class, only an int value will work correctly. In the previous example, we have manually converted the color represented by the string deepskyblue into an int with the trycolor() function from the Cast class.

away3d-36-applying-light-and-pixel-bender-materials-img-4

PhongBitmapMaterial

The PhongBitmapMaterial uses phong shading to apply lighting over a TransformBitmapMaterial base material.

protected function applyPhongBitmapMaterial():void
{
initSphere();
initDirectionalLight();
materialText.text = "PhongBitmapMaterial";
var newMaterial:PhongBitmapMaterial =
new PhongBitmapMaterial(Cast.bitmap(EarthDiffuse));
currentPrimitive.material = newMaterial;
}

away3d-36-applying-light-and-pixel-bender-materials-img-5

PhongBitmapMaterial is a composite material that passes the init object to a contained instance of the TransformBitmapMaterial class. This means that in addition to those parameters in the following list, the init object parameters listed for the TransformBitmapMaterial are also valid for the PhongBitmapMaterial.

away3d-36-applying-light-and-pixel-bender-materials-img-6

PhongColorMaterial

The PhongColorMaterial uses phong shading to apply lighting over a solid color base material.

protected function applyPhongColorMaterial():void
{
initSphere();
initDirectionalLight();
materialText.text = "PhongColorMaterial";
var newMaterial:PhongColorMaterial =
new PhongColorMaterial("deepskyblue");
currentPrimitive.material = newMaterial;
}

away3d-36-applying-light-and-pixel-bender-materials-img-7

away3d-36-applying-light-and-pixel-bender-materials-img-8

PhongMovieMaterial

The PhongMovieMaterial uses phong shading to apply lighting over an animated MovieMaterial base material.

protected function applyPhongMovieMaterial():void
{
initSphere();
initDirectionalLight();
materialText.text = "PhongMovieMaterial";
var newMaterial:PhongMovieMaterial =
new PhongMovieMaterial(new Bear());
currentPrimitive.material = newMaterial;
}

away3d-36-applying-light-and-pixel-bender-materials-img-9

PhongMovieMaterial is a composite material that passes the init object to a contained instance of the MovieMaterial class. This means that in addition to those parameters in the following list, the init object parameters listed for the PhongMovieMaterial are also valid for the MovieMaterial.

away3d-36-applying-light-and-pixel-bender-materials-img-10

Dot3BitmapMaterial

The Dot3BitmapMaterial uses normal mapping to add depth to a 3D object.

protected function applyDot3BitmapMaterial():void
{
initSphere();
initDirectionalLight();
materialText.text = "Dot3BitmapMaterial";
var newMaterial:Dot3BitmapMaterial =
new Dot3BitmapMaterial(
Cast.bitmap(EarthDiffuse),
Cast.bitmap(EarthNormal)
);
currentPrimitive.material = newMaterial;
}

away3d-36-applying-light-and-pixel-bender-materials-img-11

Dot3BitmapMaterial is a composite material that passes the init object to a contained instance of the BitmapMaterial class. This means that in addition to those parameters in the following list, the init object parameters listed for the BitmapMaterial are also valid for the Dot3BitmapMaterial.

away3d-36-applying-light-and-pixel-bender-materials-img-12