Away3D - shadows cast by DirectionalLight are off

393 Views Asked by At

I am implementing an Away3D 4.x app where I have some meshes that should cast shadows. I setup a DirectionalLight and a FilteredShadowMapMethod, then apply the method onto the materials. However, as you can see on the screenshot, the light as if ignores objects that are close to the ground (their Y position is small) and only casts shadows for objects that are above certain Y coordinate. You can see this nicely on the bricks on the right. enter image description here

I don't understand what I am doing wrong, could someone please help? This is the main part of my code:

light1 = new DirectionalLight(0, -3, -5);
light1.ambient = 0.5;
light1.diffuse = 1.0;
light1.specular = 1.0;

lightPicker = new StaticLightPicker([light1]);      
this.scene.addChild(light1);        
shadowMapMethod = new FilteredShadowMapMethod(light1);

groundCloseMaterial = new TextureMaterial(Cast.bitmapTexture(GroundDiffuseClose));
groundCloseMaterial.lightPicker = lightPicker;
groundCloseMaterial.specular = 0;
groundCloseMaterial.ambient = 1;
groundCloseMaterial.shadowMethod = shadowMapMethod;
groundCloseMaterial.repeat = true;
groundCloseMaterial.mipmap = false;

groundClose = new Mesh(new PlaneGeometry(MAX_WORLD_X*2, MAX_WORLD_Z*2), groundCloseMaterial);
groundClose.geometry.scaleUV(20, 20);
groundClose.y = 0.1;


//-- create bricks
greyBrickMaterial = new TextureMaterial(Cast.bitmapTexture(BrickDiffuse));
greyBrickMaterial.specularMap = Cast.bitmapTexture(BrickSpecular);
greyBrickMaterial.normalMap = Cast.bitmapTexture(BrickNormals);
greyBrickMaterial.lightPicker = lightPicker;
greyBrickMaterial.mipmap = false;
greyBrickMaterial.specular = 1;
greyBrickMaterial.ambient = 1;
greyBrickMaterial.shadowMethod = shadowMapMethod;

Bricks are created as just CubeMeshes with the brick material. Similarly, the are some SphereMeshes with their own material, that is created the same way as greyBrickMaterial, flying around and one huge CubeMesh in the distance.

Notice also the weird light effect on the big brown cube - that kind of lighting just doesn't make sense!

1

There are 1 best solutions below

0
Lenka Pitonakova On

Ok with a help of a community member on Away3d forums, I found a solution.

In short, the light's position values should be < 1.0 to prevent strong reflections on some surfaces:

light1 = new DirectionalLight(0., -0.7, -0.7);

Secondly, playing with the .epsilon attribute of the shadowMapMethod helps bring the shadows to start from where they should, rather than to be offset:

shadowMapMethod = new FilteredShadowMapMethod(light1);
shadowMapMethod.epsilon = 0.08;

Long answer here: http://away3d.com/forum/viewthread/5787/