Disappearing shadows help

Software: Away3D 4.x

OceanBreezeGames, Newbie
Posted: 26 February 2013 08:55 PM   Total Posts: 12

I’m having an issue where my shadows are disappearing on one side of a plane depending on what direction the directional light is “shining”.

In the code below a red sphere is created that casts a shadow on a green plane below it.

If the directional light is created like this:
_light = new DirectionalLight(0.5, -1, -0.2);
then the shadow disappears as you approach the left side of the plane.

If the directional light is created like this (change in x direction):
_light = new DirectionalLight(-0.5, -1, -0.2);
then the shadow disappears as you approach the right side of the plane.

Use the left/right arrow keys to move the object.

Edit: Just wanted to add, I had smaller values before for objects sizes where the shadows didn’t disappear on the edges but I had a different issue where as my object approached the ground the shadow would disappear. Scaling the size of all objects and camera locations fixed the issue but introduced this new issue I’m having now…

package
{
 import away3d
.containers.View3D;
 
import away3d.entities.Mesh;
 
import away3d.lights.DirectionalLight;
 
import away3d.materials.ColorMaterial;
 
import away3d.materials.lightpickers.StaticLightPicker;
 
import away3d.materials.methods.FilteredShadowMapMethod;
 
import away3d.primitives.PlaneGeometry;
 
import away3d.primitives.SphereGeometry;
 
 
import flash.display.Sprite;
 
import flash.events.Event;
 
import flash.events.KeyboardEvent;
 
import flash.geom.Vector3D;
 
import flash.ui.Keyboard;
 
   
 
[SWF(width='1024',height='768',backgroundColor='#c3d6ea',frameRate='60')]
 
 
public class Main extends Sprite  
 {  
  
private var _view:View3D;
  private var 
_plane:Mesh;  
  private var 
_sphere:Mesh;   
  private var 
_lightPicker:StaticLightPicker;   
  private var 
_light:DirectionalLight;  
  private var 
_shadowMapMethod:FilteredShadowMapMethod;
  private var 
_dir:Number;
  
  public function 
Main()
  
{      
   addEventListener
(Event.ADDED_TO_STAGE,addedToStage);        
  
}
  
  
private function addedToStage(ev:Event):void 
  {         
   _view 
= new View3D();   
   
addChild(_view); 
   
   
_dir 0;
      
   
_light = new DirectionalLight(0.5, -1, -0.2);  
   
_view.scene.addChild(_light);
   
   
_lightPicker = new StaticLightPicker([_light]);     
   
_shadowMapMethod = new FilteredShadowMapMethod(_light);         
      
   var 
greenMaterial:ColorMaterial = new ColorMaterial(0x00FFF00);
   
greenMaterial.lightPicker _lightPicker;
   
greenMaterial.specular 0;   
   
greenMaterial.shadowMethod _shadowMapMethod;
   
_plane = new Mesh(new PlaneGeometry(50000,50000), greenMaterial);   
   
_view.scene.addChild(_plane);
     
   var 
redMaterial:ColorMaterial = new ColorMaterial(0xFF0000);
   
redMaterial.lightPicker _lightPicker;
   
redMaterial.shadowMethod _shadowMapMethod;   
   
_sphere = new Mesh(new SphereGeometry(1000), redMaterial);
   
_sphere.castsShadows true
   
_sphere.position = new Vector3D(0,2000,0);
   
_view.scene.addChild(_sphere);
   
   
_view.camera.position = new Vector3D(0,50000,0);
   
_view.camera.lookAt(new Vector3D(0,0,0));
   
_view.camera.lens.far 100000;
         
   
stage.addEventListener(KeyboardEvent.KEY_DOWNkeyDown);
   
stage.addEventListener(KeyboardEvent.KEY_UPkeyUp);
   
addEventListener(Event.ENTER_FRAMEupdate);
  
}
  
  
private function keyDown(k:KeyboardEvent):void
  {   
   
switch(k.keyCode)
   
{
    
case Keyboard.LEFT
     
_dir = -1;
    break;
    case 
Keyboard.RIGHT
     
_dir 1;
    break;
    default:
     
_dir 0;
    break;
   
}   
  }
  
  
private function keyUp(k:KeyboardEvent):void
  {     
   
switch(k.keyCode)
   
{
    
case Keyboard.LEFT:   
    case 
Keyboard.RIGHT
     
_dir 0;
    break;
   
}
  }
  
  
private function update(ev:Event):void
  {
   _sphere
.position = new Vector3D_sphere.position.x+_dir*100_sphere.position.y_sphere.position.z);
   
_view.render();
  
}
 }
   

