Shadows
Heaps has support for real-time shadows. Objects can both cast and receive shadows. This is set at a material level. In order to for shadows to work properly normals need to be calculated for your geometry. light.
//Create a floor plane where we can view our cast shadowsvar floor = new h3d.prim.Cube(10, 10, 0.1);//Make sure se add normalsfloor.addNormals();floor.translate( -5, -5, 0);var m = new h3d.scene.Mesh(floor, s3d);//Enabled lightingm.material.mainPass.enableLights = true;//Enable receieiving of shadows. Our floor does not need to castm.material.receiveShadows = true;//Greate some sphere geometry for casting and receiving shadowsvar sphere = new h3d.prim.Sphere(1, 32, 24);//Make sure we add normalssphere.addNormals();var p = new h3d.scene.Mesh(sphere, s3d);p.z = 1;p.material.mainPass.enableLights = true;//Enable casting and receiving of shadowsp.material.shadows = true;p.material.color.setColor(Std.random(0x1000000));var p2 = new h3d.scene.Mesh(sphere, s3d);p2.z = 2.5;p2.x = 1;p2.y = 1;p2.scale(0.5);p2.material.mainPass.enableLights = true;//Enable casting and receiving of shadowsp2.material.shadows = true;p2.material.color.setColor(Std.random(0x1000000));//Set up a light otherwise we don't get any shadowsvar directionalLight = new h3d.scene.DirLight(new h3d.Vector(-0.3, -0.2, -1), s3d);//Move our camera to a position to see the shadowss3d.camera.pos.set(12, 12, 6);//Setup a Camera Controller to move the cameranew h3d.scene.CameraController(s3d).loadFromCamera();
Blurring Shadows
To create a more realistic effect you can blur your shadows. You do so by accessing the shadow pass from the renderer and setting the amount of passes on the blur object. You can see an example here:
var shadow = s3d.renderer.getPass(h3d.pass.ShadowMap);//Increasing the amount of passes increases the amount of blur applied to the shadowshadow.blur.passes = 3;
