Shadows cast by DirectionalLight are off and at weird locations

Software: Away3D 4.x

Elendurwen, Newbie
Posted: 12 February 2015 08:09 PM   Total Posts: 4

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.

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*2MAX_WORLD_Z*2), groundCloseMaterial);
groundClose.geometry.scaleUV(2020);
groundClose.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!

 

   

Pierce, Jr. Member
Posted: 20 February 2015 12:17 AM   Total Posts: 40   [ # 1 ]

is this still broken?

   

Elendurwen, Newbie
Posted: 20 February 2015 12:53 AM   Total Posts: 4   [ # 2 ]

Yes, although I did sort out the weird light on the large box by changing the specular texture. However, I haven’t been able to figure out how to make the shadows right.

   

Pierce, Jr. Member
Posted: 20 February 2015 01:18 AM   Total Posts: 40   [ # 3 ]

do the bricks need a shadowmethod assigned to just cast shadows? because if you disable them receiving shadows by not adding it that may help. also try playing with the epsilon value of the shadowmethod, or scaling your scene, as it could be a precision issue. also experiment with different shadow methods, as a harder one may be more accurate, or a softer one may better hide errors. and play with the direction of the light to see how different angles affect it. basically just play with everything is the best advice i’ve got right now, but maybe you’ve already done a lot of that :/

   

Elendurwen, Newbie
Posted: 20 February 2015 01:33 AM   Total Posts: 4   [ # 4 ]

Thanks for the suggestions, you are right, I already played A LOT with the direction of the light as well as different shading methods. But I will try the other suggestions.

Everything needs to both cast and receive shadows, as there are robots that move around and build stuff.

Could you maybe please explain to me what the light direction actually means? I played a lot with different values and while I think it makes sense to me, some situations just don’t. Is the vector relative to an object? If yes, then which point of the mesh? Or is it relative to something else?

   

Pierce, Jr. Member
Posted: 20 February 2015 02:32 AM   Total Posts: 40   [ # 5 ]

relative to the scene. as i understand it, the light direction is a unit vector, so (1,0,0) would point to +x and (0,1,0) would point straight up and (0,-1,0) would point straight down and something like (.707, -.707,  0) would point down at a 45 degree angle along the x-axis. you don’t have to normalize it yourself (although it couldn’t hurt), so I’d suggest just setting it to ( {+/-}1, -1, {+/-}1 ) so you’ll be 45 degrees to each axis. that should be a good angle to debug the shadows.

yeah try messing with scale of your geometry and epsilon on a few different methods and screencap the differences between settings.

   

Pierce, Jr. Member
Posted: 20 February 2015 02:36 AM   Total Posts: 40   [ # 6 ]

and knowing the actual size/dimensions of your geometry currently might be useful information too

   

Elendurwen, Newbie
Posted: 20 February 2015 11:41 AM   Total Posts: 4   [ # 7 ]

Ok - I finally fixed this, thanks a lot for your help!

There were two things:

1. Setting the light position with values < 1.0 to achieve light angle instead of using values > 1.0 is better. It prevented strong reflection on the ‘ground’ plane.

2. Playing with the .epsilon attribute of the shadow map method helped to bring the shadows closer to the objects, whereas before the shadows had an offset in direction away from the light. The default epsilon was 0.02, I set it to 0.08.

The light still changes its X position slightly when you move / rotate the camera but I can live with that, looks so much better now!

   
   

X

Away3D Forum

Member Login

Username

Password

Remember_me



X