Browse Source

Fixing bug with CreateScreenshot

David Catuhe 10 years ago
parent
commit
d7203532d0

+ 4 - 22
Babylon/Lights/Shadows/babylon.shadowGenerator.js

@@ -44,28 +44,11 @@ var BABYLON;
                         _this._effect.setMatrix("diffuseMatrix", alphaTexture.getTextureMatrix());
                     }
                     // Bones
-                    var useBones = mesh.skeleton && scene.skeletonsEnabled && mesh.isVerticesDataPresent(BABYLON.VertexBuffer.MatricesIndicesKind) && mesh.isVerticesDataPresent(BABYLON.VertexBuffer.MatricesWeightsKind);
-                    if (useBones) {
+                    if (mesh.useBones) {
                         _this._effect.setMatrices("mBones", mesh.skeleton.getTransformMatrices());
                     }
-                    if (hardwareInstancedRendering) {
-                        mesh._renderWithInstances(subMesh, BABYLON.Material.TriangleFillMode, batch, _this._effect, engine);
-                    }
-                    else {
-                        if (batch.renderSelf[subMesh._id]) {
-                            _this._effect.setMatrix("world", mesh.getWorldMatrix());
-                            // Draw
-                            mesh._draw(subMesh, BABYLON.Material.TriangleFillMode);
-                        }
-                        if (batch.visibleInstances[subMesh._id]) {
-                            for (var instanceIndex = 0; instanceIndex < batch.visibleInstances[subMesh._id].length; instanceIndex++) {
-                                var instance = batch.visibleInstances[subMesh._id][instanceIndex];
-                                _this._effect.setMatrix("world", instance.getWorldMatrix());
-                                // Draw
-                                mesh._draw(subMesh, BABYLON.Material.TriangleFillMode);
-                            }
-                        }
-                    }
+                    // Draw
+                    mesh._processRendering(subMesh, _this._effect, BABYLON.Material.TriangleFillMode, batch, hardwareInstancedRendering, function (isInstance, world) { return _this._effect.setMatrix("world", world); });
                 }
                 else {
                     // Need to reset refresh rate of the shadowMap
@@ -136,7 +119,6 @@ var BABYLON;
             }
             var attribs = [BABYLON.VertexBuffer.PositionKind];
             var mesh = subMesh.getMesh();
-            var scene = mesh.getScene();
             var material = subMesh.getMaterial();
             // Alpha test
             if (material && material.needAlphaTesting()) {
@@ -151,7 +133,7 @@ var BABYLON;
                 }
             }
             // Bones
