Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <html>
  <head>
  </head>
  
  <body>
    <canvas></canvas>
    <script src="https://cdn.babylonjs.com/2-2/babylon.js"></script>
  </body>
</html>
              
            
!

CSS

              
                html, body {
  margin:0;
  
  width: 100%;
  height: 100%;
}

canvas {
  height: 100%;
}
              
            
!

JS

              
                var canvas = document.querySelector("canvas");

var engine,
	scene,
	camera,
	shadowGenerator,
  boxes = [];

engine = new BABYLON.Engine(canvas, true);
	scene = new BABYLON.Scene(engine);

    // Change the scene background color to green.
    scene.clearColor = new BABYLON.Color3(1, 1, 1);

    // This creates and positions a free camera
    camera = new BABYLON.FreeCamera("camera1", new BABYLON.Vector3(0, 40, -20), scene);

    // This targets the camera to scene origin
    camera.setTarget(new BABYLON.Vector3(100, -40, 100));

    // This attaches the camera to the canvas
    camera.attachControl(canvas, false);

    // This creates a light, aiming 0,1,0 - to the sky.
    var light = new BABYLON.DirectionalLight("dir01", new BABYLON.Vector3(-1, -2, -1), scene);
	light.position = new BABYLON.Vector3(40, 80, 40);
	light.intensity = 0.5;
	

    // Let's try our built-in 'sphere' shape. Params: name, subdivisions, size, scene
    var sphere = BABYLON.Mesh.CreateSphere("sphere1", 16, 2, scene);

    // Move the sphere upward 1/2 its height
    sphere.position.y = 1;

    // Let's try our built-in 'ground' shape.  Params: name, width, depth, subdivisions, scene
    var ground = BABYLON.Mesh.CreateGround("ground1", 400, 400, 2, scene);
	ground.position.y = 5;
	
	// Shadows
	shadowGenerator = new BABYLON.ShadowGenerator(4096, light);
	// shadowGenerator.bias = 0.00001;
	shadowGenerator.bias = 0.000005;
    // shadowGenerator.usePoissonSampling = true; 
	// shadowGenerator.getShadowMap().refreshRate = 5;
	
	console.log(shadowGenerator);
	shadowGenerator.getShadowMap().renderList.push(sphere);

	ground.receiveShadows = true;

for (var i = 0; i < 200; i++) {
  var box = BABYLON.Mesh.CreateBox("gameObject" + i, {
    width: Math.random() * 10,
    height: Math.random() * 10,
    depth: Math.random() * 10
  }, scene);
  box.position = new BABYLON.Vector3(Math.random() * 100, 5, Math.random() * 100);
  box.material = new BABYLON.StandardMaterial("texture1", scene);
  box.material.diffuseColor = new BABYLON.Color3(1.0, 0.2, 0.0);

  shadowGenerator.getShadowMap().renderList.push(box);
  box.receiveShadows = true;
  boxes.push(box);
}

engine.runRenderLoop(function () {
  if (new Date().getSeconds() % 2 === 0) {
    shadowGenerator.useVarianceShadowMap = true;
    
    for (var i = 0; i < boxes.length; i++) {
      boxes[i].material.diffuseColor = new BABYLON.Color3(1, 1, 1);
    }
  } else {
    shadowGenerator.useVarianceShadowMap = false;
    for (var i = 0; i < boxes.length; i++) {
      boxes[i].material.diffuseColor = new BABYLON.Color3(0, 1, 1);
    }
  }
  scene.render();
});

window.addEventListener("resize", function () {
  engine.resize();
});
              
            
!
999px

Console