i need help on primitives casting shadows.

Software: Away3D 4.x

Annita, Newbie
Posted: 16 March 2012 04:46 PM   Total Posts: 3

Hello,  I am very new at this,  I’m not a programmer so, please, be nice to me.

I’ve been stealing code from the forums,  >.< and now I can finally render some primitives, but there is no shadow..  I have one cube acting as ground and a few primitives.  but the primitives don’t cast any shadow to the cube (ground)

Can anyone give me the code for shadow casting;

This is what I have:

private function initLights():void
  {
   
//create a light for the camera
   
pointLight = new PointLight();
   
   
pointLight.y+=500;
   
   
scene.addChild(pointLight);
   
trace("coord Luz x="+pointLight.x"   y="+pointLight.y+"     z="+pointLight.z);
   
   
lightPicker = new StaticLightPicker([pointLight]);
   var 
sunPointLight:PointLight = new PointLight();
   
sunPointLight.specular 0;
   
scene.addChild(sunPointLight);
  
  


Thanks a lot in advance.

   

Avatar
Matse, Sr. Member
Posted: 16 March 2012 05:20 PM   Total Posts: 149   [ # 1 ]

Hi Annita,

First you need a DirectionalLight, as PointLight doesn’t cast shadows, and set its .castsShadows property to true (the default value might be “true” already, not sure anymore).

Then you need to add a ShadowMethod to all materials on which you want shadows to appear :

var directionalLight:DirectionalLight = new DirectionalLight();
directionalLight.castsShadows true
var shadowMethod:FilteredShadowMapMethod = new FilteredShadowMapMethod(directionalLight);
material.shadowMethod shadowMethod 

That should be it, there are several types of shadowMethod, you might want to try the others.

   

Annita, Newbie
Posted: 16 March 2012 06:03 PM   Total Posts: 3   [ # 2 ]

Thank you very much.  It’s working.  smile

   

NemoStein, Newbie
Posted: 15 November 2012 05:44 AM   Total Posts: 4   [ # 3 ]

@Matse, they do, in fact (ATM at least).
Just be sure to set radius and fallOff correctly and use the HardShadowMapMethod.

var light:PointLight = new PointLight();
light.castsShadows true;
light.radius 500;
light.fallOff 750;
light.500;

material.shadowMethod = new HardShadowMapMethod(light); 

note: I’m only answer this 8 months after because Google led me here and I was looking for the same thing that @Annita.

   
   

X

Away3D Forum

Member Login

Username

Password

Remember_me



X