-            if (mesh.skeleton && scene.skeletonsEnabled && mesh.isVerticesDataPresent(BABYLON.VertexBuffer.MatricesIndicesKind) && mesh.isVerticesDataPresent(BABYLON.VertexBuffer.MatricesWeightsKind)) {
+            if (mesh.useBones) {
                 attribs.push(BABYLON.VertexBuffer.MatricesIndicesKind);
                 attribs.push(BABYLON.VertexBuffer.MatricesWeightsKind);
                 defines.push("#define BONES");

+ 5 - 26
Babylon/Lights/Shadows/babylon.shadowGenerator.ts

@@ -94,33 +94,13 @@
                     }
 
                     // Bones
-                    var useBones = mesh.skeleton && scene.skeletonsEnabled && mesh.isVerticesDataPresent(VertexBuffer.MatricesIndicesKind) && mesh.isVerticesDataPresent(VertexBuffer.MatricesWeightsKind);
-
-                    if (useBones) {
+                    if (mesh.useBones) {
                         this._effect.setMatrices("mBones", mesh.skeleton.getTransformMatrices());
                     }
 
-                    if (hardwareInstancedRendering) {
-                        mesh._renderWithInstances(subMesh, Material.TriangleFillMode, batch, this._effect, engine);
-                    } else {
-                        if (batch.renderSelf[subMesh._id]) {
-                            this._effect.setMatrix("world", mesh.getWorldMatrix());
-
-                            // Draw
-                            mesh._draw(subMesh, Material.TriangleFillMode);
-                        }
-
-                        if (batch.visibleInstances[subMesh._id]) {
-                            for (var instanceIndex = 0; instanceIndex < batch.visibleInstances[subMesh._id].length; instanceIndex++) {
-                                var instance = batch.visibleInstances[subMesh._id][instanceIndex];
-
-                                this._effect.setMatrix("world", instance.getWorldMatrix());
-
-                                // Draw
-                                mesh._draw(subMesh, Material.TriangleFillMode);
-                            }
-                        }
-                    }
+                    // Draw
+                    mesh._processRendering(subMesh, this._effect, Material.TriangleFillMode, batch, hardwareInstancedRendering,
+                        (isInstance, world) => this._effect.setMatrix("world", world));
                 } else {
                     // Need to reset refresh rate of the shadowMap
                     this._shadowMap.resetRefreshCounter();
@@ -157,7 +137,6 @@
             var attribs = [VertexBuffer.PositionKind];
 
             var mesh = subMesh.getMesh();
-            var scene = mesh.getScene();
             var material = subMesh.getMaterial();
 
             // Alpha test
@@ -174,7 +153,7 @@
             }
 
             // Bones
-            if (mesh.skeleton && scene.skeletonsEnabled && mesh.isVerticesDataPresent(VertexBuffer.MatricesIndicesKind) && mesh.isVerticesDataPresent(VertexBuffer.MatricesWeightsKind)) {
+            if (mesh.useBones) {
                 attribs.push(VertexBuffer.MatricesIndicesKind);
                 attribs.push(VertexBuffer.MatricesWeightsKind);
                 defines.push("#define BONES");

+ 4 - 1
Babylon/Materials/Textures/babylon.renderTargetTexture.js

@@ -81,6 +81,9 @@ var BABYLON;
         RenderTargetTexture.prototype.render = function (useCameraPostProcess) {
             var scene = this.getScene();
             var engine = scene.getEngine();
+            if (!this.activeCamera) {
+                this.activeCamera = scene.activeCamera;
+            }
             if (this._waitingRenderList) {
                 this.renderList = [];
                 for (var index = 0; index < this._waitingRenderList.length; index++) {
@@ -103,7 +106,7 @@ var BABYLON;
             for (var meshIndex = 0; meshIndex < currentRenderList.length; meshIndex++) {
                 var mesh = currentRenderList[meshIndex];
                 if (mesh) {
-                    if (!mesh.isReady() || (mesh.material && !mesh.material.isReady())) {
+                    if (!mesh.isReady()) {
                         // Reset _currentRefreshId
                         this.resetRefreshCounter();
                         continue;

+ 6 - 2
Babylon/Materials/Textures/babylon.renderTargetTexture.ts

@@ -91,6 +91,10 @@
             var scene = this.getScene();
             var engine = scene.getEngine();
 
+            if (!this.activeCamera) {
+                this.activeCamera = scene.activeCamera;
+            }
+
             if (this._waitingRenderList) {
                 this.renderList = [];
                 for (var index = 0; index < this._waitingRenderList.length; index++) {
@@ -121,7 +125,7 @@
                 var mesh = currentRenderList[meshIndex];
 
                 if (mesh) {
-                    if (!mesh.isReady() || (mesh.material && !mesh.material.isReady())) {
+                    if (!mesh.isReady()) {
                         // Reset _currentRefreshId
                         this.resetRefreshCounter();
                         continue;
@@ -136,7 +140,7 @@
                             this._renderingManager.dispatch(subMesh);
                         }
                     }
-                }
+                }                
             }
 
             if (!this._doNotChangeAspectRatio) {

+ 2 - 2
Babylon/Materials/babylon.standardMaterial.js

@@ -285,7 +285,7 @@ var BABYLON;
                         defines.push("#define VERTEXALPHA");
                     }
                 }
-                if (mesh.skeleton && scene.skeletonsEnabled && mesh.isVerticesDataPresent(BABYLON.VertexBuffer.MatricesIndicesKind) && mesh.isVerticesDataPresent(BABYLON.VertexBuffer.MatricesWeightsKind)) {
+                if (mesh.useBones) {
                     attribs.push(BABYLON.VertexBuffer.MatricesIndicesKind);
                     attribs.push(BABYLON.VertexBuffer.MatricesWeightsKind);
                     defines.push("#define BONES");
@@ -335,7 +335,7 @@ var BABYLON;
             this.bindOnlyWorldMatrix(world);
             this._effect.setMatrix("viewProjection", scene.getTransformMatrix());
             // Bones
-            if (mesh.skeleton && scene.skeletonsEnabled && mesh.isVerticesDataPresent(BABYLON.VertexBuffer.MatricesIndicesKind) && mesh.isVerticesDataPresent(BABYLON.VertexBuffer.MatricesWeightsKind)) {
+            if (mesh.useBones) {
                 this._effect.setMatrices("mBones", mesh.skeleton.getTransformMatrices());
             }
             if (scene.getCachedMaterial() !== this) {

+ 2 - 2
Babylon/Materials/babylon.standardMaterial.ts

@@ -337,7 +337,7 @@
                         defines.push("#define VERTEXALPHA");
                     }
                 }
-                if (mesh.skeleton && scene.skeletonsEnabled && mesh.isVerticesDataPresent(VertexBuffer.MatricesIndicesKind) && mesh.isVerticesDataPresent(VertexBuffer.MatricesWeightsKind)) {
+                if (mesh.useBones) {
                     attribs.push(VertexBuffer.MatricesIndicesKind);
                     attribs.push(VertexBuffer.MatricesWeightsKind);
                     defines.push("#define BONES");
@@ -416,7 +416,7 @@
             this._effect.setMatrix("viewProjection", scene.getTransformMatrix());
 
             // Bones
-            if (mesh.skeleton && scene.skeletonsEnabled && mesh.isVerticesDataPresent(VertexBuffer.MatricesIndicesKind) && mesh.isVerticesDataPresent(VertexBuffer.MatricesWeightsKind)) {
+            if (mesh.useBones) {
                 this._effect.setMatrices("mBones", mesh.skeleton.getTransformMatrices());
             }
 

+ 7 - 0
Babylon/Mesh/babylon.abstractMesh.js

@@ -138,6 +138,13 @@ var BABYLON;
             }
             return this._boundingInfo;
         };
+        Object.defineProperty(AbstractMesh.prototype, "useBones", {
+            get: function () {
+                return this.skeleton && this.getScene().skeletonsEnabled && this.isVerticesDataPresent(BABYLON.VertexBuffer.MatricesIndicesKind) && this.isVerticesDataPresent(BABYLON.VertexBuffer.MatricesWeightsKind);
+            },
+            enumerable: true,
+            configurable: true
+        });
         AbstractMesh.prototype._preActivate = function () {
         };
         AbstractMesh.prototype._activate = function (renderId) {

+ 4 - 0
Babylon/Mesh/babylon.abstractMesh.ts

@@ -152,6 +152,10 @@
             return this._boundingInfo;
         }
 
+        public get useBones(): boolean {
+            return this.skeleton && this.getScene().skeletonsEnabled && this.isVerticesDataPresent(VertexBuffer.MatricesIndicesKind) && this.isVerticesDataPresent(VertexBuffer.MatricesWeightsKind);
+        }
+        
         public _preActivate(): void {
         }
 

+ 37 - 23
Babylon/Mesh/babylon.mesh.js

@@ -459,6 +459,34 @@ var BABYLON;
             this._draw(subMesh, fillMode, instancesCount);
             engine.unBindInstancesBuffer(this._worldMatricesInstancesBuffer, offsetLocations);
         };
+        Mesh.prototype._processRendering = function (subMesh, effect, fillMode, batch, hardwareInstancedRendering, onBeforeDraw) {
+            var scene = this.getScene();
+            var engine = scene.getEngine();
+            if (hardwareInstancedRendering) {
+                this._renderWithInstances(subMesh, fillMode, batch, effect, engine);
+            }
+            else {
+                if (batch.renderSelf[subMesh._id]) {
+                    // Draw
+                    if (onBeforeDraw) {
+                        onBeforeDraw(false, this.getWorldMatrix());
+                    }
+                    this._draw(subMesh, fillMode);
+                }
+                if (batch.visibleInstances[subMesh._id]) {
+                    for (var instanceIndex = 0; instanceIndex < batch.visibleInstances[subMesh._id].length; instanceIndex++) {
+                        var instance = batch.visibleInstances[subMesh._id][instanceIndex];
+                        // World
+                        var world = instance.getWorldMatrix();
+                        if (onBeforeDraw) {
+                            onBeforeDraw(true, world);
+                        }
+                        // Draw
+                        this._draw(subMesh, fillMode);
+                    }
+                }
+            }
+        };
         Mesh.prototype.render = function (subMesh) {
             var scene = this.getScene();
             // Managing instances
@@ -494,26 +522,12 @@ var BABYLON;
             this._bind(subMesh, effect, fillMode);
             var world = this.getWorldMatrix();
             effectiveMaterial.bind(world, this);
-            // Instances rendering
-            if (hardwareInstancedRendering) {
-                this._renderWithInstances(subMesh, fillMode, batch, effect, engine);
-            }
-            else {
-                if (batch.renderSelf[subMesh._id]) {
-                    // Draw
-                    this._draw(subMesh, fillMode);
+            // Draw
+            this._processRendering(subMesh, effect, fillMode, batch, hardwareInstancedRendering, function (isInstance, world) {
+                if (isInstance) {
+                    effectiveMaterial.bindOnlyWorldMatrix(world);
                 }
-                if (batch.visibleInstances[subMesh._id]) {
-                    for (var instanceIndex = 0; instanceIndex < batch.visibleInstances[subMesh._id].length; instanceIndex++) {
-                        var instance = batch.visibleInstances[subMesh._id][instanceIndex];
-                        // World
-                        world = instance.getWorldMatrix();
-                        effectiveMaterial.bindOnlyWorldMatrix(world);
-                        // Draw
-                        this._draw(subMesh, fillMode);
-                    }
-                }
-            }
+            });
             // Unbind
             effectiveMaterial.unbind();
             // Outline - step 2
@@ -560,7 +574,7 @@ var BABYLON;
             var results = [];
             for (var index = 0; index < this.getScene().meshes.length; index++) {
                 var mesh = this.getScene().meshes[index];
-                if (mesh.parent == this) {
+                if (mesh.parent === this) {
                     results.push(mesh);
                 }
             }
@@ -603,7 +617,7 @@ var BABYLON;
         Mesh.prototype.setMaterialByID = function (id) {
             var materials = this.getScene().materials;
             for (var index = 0; index < materials.length; index++) {
-                if (materials[index].id == id) {
+                if (materials[index].id === id) {
                     this.material = materials[index];
                     return;
                 }
@@ -611,7 +625,7 @@ var BABYLON;
             // Multi
             var multiMaterials = this.getScene().multiMaterials;
             for (index = 0; index < multiMaterials.length; index++) {
-                if (multiMaterials[index].id == id) {
+                if (multiMaterials[index].id === id) {
                     this.material = multiMaterials[index];
                     return;
                 }
@@ -846,7 +860,7 @@ var BABYLON;
                     simplifier.simplify(setting, function (newMesh) {
                         _this.addLODLevel(setting.distance, newMesh);
                         //check if it is the last
-                        if (setting.quality == settings[settings.length - 1].quality && successCallback) {
+                        if (setting.quality === settings[settings.length - 1].quality && successCallback) {
                             //all done, run the success callback.
                             successCallback();
                         }

+ 45 - 25
Babylon/Mesh/babylon.mesh.ts

@@ -554,6 +554,40 @@
             engine.unBindInstancesBuffer(this._worldMatricesInstancesBuffer, offsetLocations);
         }
 
+        public _processRendering(subMesh: SubMesh, effect: Effect, fillMode: number, batch: _InstancesBatch, hardwareInstancedRendering: boolean,
+            onBeforeDraw: (isInstance: boolean, world: Matrix) => void) {
+            var scene = this.getScene();
+            var engine = scene.getEngine();
+
+            if (hardwareInstancedRendering) {
+                this._renderWithInstances(subMesh, fillMode, batch, effect, engine);
+            } else {
+                if (batch.renderSelf[subMesh._id]) {
+                    // Draw
+                    if (onBeforeDraw) {
+                        onBeforeDraw(false, this.getWorldMatrix());
+                    }
+
+                    this._draw(subMesh, fillMode);
+                }
+
+                if (batch.visibleInstances[subMesh._id]) {
+                    for (var instanceIndex = 0; instanceIndex < batch.visibleInstances[subMesh._id].length; instanceIndex++) {
+                        var instance = batch.visibleInstances[subMesh._id][instanceIndex];
+
+                        // World
+                        var world = instance.getWorldMatrix();
+                        if (onBeforeDraw) {
+                            onBeforeDraw(true, world);
+                        }
+
+                        // Draw
+                        this._draw(subMesh, fillMode);
+                    }
+                }
+            }
+        }
+
         public render(subMesh: SubMesh): void {
             var scene = this.getScene();
 
@@ -602,28 +636,14 @@
 
             effectiveMaterial.bind(world, this);
 
-            // Instances rendering
-            if (hardwareInstancedRendering) {
-                this._renderWithInstances(subMesh, fillMode, batch, effect, engine);
-            } else {
-                if (batch.renderSelf[subMesh._id]) {
-                    // Draw
-                    this._draw(subMesh, fillMode);
-                }
-
-                if (batch.visibleInstances[subMesh._id]) {
-                    for (var instanceIndex = 0; instanceIndex < batch.visibleInstances[subMesh._id].length; instanceIndex++) {
-                        var instance = batch.visibleInstances[subMesh._id][instanceIndex];
-
-                        // World
-                        world = instance.getWorldMatrix();
+            // Draw
+            this._processRendering(subMesh, effect, fillMode, batch, hardwareInstancedRendering,
+                (isInstance, world) => {
+                    if (isInstance) {
                         effectiveMaterial.bindOnlyWorldMatrix(world);
-
-                        // Draw
-                        this._draw(subMesh, fillMode);
                     }
-                }
-            }
+                });
+
             // Unbind
             effectiveMaterial.unbind();
 
@@ -679,7 +699,7 @@
             var results = [];
             for (var index = 0; index < this.getScene().meshes.length; index++) {
                 var mesh = this.getScene().meshes[index];
-                if (mesh.parent == this) {
+                if (mesh.parent === this) {
                     results.push(mesh);
                 }
             }
@@ -733,7 +753,7 @@
         public setMaterialByID(id: string): void {
             var materials = this.getScene().materials;
             for (var index = 0; index < materials.length; index++) {
-                if (materials[index].id == id) {
+                if (materials[index].id === id) {
                     this.material = materials[index];
                     return;
                 }
@@ -742,7 +762,7 @@
             // Multi
             var multiMaterials = this.getScene().multiMaterials;
             for (index = 0; index < multiMaterials.length; index++) {
-                if (multiMaterials[index].id == id) {
+                if (multiMaterials[index].id === id) {
                     this.material = multiMaterials[index];
                     return;
                 }
@@ -1042,7 +1062,7 @@
                     simplifier.simplify(setting,(newMesh) => {
                         this.addLODLevel(setting.distance, newMesh);
                         //check if it is the last
-                        if (setting.quality == settings[settings.length - 1].quality && successCallback) {
+                        if (setting.quality === settings[settings.length - 1].quality && successCallback) {
                             //all done, run the success callback.
                             successCallback();
                         }
@@ -1175,7 +1195,7 @@
             return tiledGround;
         }
 
-        public static CreateGroundFromHeightMap(name: string, url: string, width: number, height: number, subdivisions: number, minHeight: number, maxHeight: number, scene: Scene, updatable?: boolean, onReady?:(mesh: GroundMesh) => void): GroundMesh {
+        public static CreateGroundFromHeightMap(name: string, url: string, width: number, height: number, subdivisions: number, minHeight: number, maxHeight: number, scene: Scene, updatable?: boolean, onReady?: (mesh: GroundMesh) => void): GroundMesh {
             var ground = new GroundMesh(name, scene);
             ground._subdivisions = subdivisions;
 

+ 10 - 11
Babylon/PostProcess/babylon.ssaoRenderingPipeline.js

@@ -18,14 +18,6 @@ var BABYLON;
             this.SSAOBlurHRenderEffect = "SSAOBlurHRenderEffect";
             this.SSAOBlurVRenderEffect = "SSAOBlurVRenderEffect";
             this.SSAOCombineRenderEffect = "SSAOCombineRenderEffect";
-            this._scene = null;
-            this._depthTexture = null;
-            this._randomTexture = null;
-            this._originalColorPostProcess = null;
-            this._ssaoPostProcess = null;
-            this._blurHPostProcess = null;
-            this._blurVPostProcess = null;
-            this._ssaoCombinePostProcess = null;
             this._firstUpdate = true;
             this._scene = scene;
             // Set up assets
@@ -33,8 +25,8 @@ var BABYLON;
             this._depthTexture = scene.enableDepthRenderer().getDepthMap(); // Force depth renderer "on"
             this._originalColorPostProcess = new BABYLON.PassPostProcess("SSAOOriginalSceneColor", 1.0, null, BABYLON.Texture.BILINEAR_SAMPLINGMODE, scene.getEngine(), false);
             this._createSSAOPostProcess(ratio);
-            this._blurHPostProcess = new BABYLON.BlurPostProcess("SSAOBlur", new BABYLON.Vector2(1.0, 0.0), 1.0, ratio, null, BABYLON.Texture.BILINEAR_SAMPLINGMODE, scene.getEngine(), false);
-            this._blurVPostProcess = new BABYLON.BlurPostProcess("SSAOBlur", new BABYLON.Vector2(0.0, 1.0), 1.0, ratio, null, BABYLON.Texture.BILINEAR_SAMPLINGMODE, scene.getEngine(), false);
+            this._blurHPostProcess = new BABYLON.BlurPostProcess("SSAOBlurH", new BABYLON.Vector2(1.0, 0.0), 1.0, ratio, null, BABYLON.Texture.BILINEAR_SAMPLINGMODE, scene.getEngine(), false);
+            this._blurVPostProcess = new BABYLON.BlurPostProcess("SSAOBlurV", new BABYLON.Vector2(0.0, 1.0), 1.0, ratio, null, BABYLON.Texture.BILINEAR_SAMPLINGMODE, scene.getEngine(), false);
             this._createSSAOCombinePostProcess();
             // Set up pipeline
             this.addEffect(new BABYLON.PostProcessRenderEffect(scene.getEngine(), this.SSAOOriginalSceneColorEffect, function () {
@@ -62,6 +54,11 @@ var BABYLON;
         SSAORenderingPipeline.prototype.getBlurVPostProcess = function () {
             return this._blurVPostProcess;
         };
+        SSAORenderingPipeline.prototype.dispose = function (cameras) {
+            if (cameras !== undefined)
+                this._scene.postProcessRenderPipelineManager.detachCamerasFromRenderPipeline(this._name, cameras);
+            this._randomTexture.dispose();
+        };
         // Private Methods
         SSAORenderingPipeline.prototype._createSSAOPostProcess = function (ratio) {
             var _this = this;
@@ -115,10 +112,12 @@ var BABYLON;
                 0.2847,
                 -0.0271
             ];
-            this._ssaoPostProcess = new BABYLON.PostProcess("ssao", "ssao", ["sampleSphere"], ["randomSampler"], ratio, null, BABYLON.Texture.BILINEAR_SAMPLINGMODE, this._scene.getEngine(), false);
+            var samplesFactor = 1.0 / 8.0;
+            this._ssaoPostProcess = new BABYLON.PostProcess("ssao", "ssao", ["sampleSphere", "samplesFactor"], ["randomSampler"], ratio, null, BABYLON.Texture.BILINEAR_SAMPLINGMODE, this._scene.getEngine(), false);
             this._ssaoPostProcess.onApply = function (effect) {
                 if (_this._firstUpdate === true) {
                     effect.setArray3("sampleSphere", sampleSphere);
+                    effect.setFloat("samplesFactor", samplesFactor);
                     _this._firstUpdate = false;
                 }
                 effect.setTexture("textureSampler", _this._depthTexture);

+ 21 - 13
Babylon/PostProcess/babylon.ssaoRenderingPipeline.ts

@@ -7,15 +7,15 @@
         public SSAOBlurVRenderEffect: string = "SSAOBlurVRenderEffect";
         public SSAOCombineRenderEffect: string = "SSAOCombineRenderEffect";
 
-        private _scene: Scene = null;
-        private _depthTexture: RenderTargetTexture = null;
-        private _randomTexture: DynamicTexture = null;
+        private _scene: Scene;
+        private _depthTexture: RenderTargetTexture;
+        private _randomTexture: DynamicTexture;
 
-        private _originalColorPostProcess: PassPostProcess = null;
-        private _ssaoPostProcess: PostProcess = null;
-        private _blurHPostProcess: BlurPostProcess = null;
-        private _blurVPostProcess: BlurPostProcess = null;
-        private _ssaoCombinePostProcess: PostProcess = null;
+        private _originalColorPostProcess: PassPostProcess;
+        private _ssaoPostProcess: PostProcess;
+        private _blurHPostProcess: BlurPostProcess;
+        private _blurVPostProcess: BlurPostProcess;
+        private _ssaoCombinePostProcess: PostProcess;
 
         private _firstUpdate: boolean = true;
 
@@ -30,8 +30,8 @@
 
             this._originalColorPostProcess = new PassPostProcess("SSAOOriginalSceneColor", 1.0, null, Texture.BILINEAR_SAMPLINGMODE, scene.getEngine(), false);
             this._createSSAOPostProcess(ratio);
-            this._blurHPostProcess = new BlurPostProcess("SSAOBlur", new Vector2(1.0, 0.0), 1.0, ratio, null, Texture.BILINEAR_SAMPLINGMODE, scene.getEngine(), false);
-            this._blurVPostProcess = new BlurPostProcess("SSAOBlur", new Vector2(0.0, 1.0), 1.0, ratio, null, Texture.BILINEAR_SAMPLINGMODE, scene.getEngine(), false);
+            this._blurHPostProcess = new BlurPostProcess("SSAOBlurH", new Vector2(1.0, 0.0), 1.0, ratio, null, Texture.BILINEAR_SAMPLINGMODE, scene.getEngine(), false);
+            this._blurVPostProcess = new BlurPostProcess("SSAOBlurV", new Vector2(0.0, 1.0), 1.0, ratio, null, Texture.BILINEAR_SAMPLINGMODE, scene.getEngine(), false);
             this._createSSAOCombinePostProcess();
 
             // Set up pipeline
@@ -54,6 +54,12 @@
             return this._blurVPostProcess;
         }
 
+        public dispose(cameras: any): void {
+            if (cameras !== undefined)
+                this._scene.postProcessRenderPipelineManager.detachCamerasFromRenderPipeline(this._name, cameras);
+            this._randomTexture.dispose();
+        }
+
         // Private Methods
         private _createSSAOPostProcess(ratio: number): PostProcess {
             var sampleSphere = [
@@ -74,14 +80,16 @@
                 0.0352, -0.0631, 0.5460,
                 -0.4776, 0.2847, -0.0271
             ];
+            var samplesFactor = 1.0 / 8.0;
 
-            this._ssaoPostProcess = new PostProcess("ssao", "ssao", ["sampleSphere"], ["randomSampler"],
+            this._ssaoPostProcess = new PostProcess("ssao", "ssao", ["sampleSphere", "samplesFactor"], ["randomSampler"],
                                                     ratio, null, Texture.BILINEAR_SAMPLINGMODE,
                                                     this._scene.getEngine(), false);
 
             this._ssaoPostProcess.onApply = (effect: Effect) => {
                 if (this._firstUpdate === true) {
                     effect.setArray3("sampleSphere", sampleSphere);
+                    effect.setFloat("samplesFactor", samplesFactor);
                     this._firstUpdate = false;
                 }
 
@@ -108,8 +116,8 @@
             var size = 512;
 
             this._randomTexture = new BABYLON.DynamicTexture("SSAORandomTexture", size, this._scene, false, BABYLON.Texture.BILINEAR_SAMPLINGMODE);
-            this._randomTexture.wrapU = BABYLON.Texture.WRAP_ADDRESSMODE;
-            this._randomTexture.wrapV = BABYLON.Texture.WRAP_ADDRESSMODE;
+            this._randomTexture.wrapU = Texture.WRAP_ADDRESSMODE;
+            this._randomTexture.wrapV = Texture.WRAP_ADDRESSMODE;
 
             var context = this._randomTexture.getContext();
 

+ 4 - 21
Babylon/Rendering/babylon.depthRenderer.js

@@ -43,28 +43,11 @@ var BABYLON;
                         _this._effect.setMatrix("diffuseMatrix", alphaTexture.getTextureMatrix());
                     }
                     // Bones
-                    var useBones = mesh.skeleton && scene.skeletonsEnabled && mesh.isVerticesDataPresent(BABYLON.VertexBuffer.MatricesIndicesKind) && mesh.isVerticesDataPresent(BABYLON.VertexBuffer.MatricesWeightsKind);
-                    if (useBones) {
+                    if (mesh.useBones) {
                         _this._effect.setMatrices("mBones", mesh.skeleton.getTransformMatrices());
                     }
-                    if (hardwareInstancedRendering) {
-                        mesh._renderWithInstances(subMesh, BABYLON.Material.TriangleFillMode, batch, _this._effect, engine);
-                    }
-                    else {
-                        if (batch.renderSelf[subMesh._id]) {
-                            _this._effect.setMatrix("world", mesh.getWorldMatrix());
-                            // Draw
-                            mesh._draw(subMesh, BABYLON.Material.TriangleFillMode);
-                        }
-                        if (batch.visibleInstances[subMesh._id]) {
-                            for (var instanceIndex = 0; instanceIndex < batch.visibleInstances[subMesh._id].length; instanceIndex++) {
-                                var instance = batch.visibleInstances[subMesh._id][instanceIndex];
-                                _this._effect.setMatrix("world", instance.getWorldMatrix());
-                                // Draw
-                                mesh._draw(subMesh, BABYLON.Material.TriangleFillMode);
-                            }
-                        }
-                    }
+                    // Draw
+                    mesh._processRendering(subMesh, _this._effect, BABYLON.Material.TriangleFillMode, batch, hardwareInstancedRendering, function (isInstance, world) { return _this._effect.setMatrix("world", world); });
                 }
             };
             this._depthMap.customRenderFunction = function (opaqueSubMeshes, alphaTestSubMeshes) {
@@ -96,7 +79,7 @@ var BABYLON;
                 }
             }
             // Bones
-            if (mesh.skeleton && scene.skeletonsEnabled && mesh.isVerticesDataPresent(BABYLON.VertexBuffer.MatricesIndicesKind) && mesh.isVerticesDataPresent(BABYLON.VertexBuffer.MatricesWeightsKind)) {
+            if (mesh.useBones) {
                 attribs.push(BABYLON.VertexBuffer.MatricesIndicesKind);
                 attribs.push(BABYLON.VertexBuffer.MatricesWeightsKind);
                 defines.push("#define BONES");

+ 5 - 25
Babylon/Rendering/babylon.depthRenderer.ts

@@ -58,33 +58,13 @@
                     }
 
                     // Bones
-                    var useBones = mesh.skeleton && scene.skeletonsEnabled && mesh.isVerticesDataPresent(VertexBuffer.MatricesIndicesKind) && mesh.isVerticesDataPresent(VertexBuffer.MatricesWeightsKind);
-
-                    if (useBones) {
+                    if (mesh.useBones) {
                         this._effect.setMatrices("mBones", mesh.skeleton.getTransformMatrices());
                     }
 
-                    if (hardwareInstancedRendering) {
-                        mesh._renderWithInstances(subMesh, Material.TriangleFillMode, batch, this._effect, engine);
-                    } else {
-                        if (batch.renderSelf[subMesh._id]) {
-                            this._effect.setMatrix("world", mesh.getWorldMatrix());
-
-                            // Draw
-                            mesh._draw(subMesh, Material.TriangleFillMode);
-                        }
-
-                        if (batch.visibleInstances[subMesh._id]) {
-                            for (var instanceIndex = 0; instanceIndex < batch.visibleInstances[subMesh._id].length; instanceIndex++) {
-                                var instance = batch.visibleInstances[subMesh._id][instanceIndex];
-
-                                this._effect.setMatrix("world", instance.getWorldMatrix());
-
-                                // Draw
-                                mesh._draw(subMesh, Material.TriangleFillMode);
-                            }
-                        }
-                    }
+                    // Draw
+                    mesh._processRendering(subMesh, this._effect, Material.TriangleFillMode, batch, hardwareInstancedRendering,
+                        (isInstance, world) => this._effect.setMatrix("world", world));
                 }
             };
 
@@ -124,7 +104,7 @@
             }
 
             // Bones
-            if (mesh.skeleton && scene.skeletonsEnabled && mesh.isVerticesDataPresent(VertexBuffer.MatricesIndicesKind) && mesh.isVerticesDataPresent(VertexBuffer.MatricesWeightsKind)) {
+            if (mesh.useBones) {
                 attribs.push(VertexBuffer.MatricesIndicesKind);
                 attribs.push(VertexBuffer.MatricesWeightsKind);
                 defines.push("#define BONES");

+ 7 - 22
Babylon/Rendering/babylon.outlineRenderer.js

@@ -5,6 +5,7 @@ var BABYLON;
             this._scene = scene;
         }
         OutlineRenderer.prototype.render = function (subMesh, batch, useOverlay) {
+            var _this = this;
             if (useOverlay === void 0) { useOverlay = false; }
             var scene = this._scene;
             var engine = this._scene.getEngine();
@@ -19,8 +20,7 @@ var BABYLON;
             this._effect.setColor4("color", useOverlay ? mesh.overlayColor : mesh.outlineColor, useOverlay ? mesh.overlayAlpha : 1.0);
             this._effect.setMatrix("viewProjection", scene.getTransformMatrix());
             // Bones
-            var useBones = mesh.skeleton && scene.skeletonsEnabled && mesh.isVerticesDataPresent(BABYLON.VertexBuffer.MatricesIndicesKind) && mesh.isVerticesDataPresent(BABYLON.VertexBuffer.MatricesWeightsKind);
-            if (useBones) {
+            if (mesh.useBones) {
                 this._effect.setMatrices("mBones", mesh.skeleton.getTransformMatrices());
             }
             mesh._bind(subMesh, this._effect, BABYLON.Material.TriangleFillMode);
@@ -30,24 +30,9 @@ var BABYLON;
                 this._effect.setTexture("diffuseSampler", alphaTexture);
                 this._effect.setMatrix("diffuseMatrix", alphaTexture.getTextureMatrix());
             }
-            if (hardwareInstancedRendering) {
-                mesh._renderWithInstances(subMesh, BABYLON.Material.TriangleFillMode, batch, this._effect, engine);
-            }
-            else {
-                if (batch.renderSelf[subMesh._id]) {
-                    this._effect.setMatrix("world", mesh.getWorldMatrix());
-                    // Draw
-                    mesh._draw(subMesh, BABYLON.Material.TriangleFillMode);
-                }
-                if (batch.visibleInstances[subMesh._id]) {
-                    for (var instanceIndex = 0; instanceIndex < batch.visibleInstances[subMesh._id].length; instanceIndex++) {
-                        var instance = batch.visibleInstances[subMesh._id][instanceIndex];
-                        this._effect.setMatrix("world", instance.getWorldMatrix());
-                        // Draw
-                        mesh._draw(subMesh, BABYLON.Material.TriangleFillMode);
-                    }
-                }
-            }
+            mesh._processRendering(subMesh, this._effect, BABYLON.Material.TriangleFillMode, batch, hardwareInstancedRendering, function (isInstance, world) {
+                _this._effect.setMatrix("world", world);
+            });
         };
         OutlineRenderer.prototype.isReady = function (subMesh, useInstances) {
             var defines = [];
@@ -67,7 +52,7 @@ var BABYLON;
                 }
             }
             // Bones
-            if (mesh.skeleton && mesh.isVerticesDataPresent(BABYLON.VertexBuffer.MatricesIndicesKind) && mesh.isVerticesDataPresent(BABYLON.VertexBuffer.MatricesWeightsKind)) {
+            if (mesh.useBones) {
                 attribs.push(BABYLON.VertexBuffer.MatricesIndicesKind);
                 attribs.push(BABYLON.VertexBuffer.MatricesWeightsKind);
                 defines.push("#define BONES");
@@ -83,7 +68,7 @@ var BABYLON;
             }
             // Get correct effect      
             var join = defines.join("\n");
-            if (this._cachedDefines != join) {
+            if (this._cachedDefines !== join) {
                 this._cachedDefines = join;
                 this._effect = this._scene.getEngine().createEffect("outline", attribs, ["world", "mBones", "viewProjection", "diffuseMatrix", "offset", "color"], ["diffuseSampler"], join);
             }

+ 11 - 31
Babylon/Rendering/babylon.outlineRenderer.ts

@@ -27,8 +27,7 @@
             this._effect.setMatrix("viewProjection", scene.getTransformMatrix());
 
             // Bones
-            var useBones = mesh.skeleton && scene.skeletonsEnabled && mesh.isVerticesDataPresent(BABYLON.VertexBuffer.MatricesIndicesKind) && mesh.isVerticesDataPresent(BABYLON.VertexBuffer.MatricesWeightsKind);
-            if (useBones) {
+            if (mesh.useBones) {
                 this._effect.setMatrices("mBones", mesh.skeleton.getTransformMatrices());
             }
 
@@ -41,27 +40,8 @@
                 this._effect.setMatrix("diffuseMatrix", alphaTexture.getTextureMatrix());
             }
 
-            if (hardwareInstancedRendering) {
-                mesh._renderWithInstances(subMesh, Material.TriangleFillMode, batch, this._effect, engine);
-            } else {
-                if (batch.renderSelf[subMesh._id]) {
-                    this._effect.setMatrix("world", mesh.getWorldMatrix());
-
-                    // Draw
-                    mesh._draw(subMesh, Material.TriangleFillMode);
-                }
-
-                if (batch.visibleInstances[subMesh._id]) {
-                    for (var instanceIndex = 0; instanceIndex < batch.visibleInstances[subMesh._id].length; instanceIndex++) {
-                        var instance = batch.visibleInstances[subMesh._id][instanceIndex];
-
-                        this._effect.setMatrix("world", instance.getWorldMatrix());
-
-                        // Draw
-                        mesh._draw(subMesh, Material.TriangleFillMode);
-                    }
-                }
-            }
+            mesh._processRendering(subMesh, this._effect, Material.TriangleFillMode, batch, hardwareInstancedRendering,
+                (isInstance, world) => { this._effect.setMatrix("world", world)});
         }
 
         public isReady(subMesh: SubMesh, useInstances: boolean): boolean {
@@ -74,20 +54,20 @@
             // Alpha test
             if (material && material.needAlphaTesting()) {
                 defines.push("#define ALPHATEST");
-                if (mesh.isVerticesDataPresent(BABYLON.VertexBuffer.UVKind)) {
-                    attribs.push(BABYLON.VertexBuffer.UVKind);
+                if (mesh.isVerticesDataPresent(VertexBuffer.UVKind)) {
+                    attribs.push(VertexBuffer.UVKind);
                     defines.push("#define UV1");
                 }
-                if (mesh.isVerticesDataPresent(BABYLON.VertexBuffer.UV2Kind)) {
-                    attribs.push(BABYLON.VertexBuffer.UV2Kind);
+                if (mesh.isVerticesDataPresent(VertexBuffer.UV2Kind)) {
+                    attribs.push(VertexBuffer.UV2Kind);
                     defines.push("#define UV2");
                 }
             }
 
             // Bones
-            if (mesh.skeleton && mesh.isVerticesDataPresent(BABYLON.VertexBuffer.MatricesIndicesKind) && mesh.isVerticesDataPresent(BABYLON.VertexBuffer.MatricesWeightsKind)) {
-                attribs.push(BABYLON.VertexBuffer.MatricesIndicesKind);
-                attribs.push(BABYLON.VertexBuffer.MatricesWeightsKind);
+            if (mesh.useBones) {
+                attribs.push(VertexBuffer.MatricesIndicesKind);
+                attribs.push(VertexBuffer.MatricesWeightsKind);
                 defines.push("#define BONES");
                 defines.push("#define BonesPerMesh " + (mesh.skeleton.bones.length + 1));
             }
@@ -103,7 +83,7 @@
 
             // Get correct effect      
             var join = defines.join("\n");
-            if (this._cachedDefines != join) {
+            if (this._cachedDefines !== join) {
                 this._cachedDefines = join;
                 this._effect = this._scene.getEngine().createEffect("outline",
                     attribs,

+ 25 - 19
Babylon/Shaders/ssao.fragment.fx

@@ -1,18 +1,21 @@
 #ifdef GL_ES
-precision mediump float;
+precision highp float;
 #endif
 
+#define SAMPLES 8
+
 uniform sampler2D textureSampler;
 uniform sampler2D randomSampler;
 
+uniform float samplesFactor;
 uniform vec3 sampleSphere[16];
 
 varying vec2 vUV;
 
-vec3 normalFromDepth(float depth, vec2 coords) {
-    const vec2 offset1 = vec2(0.0, 0.001);
-    const vec2 offset2 = vec2(0.001, 0.0);
+const vec2 offset1 = vec2(0.0, 0.001);
+const vec2 offset2 = vec2(0.001, 0.0);
 
+vec3 normalFromDepth(const float depth, const vec2 coords) {
     float depth1 = texture2D(textureSampler, coords + offset1).r;
     float depth2 = texture2D(textureSampler, coords + offset2).r;
 
@@ -25,35 +28,38 @@ vec3 normalFromDepth(float depth, vec2 coords) {
     return normalize(normal);
 }
 
-void main(void) {
-
+void main(void)
+{
 	const float totalStrength = 1.0;
-	const float base = 0.2;
+	const float base = 0.0;
 	const float area = 0.0075;
-	const float fallOff = 0.000001;
-	const float radius = 0.002;
+	const float fallOff = 0.00001;
+	const float radius = 0.0002;
 
-	vec3 random = normalize(texture2D(randomSampler, vUV * 4.0).rgb);
+	vec3 random = texture2D(randomSampler, vUV * 4.0).rgb;
 	float depth = texture2D(textureSampler, vUV).r;
-
 	vec3 position = vec3(vUV, depth);
 	vec3 normal = normalFromDepth(depth, vUV);
-
 	float radiusDepth = radius / depth;
 	float occlusion = 0.0;
 
-	const int samples = 16;
-	for (int i = 0; i < samples; i++) {
-		vec3 ray = radiusDepth * reflect(sampleSphere[i], random);
-		vec3 hemiRay = position + sign(dot(ray, normal)) * ray;
+	vec3 ray;
+	vec3 hemiRay;
+	float occlusionDepth;
+	float difference;
+
+	for (int i = 0; i < SAMPLES; i++)
+	{
+		ray = radiusDepth * reflect(sampleSphere[i], random);
+		hemiRay = position + sign(dot(ray, normal)) * ray;
 
-		float occlusionDepth = texture2D(textureSampler, clamp(hemiRay.xy, 0.0, 1.0)).r;
-		float difference = depth - occlusionDepth;
+		occlusionDepth = texture2D(textureSampler, clamp(hemiRay.xy, 0.0, 1.0)).r;
+		difference = depth - occlusionDepth;
 
 		occlusion += step(fallOff, difference) * (1.0 - smoothstep(fallOff, area, difference));
 	}
 
-	float ao = 1.0 - totalStrength * occlusion * (1.0 / float(samples));
+	float ao = 1.0 - totalStrength * occlusion * samplesFactor;
 
 	float result = clamp(ao + base, 0.0, 1.0);
 	gl_FragColor.r = result;

+ 41 - 0
Babylon/Shaders/volumetricLightScattering.fragment.fx

@@ -0,0 +1,41 @@
+// Inspired by http://http.developer.nvidia.com/GPUGems3/gpugems3_ch13.html
+
+#ifdef GL_ES
+precision mediump float;
+#endif
+
+uniform sampler2D textureSampler;
+uniform sampler2D lightScatteringSampler;
+
+uniform vec2 lightPositionOnScreen;
+
+varying vec2 vUV;
+
+void main(void) {
+    float decay = 0.96815;
+    float exposure = 0.3;
+    float density = 0.926;
+    float weight = 0.58767;
+
+    const int NUM_SAMPLES = 100;
+
+    vec2 tc = vUV;
+    vec2 deltaTexCoord = (tc - lightPositionOnScreen.xy);
+    deltaTexCoord *= 1.0 / float(NUM_SAMPLES) * density;
+
+    float illuminationDecay = 1.0;
+
+	vec4 color = texture2D(lightScatteringSampler, tc) * 0.4;
+
+    for(int i=0; i < NUM_SAMPLES; i++)
+    {
+        tc -= deltaTexCoord;
+		vec4 sample = texture2D(lightScatteringSampler, tc) * 0.4;
+        sample *= illuminationDecay * weight;
+        color += sample;
+        illuminationDecay *= decay;
+    }
+
+    vec4 realColor = texture2D(textureSampler, vUV);
+    gl_FragColor = ((vec4((vec3(color.r, color.g, color.b) * exposure), 1)) + (realColor * (1.5 - 0.4)));
+}

+ 1 - 0
Babylon/Tools/babylon.tools.js

@@ -435,6 +435,7 @@ var BABYLON;
                     newWindow.document.body.appendChild(img);
                 }
             };
+            scene.incrementRenderId();
             texture.render(true);
             texture.dispose();
             if (previousCamera) {

+ 2 - 1
Babylon/Tools/babylon.tools.ts

@@ -432,7 +432,7 @@
             var height: number;
 
             var scene = camera.getScene();
-            var previousCamera: BABYLON.Camera = null;
+            var previousCamera: Camera = null;
 
             if (scene.activeCamera !== camera) {
                 previousCamera = scene.activeCamera;
@@ -537,6 +537,7 @@
 
             };
 
+            scene.incrementRenderId();
             texture.render(true);
             texture.dispose();
 

+ 3 - 0
Babylon/babylon.scene.js

@@ -230,6 +230,9 @@ var BABYLON;
         Scene.prototype.getRenderId = function () {
             return this._renderId;
         };
+        Scene.prototype.incrementRenderId = function () {
+            this._renderId++;
+        };
         Scene.prototype._updatePointerPosition = function (evt) {
             var canvasRect = this._engine.getRenderingCanvasClientRect();
             this._pointerX = evt.clientX - canvasRect.left;

+ 4 - 0
Babylon/babylon.scene.ts

@@ -354,6 +354,10 @@
             return this._renderId;
         }
 
+        public incrementRenderId(): void {
+            this._renderId++;
+        }
+
         private _updatePointerPosition(evt: PointerEvent): void {
             var canvasRect = this._engine.getRenderingCanvasClientRect();
 

File diff suppressed because it is too large
+ 81 - 103
babylon.2.0-beta.debug.js


File diff suppressed because it is too large
+ 18 - 18
babylon.2.0-beta.js


+ 9 - 61
babylon.2.0.d.ts

@@ -638,6 +638,7 @@ declare module BABYLON {
         getSpritesDuration(): number;
         getAnimationRatio(): number;
         getRenderId(): number;
+        incrementRenderId(): void;
         private _updatePointerPosition(evt);
         attachControl(): void;
         detachControl(): void;
@@ -781,6 +782,10 @@ declare module BABYLON {
         dispose(): void;
         _getNewPosition(position: Vector3, velocity: Vector3, collider: Collider, maximumRetry: number, finalPosition: Vector3, excludedMesh?: AbstractMesh): void;
         private _collideWithWorld(position, velocity, collider, maximumRetry, finalPosition, excludedMesh?);
+        getWorldExtends(): {
+            min: Vector3;
+            max: Vector3;
+        };
         createOrUpdateSelectionOctree(maxCapacity?: number, maxDepth?: number): Octree<AbstractMesh>;
         createPickingRay(x: number, y: number, world: Matrix, camera: Camera): Ray;
         private _internalPick(rayFunction, predicate, fastCheck?);
@@ -795,6 +800,7 @@ declare module BABYLON {
         setGravity(gravity: Vector3): void;
         createCompoundImpostor(parts: any, options: PhysicsBodyCreationOptions): any;
         deleteCompoundImpostor(compound: any): void;
+        createDefaultCameraOrLight(): void;
         private _getByTags(list, tagsQuery, forEach?);
         getMeshesByTags(tagsQuery: string, forEach?: (mesh: AbstractMesh) => void): Mesh[];
         getCamerasByTags(tagsQuery: string, forEach?: (camera: Camera) => void): Camera[];
@@ -1596,41 +1602,6 @@ declare module BABYLON {
     }
 }
 declare module BABYLON {
-    class OculusCamera extends FreeCamera {
-        private _leftCamera;
-        private _rightCamera;
-        private _offsetOrientation;
-        private _deviceOrientationHandler;
-        constructor(name: string, position: Vector3, scene: Scene);
-        public _update(): void;
-        public _updateCamera(camera: FreeCamera): void;
-        public _onOrientationEvent(evt: DeviceOrientationEvent): void;
-        public attachControl(element: HTMLElement, noPreventDefault?: boolean): void;
-        public detachControl(element: HTMLElement): void;
-    }
-}
-declare module BABYLON {
-    class OculusGamepadCamera extends FreeCamera {
-        private _leftCamera;
-        private _rightCamera;
-        private _offsetOrientation;
-        private _deviceOrientationHandler;
-        private _gamepad;
-        private _gamepads;
-        public angularSensibility: number;
-        public moveSensibility: number;
-        constructor(name: string, position: Vector3, scene: Scene);
-        private _onNewGameConnected(gamepad);
-        public _update(): void;
-        public _checkInputs(): void;
-        public _updateCamera(camera: FreeCamera): void;
-        public _onOrientationEvent(evt: DeviceOrientationEvent): void;
-        public attachControl(element: HTMLElement, noPreventDefault?: boolean): void;
-        public detachControl(element: HTMLElement): void;
-        public dispose(): void;
-    }
-}
-declare module BABYLON {
     class TargetCamera extends Camera {
         cameraDirection: Vector3;
         cameraRotation: Vector2;
@@ -1691,32 +1662,6 @@ declare module BABYLON {
     }
 }
 declare module BABYLON {
-    class VRDeviceOrientationCamera extends OculusCamera {
-        public _alpha: number;
-        public _beta: number;
-        public _gamma: number;
-        constructor(name: string, position: Vector3, scene: Scene);
-        public _onOrientationEvent(evt: DeviceOrientationEvent): void;
-    }
-}
-declare var HMDVRDevice: any;
-declare var PositionSensorVRDevice: any;
-declare module BABYLON {
-    class WebVRCamera extends OculusCamera {
-        public _hmdDevice: any;
-        public _sensorDevice: any;
-        public _cacheState: any;
-        public _cacheQuaternion: Quaternion;
-        public _cacheRotation: Vector3;
-        public _vrEnabled: boolean;
-        constructor(name: string, position: Vector3, scene: Scene);
-        private _getWebVRDevices(devices);
-        public _update(): void;
-        public attachControl(element: HTMLElement, noPreventDefault?: boolean): void;
-        public detachControl(element: HTMLElement): void;
-    }
-}
-declare module BABYLON {
     class OculusCamera extends FreeCamera {
         private _leftCamera;
         private _rightCamera;
@@ -3231,6 +3176,7 @@ declare module BABYLON {
         getVerticesData(kind: string): number[];
         isVerticesDataPresent(kind: string): boolean;
         getBoundingInfo(): BoundingInfo;
+        useBones: boolean;
         _preActivate(): void;
         _activate(renderId: number): void;
         getWorldMatrix(): Matrix;
@@ -3620,6 +3566,7 @@ declare module BABYLON {
         unregisterAfterRender(func: () => void): void;
         _getInstancesRenderList(subMeshId: number): _InstancesBatch;
         _renderWithInstances(subMesh: SubMesh, fillMode: number, batch: _InstancesBatch, effect: Effect, engine: Engine): void;
+        _processRendering(subMesh: SubMesh, effect: Effect, fillMode: number, batch: _InstancesBatch, hardwareInstancedRendering: boolean, onBeforeDraw: (isInstance: boolean, world: Matrix) => void): void;
         render(subMesh: SubMesh): void;
         getEmittedParticleSystems(): ParticleSystem[];
         getHierarchyEmittedParticleSystems(): ParticleSystem[];
@@ -4239,6 +4186,7 @@ declare module BABYLON {
         constructor(name: string, scene: Scene, ratio?: number);
         getBlurHPostProcess(): BlurPostProcess;
         getBlurVPostProcess(): BlurPostProcess;
+        dispose(cameras: any): void;
         private _createSSAOPostProcess(ratio);
         private _createSSAOCombinePostProcess();
         private _createRandomTexture();