Can’t see shadow.. What am I doing wrong?

Software: Away3D 4.x

antonio.lea, Newbie
Posted: 06 August 2012 10:11 PM   Total Posts: 19

I have an simple example that I’ve sorta converted from the broomstick version to Gold but it doesn’t cast the shadow.
When lights are added, I see the specular highlight (images are attached) but no shadows.  What’s the issue here?  Thanks in advance..

package {
 
// import packages not shown here

 // [SWF(width="800", height="600", frameRate="60")]
 
public class PrefabProject extends Sprite {
  
private var _view View3D;
  private var 
_camera Camera3D;
  private var 
sLp0 StaticLightPicker;
  private var 
light DirectionalLight;
  private var 
_count Number 0;
   private var 
sphere2 Mesh;

  public function 
PrefabProject() {
   addEventListener
(Event.ADDED_TO_STAGEinit);
  
}

  
private function init(Event) : void {
   removeEventListener
(Event.ADDED_TO_STAGEinit);
   
stage.addEventListener(Event.RESIZEonResize);
   
stage.align StageAlign.TOP_LEFT;
   
stage.scaleMode StageScaleMode.NO_SCALE;
   
stage.showDefaultContextMenu true;
   
stage.stageFocusRect false;

   
initView();
   
initLights();
   
initContent();
      
addEventListener(Event.ENTER_FRAMErenderFrame);
  
}

  
private function initView() : void {
   _view 
= new View3D();
   
_view.antiAlias 2;
   
_view.backgroundColor 0xFFFFFF;

   
_camera _view.camera;
   
_camera.lens = new PerspectiveLens();
   
_camera.lens.near 10;
   
_camera.lens.far 15000;

   
_camera.= -199.03759765625;
   
_camera.1047.31494140625;
   
_camera.584.86865234375;

   
addChildAt(_view0);
  
}

    
private function initContent() : void {
   
var planeMaterial ColorMaterial = new ColorMaterial(0x009999);
   
planeMaterial.ambientColor 0xCCCCCC;
   
planeMaterial.bothSides true;
   
// SoftShadowMapMethod step size is to change the neighbour filtering
   
var plane Mesh = new Mesh(new PlaneGeometry(2000200011falsetrue));
   
planeMaterial.lightPicker sLp0;
   
planeMaterial.specular 2;
   
plane.rotationX 90;
   
plane.material planeMaterial;
   
plane.castsShadows true;
   
planeMaterial.shadowMethod = new FilteredShadowMapMethod(light);
   
_view.scene.addChild(plane);

   var 
material ColorMaterial = new ColorMaterial(0xFFFF00);
   
material.lightPicker sLp0;
   
material.ambientColor 0xCCCCCC;
   
material.bothSides true;
   
material.ambient 1;
   var 
sphere Mesh = new Mesh(new SphereGeometry(50));
   
sphere.material material;
   
sphere.50;
   
sphere.castsShadows true;
   
material.shadowMethod = new SoftShadowMapMethod(light);
   
_view.scene.addChild(sphere);

   var 
material2 ColorMaterial = new ColorMaterial(0xFF0000);
   
material2.ambientColor 0xCCCCCC;
   
material2.bothSides true;
   
material2.lightPicker sLp0;
   
material2.ambient 1;
   
sphere2 = new Mesh(new SphereGeometry(150));
   
sphere2.material material2;
   
sphere2.250;
   
sphere2.= -250;
   
sphere2.20;
   
sphere2.castsShadows true;
   
material2.shadowMethod = new SoftShadowMapMethod(light);
   
_view.scene.addChild(sphere2);

   
_camera.lookAt(new Vector3D(000));
  
}

  
private function initLights() : void {
   light 
= new DirectionalLight();
   
// light.shadowMapper = new NearDirectionalShadowMapper();
   
light.castsShadows true;
   
// light.color = 0xFFFFFF;
   
light.position = new Vector3D(10100050);
   
light.direction = new Vector3D(000);
   
light.specular .5;
   
light.ambient .5;
   
light.diffuse 1;
   
sLp0 = new StaticLightPicker([light]);
  
}

  
public function renderFrame(Event) : void {
     _view
.render();
  
}

  
private function onResize(event Event) : void {
   _view
.width stage.stageWidth;
   
_view.height stage.stageHeight;
  
}
 }

 

   

Richard Olsson, Administrator
Posted: 07 August 2012 07:58 AM   Total Posts: 1192   [ # 1 ]

I’m not sure what’s wrong. Can you try one of the examples in the away3d-examples-fp11 repository on GitHub that have shadows in them, and make sure that shadows render correctly there for you?

For example: https://github.com/away3d/away3d-examples-fp11/tree/master/src/Basic_Load3DS.as

   

Ivan Moreno, Newbie
Posted: 07 August 2012 01:36 PM   Total Posts: 22   [ # 2 ]

Hello,

I get this Error #2183 in my debugger with your code!

I believe the problem is with how you setup the lights in your scene. The direction value cannot be 0, 0, 0. So, try to use something like 0, -1, 0. Also positioning directional lights using the position reference of the Object3D class doesn’t change anything. These lights are for creating a better reference of “ambient” lights like the sun or some other general lights in your scene.

Best.

   

antonio.lea, Newbie
Posted: 07 August 2012 06:54 PM   Total Posts: 19   [ # 3 ]

I found the reason why mine didn’t really work; I thought the direction property was the actual x,y,z coordinate. 

What does this value actually represent?  It looks like the optimum value is between -1 and 1 but I have no idea what the value actually represents.

——————-

I did some testing I think I sorta get it..

   

Richard Olsson, Administrator
Posted: 08 August 2012 07:54 AM   Total Posts: 1192   [ # 4 ]

The direction vector is the direction of the DirectionalLight. Think of DirectionalLight as a light source that is infinitely far away, so that all rays are falling onto the lit objects with the same angle (as opposed to a point light where all rays are emitted spherically from a central point.)

With this in mind, the DirectionalLight can be thought of as the sun, and the direction properties define the angle with which the rays hit the object, i.e. the vector between the sun and the scene.

If you set it to (0,-1,0) it will be shining straight down from above (Y value points down.) But you could also set it to, for instance, something like (1,-4,1) in which case it will be shining down, slightly to the right and slightly inwards in the scene.

All of this also means that the position of a directional light is unimportant, since only the direction is used, and the math assumes that the light source is positioned infinitely far away.

   

antonio.lea, Newbie
Posted: 10 August 2012 12:43 AM   Total Posts: 19   [ # 5 ]

0,-1,0 will shoot straight down but what’s the difference if (0,-1,0) becomes (0,-4,0)?

   

Richard Olsson, Administrator
Posted: 10 August 2012 08:53 AM   Total Posts: 1192   [ # 6 ]

There’s no difference.

   
   

X

Away3D Forum

Member Login

Username

Password

Remember_me



X