`
sjkgxf7191
  • 浏览: 251716 次
  • 性别: Icon_minigender_1
  • 来自: 上海
社区版块
存档分类
最新评论

Away3D(九):Lighting & shading

阅读更多

Away3D中的光照可以分为三个基本要素:

  • the light source(s) defining the properties of the light(s)
  • light source(s) 定义了光照的属性
  • shaders providing algorithms that determine how a light source interacts with a material
  • shaders 提供一些决定光源如何同材质交互的算法
  • a material type combining different shaders along with base colours or bitmaps
  • 一种组合 了不同 shaders 和 colors 或者 bitmaps 的 material type

 

第一个同PV3D不同之处是我们可以指定超过一个光源 。这样会加大CPU的负担,但同时也可以制造出更加真实的场景渲染。

 

三种主要的 light sources:

  • AmbientLight3D which has no position and provides a uniform ambient light to all objects
  • AmbientLight3D 环境光源 )没有空间坐标,他为所有的 object 提供了一种统一的环境光照
  • DirectionalLight3D which provides light from a specified position but with a strength that does not diminish with distance
  • DirectionalLight3D 定向光源 ),有一个空间坐标,有一个不会减弱的光照强度
  • PointLight3D providing light from a specified position that weakens in intensity with distance
  • PointLight3D 点光源 ),有一个空间坐标,光照强度会随着距离的增加而减弱

以下几种 shaders:

  • AmbientShader which provides ambient shading to a triangle face
  • AmbientShader 为一个三角面提供环境阴影
  • DiffusePhongShader which, depending on the angle between the light source and a triangle face, produces a diffuse shading pattern
  • DiffusePhongShader 根据光源和三角面之间所成的角度,产生一个散射阴影
  • SpecularPhongShader which produces specular shading on triangles to imitate a surface that is reflecting light, depending on the observer’s position and the light position
  • SpecularPhongShader 根据观察者和光源的位置,为三角面产生一个模拟的反射光源的效果
  • EnviroShader allowing for environment mapping, producing a reflection from a surrounding environment on an object, independent of a light source. Requires bitmap data for the environment
  • EnviroShader 根据光源位置和环境贴图,给 object 添加一个环境贴图反射的映射
  • DiffuseDot3Shader to increase scene reality by adding more small scale structure through the use of normal mapping to an object. Requires bitmap data for the normal map
  • DiffuseDot3Shader 通过增加更多的 structure 来增加场景的真实感

以上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里有两种选择

  • ShadingColorMaterial for simple flat shading of a ColorMaterial
  • WhiteShadingBitmapMaterial for simple flat shading of a BitmapMaterial , but assuming that the light source is always white (independent of colour given to light source).

 

  // 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 遮挡了 ,他们可能不会被正确渲染

 

 

 

0
0
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics