Question

I am fairly new to away3d. After putting together a basic scene with shaded objects, I was wondering why they don't case shadows onto each other?

In my example there is a cube above a plane with a directional light above the both. How can I make the cube cast a shadow onto the plane under it?

The example is written using away 3d 3.6

package  {

import flash.display.MovieClip;
import flash.events.*;
import away3d.containers.View3D;
import away3d.primitives.Cube;
import away3d.primitives.Plane;
import away3d.lights.DirectionalLight3D;
import away3d.materials.PhongColorMaterial;
import away3d.materials.ColorMaterial;
import flash.geom.Vector3D;


public class Test7 extends MovieClip {

    public var view:View3D;
    public var light:DirectionalLight3D;

    public var cube:Cube;
    public var plane:Plane;     

    public function Test7() {
        // constructor code
        view = new View3D();
        view.x = 200;
        view.y = 200;
        view.z = 150;

        light = new DirectionalLight3D();
        light.direction = new Vector3D(0, -1, 0);
        light.brightness = 5;
        view.scene.addLight(light);

        plane = new Plane();
        plane.material = new PhongColorMaterial(0xCCCCCC);
        plane.width = 1000;
        plane.height = 1000;
        plane.segmentsH = 
        plane.segmentsW = 10;
        plane.y = -100;
        view.scene.addChild(plane);

        cube = new Cube();
        cube.rotationX = 45;
        cube.rotationY = 45;
        cube.segmentsD = 
        cube.segmentsH = 
        cube.segmentsW = 10;
        cube.material = new PhongColorMaterial(0x330099);
        view.scene.addChild(cube);

        addChild(view);
        addEventListener(Event.ENTER_FRAME, render);            
    }

    public function render(e:Event):void {
        view.render();
    }
}

}

Was it helpful?

Solution

Calculation of shadows in real-time is too heavy for CPU so it require GPU (Away 3D 4.0+) You should bake shadows, diffuse lighting, global illumination, ambient occlusion, etc. to texture using graphical editor. That will give you static lighting with super high quality because pre-calculation of global illumination can take plenty of time instead of 1\30 second in rea time. To make scene more dynamic You can add environment cube map to the model or primitive lighting.

Here is demo with precomputed shadows: http://alternativaplatform.com/ru/demos/temple/ And this one with env map: http://alternativaplatform.com/swf/demos/mobilephone/mobilephone.swf

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top