OceanBreezeGames, Newbie
Posted: 26 February 2013 09:22 PM   Total Posts: 12   [ # 1 ]

Here is a sample of the other shadow problem where using smaller scaled objects the shadow disappears as it approaches the ground. Use the Up/Down arrow keys to move the cube.

You can clearly see the shadow disappear before the cube begins to intersect the plane.

package
{
 import away3d
.containers.View3D;
 
import away3d.entities.Mesh;
 
import away3d.lights.DirectionalLight;
 
import away3d.materials.ColorMaterial;
 
import away3d.materials.lightpickers.StaticLightPicker;
 
import away3d.materials.methods.FilteredShadowMapMethod;
 
import away3d.primitives.CubeGeometry;
 
import away3d.primitives.PlaneGeometry;
 
import away3d.primitives.SphereGeometry;
 
 
import flash.display.Sprite;
 
import flash.events.Event;
 
import flash.events.KeyboardEvent;
 
import flash.geom.Vector3D;
 
import flash.ui.Keyboard;
 
   
 
[SWF(width='1024',height='768',backgroundColor='#c3d6ea',frameRate='60')]
 
 
public class Main extends Sprite  
 {  
  
private var _view:View3D;
  private var 
_plane:Mesh;  
  private var 
_sphere:Mesh;   
  private var 
_lightPicker:StaticLightPicker;   
  private var 
_light:DirectionalLight;  
  private var 
_shadowMapMethod:FilteredShadowMapMethod;
  private var 
_dir:Number;
  
  public function 
Main()
  
{      
   addEventListener
(Event.ADDED_TO_STAGE,addedToStage);        
  
}
  
  
private function addedToStage(ev:Event):void 
  {         
   _view 
= new View3D();   
   
addChild(_view); 
   
   
_dir 0;
      
   
_light = new DirectionalLight(-0.3, -10);  
   
_view.scene.addChild(_light);
   
   
_lightPicker = new StaticLightPicker([_light]);     
   
_shadowMapMethod = new FilteredShadowMapMethod(_light);         
      
   var 
greenMaterial:ColorMaterial = new ColorMaterial(0x00FFF00);
   
greenMaterial.lightPicker _lightPicker;
   
greenMaterial.specular 0;   
   
greenMaterial.shadowMethod _shadowMapMethod;
   
_plane = new Mesh(new PlaneGeometry(500,500), greenMaterial);   
   
_view.scene.addChild(_plane);
     
   var 
redMaterial:ColorMaterial = new ColorMaterial(0xFF0000);
   
redMaterial.lightPicker _lightPicker;
   
redMaterial.shadowMethod _shadowMapMethod;   
   
   
_sphere = new Mesh(new CubeGeometry(5,5,5), redMaterial);
   
_sphere.rotationY 45;
   
_sphere.rotationZ 45;
   
_sphere.castsShadows true
   
_sphere.position = new Vector3D(0,20,0);
   
_view.scene.addChild(_sphere);
   
   
_view.camera.position = new Vector3D(80,10,0);
   
_view.camera.lookAt(new Vector3D(0,0,0));
   
_view.camera.lens.near 1;
   
_view.camera.lens.far 300;
         
   
stage.addEventListener(KeyboardEvent.KEY_DOWNkeyDown);
   
stage.addEventListener(KeyboardEvent.KEY_UPkeyUp);
   
addEventListener(Event.ENTER_FRAMEupdate);
  
}
  
  
private function keyDown(k:KeyboardEvent):void
  {   
   
switch(k.keyCode)
   
{
    
case Keyboard.UP
     
_dir 1;
    break;
    case 
Keyboard.DOWN
     
_dir = -1;
    break;
    default:
     
_dir 0;
    break;
   
}   
  }
  
  
private function keyUp(k:KeyboardEvent):void
  {     
   
switch(k.keyCode)
   
{
    
case Keyboard.UP:   
    case 
Keyboard.DOWN
     
_dir 0;
    break;
   
}
  }
  
  
private function update(ev:Event):void
  {
   _sphere
.position = new Vector3D_sphere.position.x_sphere.position.y+_dir_sphere.position.z);
   
_view.render();
  
}
 }
   
   

X

Away3D Forum

Member Login

Username

Password

Remember_me



X