Away3D中的光照可以分为三个基本要素:
第一个同PV3D不同之处是我们可以指定超过一个光源 。这样会加大CPU的负担,但同时也可以制造出更加真实的场景渲染。
三种主要的 light sources:
以下几种 shaders:
以上shaders,除了 EnviroShader ,其余的 light source 都是DirectionalLight3D
我们可以选择使用CompositeMaterials ,这种材质包含了一些不同的 shaders 和基于这些 shaders 的materials。
material列表如下:
PhongBitmapMaterial used to create ambient, diffuse and specular lighting on a texture-mapped material
Base material : BitmapMaterial
Shaders : AmbientShader , DiffusePhongShader and SpecularPhongShader
PhongMovieMaterial used to create ambient, diffuse and specular lighting on a material based on another Flash movie
Base material : MovieMaterial
Shaders : AmbientShader , DiffusePhongShader and SpecularPhongShader
PhongColorMaterial used to create ambient, diffuse and specular lighting on a simple coloured material
Base material : ColorMaterial
Shaders : AmbientShader , DiffusePhongShader and SpecularPhongShader
EnviroBitmapMaterial used to create environmental lighting on a texture-mapped material
Base material : BitmapMaterial
Shaders : EnviroShader
Dot3BitmapMaterial used to create ambient and normal-mapped lighting on a texture-mapped material
Base material : BitmapMaterial
Shaders : AmbientShader and DiffuseDot3Shader ,
Dot3MovieMaterial used to create ambient and normal-mapped lighting on a material based on another Flash movie
Base material : MovieMaterial
Shaders : AmbientShader and DiffuseDot3Shader
以上这些 materials 都是很耗性能的 ,如果你想使用简单点的 shade ,你可以选择CenterLightingMaterial 这种材质的效果就相同于PV3D里的 flat-shaded materials ,Away3D里有两种选择 :
// create a new directional white light source with specific ambient, diffuse and specular parameters var light:DirectionalLight3D = new DirectionalLight3D({color:0xFFFFFF, ambient:0.25, diffuse:0.75, specular:0.9}); light.x = 100; light.z = 500; light.y = 500; scene.addChild(light); // Create an object container to group the objects on the scene group = new ObjectContainer3D(); scene.addChild(group); // Create a new sphere object using a very shiny phong-shaded bitmap material representing the earth var earthMaterial:PhongBitmapMaterial = new PhongBitmapMaterial(Cast.bitmap(earthBitmap)); earthMaterial.shininess = 100; sphere = new Sphere({material:earthMaterial, radius:50, segmentsW:10, segmentsH:10}); sphere.x = ORBITAL_RADIUS; sphere.ownCanvas = true; group.addChild(sphere); // Create a new cube object using a tiled, phong-shaded bitmap material var tiledAway3DMaterial:PhongBitmapMaterial = new PhongBitmapMaterial(Cast.bitmap(away3DBitmap), {repeat:true, scaleX:.5, scaleY:.5}); cube = new Cube({material:tiledAway3DMaterial, width:75, height:75, depth:75}); cube.z = -ORBITAL_RADIUS; cube.ownCanvas = true; group.addChild(cube); // Create a cylinder mapping the earth data again cylinder = new Cylinder({material:earthMaterial, radius:25, height:100, segmentsW:16}); cylinder.x = -ORBITAL_RADIUS; cylinder.ownCanvas = true; group.addChild(cylinder); // Create a torus object and use a checkered, flat-shaded (from white light) bitmap material var checkerBitmapMaterial:WhiteShadingBitmapMaterial = new WhiteShadingBitmapMaterial(Cast.bitmap(checkerBitmap)); torus = new Torus({material:checkerBitmapMaterial, radius:40, tube:10, segmentsT:8, segmentsR:16}); torus.z = ORBITAL_RADIUS; torus.ownCanvas = true; group.addChild(torus); // Create a new cube object using a smoothed, precise, phong-shaded, mat (not shiny) bitmap material var away3DMaterial:PhongBitmapMaterial = new PhongBitmapMaterial(Cast.bitmap(away3DBitmap), {smooth:true, precision:2}); away3DMaterial.shininess = 0; centerCube = new Cube({material:away3DMaterial, width:75, height:75, depth:75}); centerCube.ownCanvas = true; group.addChild(centerCube); // add mouse listeners to all the 3D objects sphere.addOnMouseDown(onMouseDownOnObject); cube.addOnMouseDown(onMouseDownOnObject); cylinder.addOnMouseDown(onMouseDownOnObject); torus.addOnMouseDown(onMouseDownOnObject); centerCube.addOnMouseDown(onMouseDownOnObject);
sphere.ownCanvas = true;
这句话很重要,没有这句话,当 objects 被别的 objects 遮挡了 ,他们可能不会被正确渲染