Skip to content

Instantly share code, notes, and snippets.

@demonixis
Last active August 29, 2015 14:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save demonixis/11219632 to your computer and use it in GitHub Desktop.
Save demonixis/11219632 to your computer and use it in GitHub Desktop.
This scene is working finel on Windows and Linux but there are lighting issue when we set the receiveShadows flags to true on an object. In this demo the ground's bottom must be highlited but it's not on Windows Phone 8.1 and Mac OS X.
'use strict';
window.onload = function () {
var canvas = document.getElementById("renderCanvas");
var engine = new BABYLON.Engine(canvas, true);
var scene = new BABYLON.Scene(engine);
// CAMERA
var camera = new BABYLON.ArcRotateCamera("ArcRotateCamera", 1, 0.8, 10, new BABYLON.Vector3(15, 1, 15), scene);
camera.minZ = 0.1;
camera.maxZ = 5000000;
scene.activeCamera.attachControl(canvas);
// LIGHTS
var light = new BABYLON.DirectionalLight("dir01", new BABYLON.Vector3(-1, -2, -1), scene);
light.position = new BABYLON.Vector3(20, 40, 20);
light.diffuse = new BABYLON.Color3(1, 1, 1);
light.specular = new BABYLON.Color3(0.6, 0.6, 0.6);
light.intensity = 0.6;
var dirLight2 = new BABYLON.DirectionalLight("Dir1", new BABYLON.Vector3(0, 1, 0), scene);
dirLight2.specular = new BABYLON.Color3(0.5, 0.5, 0.5);
dirLight2.diffuse = new BABYLON.Color3(1.,1., 1.);
dirLight2.intensity = 0.5;
dirLight2.position = new BABYLON.Vector3(0,10,0);
var hemiLight = new BABYLON.HemisphericLight("Hemi0", new BABYLON.Vector3(0, 1, 0), scene);
hemiLight.diffuse = new BABYLON.Color3(0.8, 0.8, 0.8);
hemiLight.specular = new BABYLON.Color3(0.1, 0.1, 0.1);
hemiLight.groundColor = new BABYLON.Color3(1, 0, 0);
hemiLight.intensity = 1.;
var pointLight = new BABYLON.PointLight("Point0", new BABYLON.Vector3(0, 0, 0), scene);
pointLight.diffuse = new BABYLON.Color3(0.6, 0.6, 0.6);
pointLight.specular = new BABYLON.Color3(0.5, 0.5, 0.5 );
pointLight.intensity = 0.3;
// SHADOWS
var shadowGenerator = new BABYLON.ShadowGenerator(1024, light);
shadowGenerator.useVarianceShadowMap = false;
// OBJECTS
var ground = BABYLON.Mesh.CreateBox("box", 5, scene);
ground.position = new BABYLON.Vector3(10, 0, 10);
ground.material = new BABYLON.StandardMaterial("mat", scene);
ground.material.ambientColor = new BABYLON.Color3(0, 0, 0);
ground.material.diffuseColor = new BABYLON.Color3(1, 1, 1);
ground.material.specularColor = new BABYLON.Color3(0.01, 0.01, 0.01);
ground.scaling = new BABYLON.Vector3(10, 0.1, 10);
ground.material.diffuseTexture = new BABYLON.Texture("images/ground.png", scene);
ground.receiveShadows = true;
var boxMaterial = new BABYLON.StandardMaterial("mat2", scene);
boxMaterial.diffuseTexture = new BABYLON.Texture("images/box.png", scene);
var box = null;
for (var i = 0; i < 15; i++) {
box = BABYLON.Mesh.CreateBox("box" + i, 1, scene);
box.position = new BABYLON.Vector3(Math.random() * 25, 0.75, Math.random() * 25);
box.material = boxMaterial;
shadowGenerator.getShadowMap().renderList.push(box);
}
// MAIN
engine.runRenderLoop(function() {
scene.render();
});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment