Jelajahi Sumber

Fixing issue with key handlers on Chrome

David Catuhe 10 tahun lalu
induk
melakukan
cb98550c92

+ 3 - 1
Babylon/Actions/babylon.actionManager.js

@@ -221,7 +221,9 @@ var BABYLON;
                     if (trigger === ActionManager.OnKeyUpTrigger || trigger === ActionManager.OnKeyDownTrigger) {
                         var parameter = action.getTriggerParameter();
                         if (parameter) {
-                            if (evt.sourceEvent.key !== parameter) {
+                            var unicode = evt.sourceEvent.charCode ? evt.sourceEvent.charCode : evt.sourceEvent.keyCode;
+                            var actualkey = String.fromCharCode(unicode).toLowerCase();
+                            if (actualkey !== parameter.toLowerCase()) {
                                 continue;
                             }
                         }

+ 3 - 1
Babylon/Actions/babylon.actionManager.ts

@@ -212,7 +212,9 @@
                         var parameter = action.getTriggerParameter();
 
                         if (parameter) {
-                            if (evt.sourceEvent.key !== parameter) {
+                            var unicode = evt.sourceEvent.charCode ? evt.sourceEvent.charCode : evt.sourceEvent.keyCode;
+                            var actualkey = String.fromCharCode(unicode).toLowerCase();
+                            if (actualkey !== parameter.toLowerCase()) {
                                 continue;
                             }
                         }

+ 2 - 2
Babylon/Cameras/babylon.camera.js

@@ -90,7 +90,7 @@ var BABYLON;
                 return false;
             }
             var engine = this.getEngine();
-            if (this.mode === BABYLON.Camera.PERSPECTIVE_CAMERA) {
+            if (this.mode === Camera.PERSPECTIVE_CAMERA) {
                 check = this._cache.fov === this.fov && this._cache.aspectRatio === engine.getAspectRatio(this);
             }
             else {
@@ -211,7 +211,7 @@ var BABYLON;
                 return this._projectionMatrix;
             }
             var engine = this.getEngine();
-            if (this.mode === BABYLON.Camera.PERSPECTIVE_CAMERA) {
+            if (this.mode === Camera.PERSPECTIVE_CAMERA) {
                 if (this.minZ <= 0) {
                     this.minZ = 0.1;
                 }

+ 11 - 11
Babylon/Cameras/babylon.camera.ts

@@ -20,8 +20,8 @@
         public subCameras = [];
         public layerMask: number = 0xFFFFFFFF;
 
-        private _computedViewMatrix = BABYLON.Matrix.Identity();
-        public _projectionMatrix = new BABYLON.Matrix();
+        private _computedViewMatrix = Matrix.Identity();
+        public _projectionMatrix = new Matrix();
         private _worldMatrix: Matrix;
         public _postProcesses = new Array<PostProcess>();
         public _postProcessesTakenIndices = [];               
@@ -40,8 +40,8 @@
         public _initCache() {
             super._initCache();
 
-            this._cache.position = new BABYLON.Vector3(Number.MAX_VALUE, Number.MAX_VALUE, Number.MAX_VALUE);
-            this._cache.upVector = new BABYLON.Vector3(Number.MAX_VALUE, Number.MAX_VALUE, Number.MAX_VALUE);
+            this._cache.position = new Vector3(Number.MAX_VALUE, Number.MAX_VALUE, Number.MAX_VALUE);
+            this._cache.upVector = new Vector3(Number.MAX_VALUE, Number.MAX_VALUE, Number.MAX_VALUE);
 
             this._cache.mode = undefined;
             this._cache.minZ = undefined;
@@ -113,7 +113,7 @@
 
             var engine = this.getEngine();
 
-            if (this.mode === BABYLON.Camera.PERSPECTIVE_CAMERA) {
+            if (this.mode === Camera.PERSPECTIVE_CAMERA) {
                 check = this._cache.fov === this.fov
                 && this._cache.aspectRatio === engine.getAspectRatio(this);
             }
@@ -231,7 +231,7 @@
 
         public getWorldMatrix(): Matrix {
             if (!this._worldMatrix) {
-                this._worldMatrix = BABYLON.Matrix.Identity();
+                this._worldMatrix = Matrix.Identity();
             }
 
             var viewMatrix = this.getViewMatrix();
@@ -242,7 +242,7 @@
         }
 
         public _getViewMatrix(): Matrix {
-            return BABYLON.Matrix.Identity();
+            return Matrix.Identity();
         }
 
         public getViewMatrix(): Matrix {
@@ -255,7 +255,7 @@
             }
 
             if (!this._worldMatrix) {
-                this._worldMatrix = BABYLON.Matrix.Identity();
+                this._worldMatrix = Matrix.Identity();
             }
 
             this._computedViewMatrix.invertToRef(this._worldMatrix);
@@ -286,18 +286,18 @@
             }
 
             var engine = this.getEngine();
-            if (this.mode === BABYLON.Camera.PERSPECTIVE_CAMERA) {
+            if (this.mode === Camera.PERSPECTIVE_CAMERA) {
                 if (this.minZ <= 0) {
                     this.minZ = 0.1;
                 }
 
-                BABYLON.Matrix.PerspectiveFovLHToRef(this.fov, engine.getAspectRatio(this), this.minZ, this.maxZ, this._projectionMatrix);
+                Matrix.PerspectiveFovLHToRef(this.fov, engine.getAspectRatio(this), this.minZ, this.maxZ, this._projectionMatrix);
                 return this._projectionMatrix;
             }
 
             var halfWidth = engine.getRenderWidth() / 2.0;
             var halfHeight = engine.getRenderHeight() / 2.0;
-            BABYLON.Matrix.OrthoOffCenterLHToRef(this.orthoLeft || -halfWidth, this.orthoRight || halfWidth, this.orthoBottom || -halfHeight, this.orthoTop || halfHeight, this.minZ, this.maxZ, this._projectionMatrix);
+            Matrix.OrthoOffCenterLHToRef(this.orthoLeft || -halfWidth, this.orthoRight || halfWidth, this.orthoBottom || -halfHeight, this.orthoTop || halfHeight, this.minZ, this.maxZ, this._projectionMatrix);
             return this._projectionMatrix;
         }
 

+ 8 - 3
Babylon/PostProcess/babylon.ssaoRenderingPipeline.js

@@ -8,7 +8,7 @@ var BABYLON;
 (function (BABYLON) {
     var SSAORenderingPipeline = (function (_super) {
         __extends(SSAORenderingPipeline, _super);
-        function SSAORenderingPipeline(name, scene, ratio) {
+        function SSAORenderingPipeline(name, scene, ratio, cameras) {
             var _this = this;
             if (ratio === void 0) { ratio = 1.0; }
             _super.call(this, scene.getEngine(), name);
@@ -57,6 +57,11 @@ var BABYLON;
         SSAORenderingPipeline.prototype.dispose = function (cameras) {
             if (cameras !== undefined)
                 this._scene.postProcessRenderPipelineManager.detachCamerasFromRenderPipeline(this._name, cameras);
+            this._originalColorPostProcess = undefined;
+            this._ssaoPostProcess = undefined;
+            this._blurHPostProcess = undefined;
+            this._blurVPostProcess = undefined;
+            this._ssaoCombinePostProcess = undefined;
             this._randomTexture.dispose();
         };
         // Private Methods
@@ -112,10 +117,10 @@ var BABYLON;
                 0.2847,
                 -0.0271
             ];
-            var samplesFactor = 1.0 / 8.0;
+            var samplesFactor = 1.0 / 16.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) {
+                if (_this._firstUpdate) {
                     effect.setArray3("sampleSphere", sampleSphere);
                     effect.setFloat("samplesFactor", samplesFactor);
                     _this._firstUpdate = false;

+ 12 - 5
Babylon/PostProcess/babylon.ssaoRenderingPipeline.ts

@@ -19,7 +19,7 @@
 
         private _firstUpdate: boolean = true;
 
-        constructor(name: string, scene: Scene, ratio: number = 1.0) {
+        constructor(name: string, scene: Scene, ratio: number = 1.0, cameras?: Camera[]) {
             super(scene.getEngine(), name);
 
             this._scene = scene;
@@ -57,6 +57,13 @@
         public dispose(cameras: any): void {
             if (cameras !== undefined)
                 this._scene.postProcessRenderPipelineManager.detachCamerasFromRenderPipeline(this._name, cameras);
+
+            this._originalColorPostProcess = undefined;
+            this._ssaoPostProcess = undefined;
+            this._blurHPostProcess = undefined;
+            this._blurVPostProcess = undefined;
+            this._ssaoCombinePostProcess = undefined;
+
             this._randomTexture.dispose();
         }
 
@@ -80,14 +87,14 @@
                 0.0352, -0.0631, 0.5460,
                 -0.4776, 0.2847, -0.0271
             ];
-            var samplesFactor = 1.0 / 8.0;
+            var samplesFactor = 1.0 / 16.0;
 
             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) {
+                if (this._firstUpdate) {
                     effect.setArray3("sampleSphere", sampleSphere);
                     effect.setFloat("samplesFactor", samplesFactor);
                     this._firstUpdate = false;
@@ -115,7 +122,7 @@
         private _createRandomTexture(): void {
             var size = 512;
 
-            this._randomTexture = new BABYLON.DynamicTexture("SSAORandomTexture", size, this._scene, false, BABYLON.Texture.BILINEAR_SAMPLINGMODE);
+            this._randomTexture = new DynamicTexture("SSAORandomTexture", size, this._scene, false, Texture.BILINEAR_SAMPLINGMODE);
             this._randomTexture.wrapU = Texture.WRAP_ADDRESSMODE;
             this._randomTexture.wrapV = Texture.WRAP_ADDRESSMODE;
 
@@ -127,7 +134,7 @@
 
             for (var x = 0; x < size; x++) {
                 for (var y = 0; y < size; y++) {
-                    var randVector = BABYLON.Vector3.Zero();
+                    var randVector = Vector3.Zero();
 
                     randVector.x = Math.floor(rand(0.0, 1.0) * 255);
                     randVector.y = Math.floor(rand(0.0, 1.0) * 255);

+ 155 - 0
Babylon/PostProcess/babylon.volumetricLightScatteringPostProcess.js

@@ -0,0 +1,155 @@
+var __extends = this.__extends || function (d, b) {
+    for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
+    function __() { this.constructor = d; }
+    __.prototype = b.prototype;
+    d.prototype = new __();
+};
+var BABYLON;
+(function (BABYLON) {
+    var GodRaysPostProcess = (function (_super) {
+        __extends(GodRaysPostProcess, _super);
+        function GodRaysPostProcess(name, ratio, camera, samplingMode, engine, reusable) {
+            var _this = this;
+            _super.call(this, name, "volumetricLightScattering", ["lightPositionOnScreen"], ["lightScatteringSampler"], ratio, camera, samplingMode, engine, reusable);
+            this._screenCoordinates = BABYLON.Vector2.Zero();
+            this.invert = true;
+            var scene = camera.getScene();
+            this._viewPort = new BABYLON.Viewport(0, 0, 1, 1).toGlobal(scene.getEngine());
+            // Create billboard
+            this.mesh = BABYLON.Mesh.CreatePlane("VolumetricLightScatteringMesh", 2, scene);
+            this.mesh.billboardMode = BABYLON.AbstractMesh.BILLBOARDMODE_ALL;
+            this.mesh.material = new BABYLON.StandardMaterial('VolumetricLightScatteringMaterial', scene);
+            // Configure
+            this._createPass(scene);
+            this.onApply = function (effect) {
+                _this._updateScreenCoordinates(scene);
+                effect.setTexture("lightScatteringSampler", _this._godRaysRTT);
+                effect.setVector2("lightPositionOnScreen", _this._screenCoordinates);
+            };
+        }
+        GodRaysPostProcess.prototype.isReady = function (subMesh, useInstances) {
+            var mesh = subMesh.getMesh();
+            var scene = mesh.getScene();
+            var defines = [];
+            var attribs = [BABYLON.VertexBuffer.PositionKind];
+            var material = subMesh.getMaterial();
+            // Render this.mesh as default
+            if (mesh === this.mesh)
+                defines.push("#define BASIC_RENDER");
+            // Alpha test
+            if (material) {
+                if (material.needAlphaTesting() || mesh === this.mesh)
+                    defines.push("#define ALPHATEST");
+                if (mesh.isVerticesDataPresent(BABYLON.VertexBuffer.UVKind)) {
+                    attribs.push(BABYLON.VertexBuffer.UVKind);
+                    defines.push("#define UV1");
+                }
+                if (mesh.isVerticesDataPresent(BABYLON.VertexBuffer.UV2Kind)) {
+                    attribs.push(BABYLON.VertexBuffer.UV2Kind);
+                    defines.push("#define UV2");
+                }
+            }
+            // Bones
+            if (mesh.useBones) {
+                attribs.push(BABYLON.VertexBuffer.MatricesIndicesKind);
+                attribs.push(BABYLON.VertexBuffer.MatricesWeightsKind);
+                defines.push("#define BONES");
+                defines.push("#define BonesPerMesh " + (mesh.skeleton.bones.length + 1));
+            }
+            // Instances
+            if (useInstances) {
+                defines.push("#define INSTANCES");
+                attribs.push("world0");
+                attribs.push("world1");
+                attribs.push("world2");
+                attribs.push("world3");
+            }
+            // Get correct effect      
+            var join = defines.join("\n");
+            if (this._cachedDefines !== join) {
+                this._cachedDefines = join;
+                this._godRaysPass = mesh.getScene().getEngine().createEffect({ vertexElement: "depth", fragmentElement: "volumetricLightScatteringPass" }, attribs, ["world", "mBones", "viewProjection", "diffuseMatrix", "far"], ["diffuseSampler"], join);
+            }
+            return this._godRaysPass.isReady();
+        };
+        GodRaysPostProcess.prototype.dispose = function (camera) {
+            this._godRaysRTT.dispose();
+            _super.prototype.dispose.call(this, camera);
+        };
+        GodRaysPostProcess.prototype.getPass = function () {
+            return this._godRaysRTT;
+        };
+        // Private methods
+        GodRaysPostProcess.prototype._createPass = function (scene) {
+            var _this = this;
+            var engine = scene.getEngine();
+            this._godRaysRTT = new BABYLON.RenderTargetTexture("volumetricLightScatteringMap", { width: engine.getRenderWidth(), height: engine.getRenderHeight() }, scene, false, true, BABYLON.Engine.TEXTURETYPE_UNSIGNED_INT);
+            this._godRaysRTT.wrapU = BABYLON.Texture.CLAMP_ADDRESSMODE;
+            this._godRaysRTT.wrapV = BABYLON.Texture.CLAMP_ADDRESSMODE;
+            this._godRaysRTT.renderList = null;
+            scene.customRenderTargets.push(this._godRaysRTT);
+            // Custom render function for submeshes
+            var renderSubMesh = function (subMesh) {
+                var mesh = subMesh.getRenderingMesh();
+                var scene = mesh.getScene();
+                var engine = scene.getEngine();
+                // Culling
+                engine.setState(subMesh.getMaterial().backFaceCulling);
+                // Managing instances
+                var batch = mesh._getInstancesRenderList(subMesh._id);
+                if (batch.mustReturn) {
+                    return;
+                }
+                var hardwareInstancedRendering = (engine.getCaps().instancedArrays !== null) && (batch.visibleInstances[subMesh._id] !== null);
+                if (_this.isReady(subMesh, hardwareInstancedRendering)) {
+                    engine.enableEffect(_this._godRaysPass);
+                    mesh._bind(subMesh, _this._godRaysPass, BABYLON.Material.TriangleFillMode);
+                    var material = subMesh.getMaterial();
+                    _this._godRaysPass.setMatrix("viewProjection", scene.getTransformMatrix());
+                    // Alpha test
+                    if (material && (mesh === _this.mesh || material.needAlphaTesting())) {
+                        var alphaTexture = material.getAlphaTestTexture();
+                        _this._godRaysPass.setTexture("diffuseSampler", alphaTexture);
+                        _this._godRaysPass.setMatrix("diffuseMatrix", alphaTexture.getTextureMatrix());
+                    }
+                    // Bones
+                    if (mesh.useBones) {
+                        _this._godRaysPass.setMatrices("mBones", mesh.skeleton.getTransformMatrices());
+                    }
+                    // Draw
+                    mesh._processRendering(subMesh, _this._godRaysPass, BABYLON.Material.TriangleFillMode, batch, hardwareInstancedRendering, function (isInstance, world) { return _this._godRaysPass.setMatrix("world", world); });
+                }
+            };
+            // Render target texture callbacks
+            var savedSceneClearColor = null;
+            var sceneClearColor = new BABYLON.Color4(0.0, 0.0, 0.0, 1.0);
+            this._godRaysRTT.onBeforeRender = function () {
+                savedSceneClearColor = scene.clearColor;
+                scene.clearColor = sceneClearColor;
+            };
+            this._godRaysRTT.onAfterRender = function () {
+                scene.clearColor = savedSceneClearColor;
+            };
+            this._godRaysRTT.customRenderFunction = function (opaqueSubMeshes, alphaTestSubMeshes) {
+                var index;
+                for (index = 0; index < opaqueSubMeshes.length; index++) {
+                    renderSubMesh(opaqueSubMeshes.data[index]);
+                }
+                for (index = 0; index < alphaTestSubMeshes.length; index++) {
+                    renderSubMesh(alphaTestSubMeshes.data[index]);
+                }
+            };
+        };
+        GodRaysPostProcess.prototype._updateScreenCoordinates = function (scene) {
+            var transform = scene.getTransformMatrix();
+            var pos = BABYLON.Vector3.Project(this.mesh.position, BABYLON.Matrix.Identity(), transform, this._viewPort);
+            this._screenCoordinates.x = pos.x / this._viewPort.width;
+            this._screenCoordinates.y = pos.y / this._viewPort.height;
+            if (this.invert)
+                this._screenCoordinates.y = 1.0 - this._screenCoordinates.y;
+        };
+        return GodRaysPostProcess;
+    })(BABYLON.PostProcess);
+    BABYLON.GodRaysPostProcess = GodRaysPostProcess;
+})(BABYLON || (BABYLON = {}));
+//# sourceMappingURL=babylon.volumetricLightScatteringPostProcess.js.map

+ 192 - 0
Babylon/PostProcess/babylon.volumetricLightScatteringPostProcess.ts

@@ -0,0 +1,192 @@
+module BABYLON {
+    export class GodRaysPostProcess extends PostProcess {
+        // Members
+        private _godRaysPass: Effect;
+        private _godRaysRTT: RenderTargetTexture;
+        private _viewPort: Viewport;
+        private _screenCoordinates: Vector2 = Vector2.Zero();
+        private _cachedDefines: string;
+
+        public invert: boolean = true;
+        public mesh: Mesh;
+
+        constructor(name: string, ratio: number, camera: Camera, samplingMode?: number, engine?: Engine, reusable?: boolean) {
+            super(name, "volumetricLightScattering", ["lightPositionOnScreen"], ["lightScatteringSampler"], ratio, camera, samplingMode, engine, reusable);
+            var scene = camera.getScene();
+
+            this._viewPort = new Viewport(0, 0, 1, 1).toGlobal(scene.getEngine());
+
+            // Create billboard
+            this.mesh = BABYLON.Mesh.CreatePlane("VolumetricLightScatteringMesh", 2, scene);
+            this.mesh.billboardMode = BABYLON.AbstractMesh.BILLBOARDMODE_ALL;
+            this.mesh.material = new StandardMaterial('VolumetricLightScatteringMaterial', scene);
+
+            // Configure
+            this._createPass(scene);
+
+            this.onApply = (effect: Effect) => {
+                this._updateScreenCoordinates(scene);
+
+                effect.setTexture("lightScatteringSampler", this._godRaysRTT);
+                effect.setVector2("lightPositionOnScreen", this._screenCoordinates);
+            };
+        }
+
+        public isReady(subMesh: SubMesh, useInstances: boolean): boolean {
+            var mesh = subMesh.getMesh();
+            var scene = mesh.getScene();
+
+            var defines = [];
+            var attribs = [VertexBuffer.PositionKind];
+            var material = subMesh.getMaterial();
+
+            // Render this.mesh as default
+            if (mesh === this.mesh)
+                defines.push("#define BASIC_RENDER");
+
+            // Alpha test
+            if (material) {
+                if (material.needAlphaTesting() || mesh === this.mesh)
+                    defines.push("#define ALPHATEST");
+
+                if (mesh.isVerticesDataPresent(VertexBuffer.UVKind)) {
+                    attribs.push(VertexBuffer.UVKind);
+                    defines.push("#define UV1");
+                }
+                if (mesh.isVerticesDataPresent(VertexBuffer.UV2Kind)) {
+                    attribs.push(VertexBuffer.UV2Kind);
+                    defines.push("#define UV2");
+                }
+            }
+
+            // Bones
+            if (mesh.useBones) {
+                attribs.push(VertexBuffer.MatricesIndicesKind);
+                attribs.push(VertexBuffer.MatricesWeightsKind);
+                defines.push("#define BONES");
+                defines.push("#define BonesPerMesh " + (mesh.skeleton.bones.length + 1));
+            }
+
+            // Instances
+            if (useInstances) {
+                defines.push("#define INSTANCES");
+                attribs.push("world0");
+                attribs.push("world1");
+                attribs.push("world2");
+                attribs.push("world3");
+            }
+
+            // Get correct effect      
+            var join = defines.join("\n");
+            if (this._cachedDefines !== join) {
+                this._cachedDefines = join;
+                this._godRaysPass = mesh.getScene().getEngine().createEffect(
+                    { vertexElement: "depth", fragmentElement: "volumetricLightScatteringPass" },
+                    attribs,
+                    ["world", "mBones", "viewProjection", "diffuseMatrix", "far"],
+                    ["diffuseSampler"], join);
+            }
+
+            return this._godRaysPass.isReady();
+        }
+
+        public dispose(camera: Camera): void {
+            this._godRaysRTT.dispose();
+            super.dispose(camera);
+        }
+
+        public getPass(): RenderTargetTexture {
+            return this._godRaysRTT;
+        }
+
+        // Private methods
+        private _createPass(scene: Scene): void {
+            var engine = scene.getEngine();
+
+            this._godRaysRTT = new RenderTargetTexture("volumetricLightScatteringMap", { width: engine.getRenderWidth(), height: engine.getRenderHeight() }, scene, false, true, Engine.TEXTURETYPE_UNSIGNED_INT);
+            this._godRaysRTT.wrapU = Texture.CLAMP_ADDRESSMODE;
+            this._godRaysRTT.wrapV = Texture.CLAMP_ADDRESSMODE;
+            this._godRaysRTT.renderList = null;
+            scene.customRenderTargets.push(this._godRaysRTT);
+
+            // Custom render function for submeshes
+            var renderSubMesh = (subMesh: SubMesh): void => {
+                var mesh = subMesh.getRenderingMesh();
+                var scene = mesh.getScene();
+                var engine = scene.getEngine();
+
+                // Culling
+                engine.setState(subMesh.getMaterial().backFaceCulling);
+
+                // Managing instances
+                var batch = mesh._getInstancesRenderList(subMesh._id);
+
+                if (batch.mustReturn) {
+                    return;
+                }
+
+                var hardwareInstancedRendering = (engine.getCaps().instancedArrays !== null) && (batch.visibleInstances[subMesh._id] !== null);
+
+                if (this.isReady(subMesh, hardwareInstancedRendering)) {
+                    engine.enableEffect(this._godRaysPass);
+                    mesh._bind(subMesh, this._godRaysPass, Material.TriangleFillMode);
+                    var material = subMesh.getMaterial();
+
+                    this._godRaysPass.setMatrix("viewProjection", scene.getTransformMatrix());
+
+                    // Alpha test
+                    if (material && (mesh === this.mesh || material.needAlphaTesting())) {
+                        var alphaTexture = material.getAlphaTestTexture();
+                        this._godRaysPass.setTexture("diffuseSampler", alphaTexture);
+                        this._godRaysPass.setMatrix("diffuseMatrix", alphaTexture.getTextureMatrix());
+                    }
+
+                    // Bones
+                    if (mesh.useBones) {
+                        this._godRaysPass.setMatrices("mBones", mesh.skeleton.getTransformMatrices());
+                    }
+
+                    // Draw
+                    mesh._processRendering(subMesh, this._godRaysPass, Material.TriangleFillMode, batch, hardwareInstancedRendering,
+                        (isInstance, world) => this._godRaysPass.setMatrix("world", world));
+                }
+            };
+
+            // Render target texture callbacks
+            var savedSceneClearColor: Color4 = null;
+            var sceneClearColor = new Color4(0.0, 0.0, 0.0, 1.0);
+
+            this._godRaysRTT.onBeforeRender = (): void => {
+                savedSceneClearColor = scene.clearColor;
+                scene.clearColor = sceneClearColor;
+            };
+
+            this._godRaysRTT.onAfterRender = (): void => {
+                scene.clearColor = savedSceneClearColor;
+            };
+
+            this._godRaysRTT.customRenderFunction = (opaqueSubMeshes: SmartArray<SubMesh>, alphaTestSubMeshes: SmartArray<SubMesh>): void => {
+                var index;
+
+                for (index = 0; index < opaqueSubMeshes.length; index++) {
+                    renderSubMesh(opaqueSubMeshes.data[index]);
+                }
+
+                for (index = 0; index < alphaTestSubMeshes.length; index++) {
+                    renderSubMesh(alphaTestSubMeshes.data[index]);
+                }
+            };
+        }
+
+        private _updateScreenCoordinates(scene: Scene): void {
+            var transform = scene.getTransformMatrix();
+            var pos = Vector3.Project(this.mesh.position, Matrix.Identity(), transform, this._viewPort);
+
+            this._screenCoordinates.x = pos.x / this._viewPort.width;
+            this._screenCoordinates.y = pos.y / this._viewPort.height;
+
+            if (this.invert)
+                this._screenCoordinates.y = 1.0 - this._screenCoordinates.y;
+        }
+    }
+}  

+ 3 - 3
Babylon/Shaders/ssao.fragment.fx

@@ -2,7 +2,7 @@
 precision highp float;
 #endif
 
-#define SAMPLES 8
+#define SAMPLES 16
 
 uniform sampler2D textureSampler;
 uniform sampler2D randomSampler;
@@ -31,10 +31,10 @@ vec3 normalFromDepth(const float depth, const vec2 coords) {
 void main(void)
 {
 	const float totalStrength = 1.0;
-	const float base = 0.0;
+	const float base = 0.2;
 	const float area = 0.0075;
 	const float fallOff = 0.00001;
-	const float radius = 0.0002;
+	const float radius = 0.002;
 
 	vec3 random = texture2D(randomSampler, vUV * 4.0).rgb;
 	float depth = texture2D(textureSampler, vUV).r;

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

@@ -12,6 +12,7 @@ uniform vec2 lightPositionOnScreen;
 varying vec2 vUV;
 
 void main(void) {
+	
     float decay = 0.96815;
     float exposure = 0.3;
     float density = 0.926;
@@ -38,4 +39,5 @@ void main(void) {
 
     vec4 realColor = texture2D(textureSampler, vUV);
     gl_FragColor = ((vec4((vec3(color.r, color.g, color.b) * exposure), 1)) + (realColor * (1.5 - 0.4)));
+
 }

+ 22 - 0
Babylon/Shaders/volumetricLightScatteringPass.fragment.fx

@@ -0,0 +1,22 @@
+#ifdef GL_ES
+precision mediump float;
+#endif
+
+#if defined(ALPHATEST) || defined(BASIC_RENDER)
+varying vec2 vUV;
+uniform sampler2D diffuseSampler;
+#endif
+
+void main(void)
+{
+#ifdef ALPHATEST
+	if (texture2D(diffuseSampler, vUV).a < 0.4)
+		discard;
+#endif
+
+#ifdef BASIC_RENDER
+	gl_FragColor = texture2D(diffuseSampler, vUV);
+#else
+	gl_FragColor = vec4(0.0, 0.0, 0.0, 1.0);
+#endif
+}

+ 8 - 4
Babylon/babylon.scene.js

@@ -302,15 +302,19 @@ var BABYLON;
             var eventPrefix = BABYLON.Tools.GetPointerPrefix();
             this._engine.getRenderingCanvas().addEventListener(eventPrefix + "move", this._onPointerMove, false);
             this._engine.getRenderingCanvas().addEventListener(eventPrefix + "down", this._onPointerDown, false);
-            window.addEventListener("keydown", this._onKeyDown, false);
-            window.addEventListener("keyup", this._onKeyUp, false);
+            BABYLON.Tools.RegisterTopRootEvents([
+                { name: "keydown", handler: this._onKeyDown },
+                { name: "keyup", handler: this._onKeyUp }
+            ]);
         };
         Scene.prototype.detachControl = function () {
             var eventPrefix = BABYLON.Tools.GetPointerPrefix();
             this._engine.getRenderingCanvas().removeEventListener(eventPrefix + "move", this._onPointerMove);
             this._engine.getRenderingCanvas().removeEventListener(eventPrefix + "down", this._onPointerDown);
-            window.removeEventListener("keydown", this._onKeyDown);
-            window.removeEventListener("keyup", this._onKeyUp);
+            BABYLON.Tools.UnregisterTopRootEvents([
+                { name: "keydown", handler: this._onKeyDown },
+                { name: "keyup", handler: this._onKeyUp }
+            ]);
         };
         // Ready
         Scene.prototype.isReady = function () {

+ 9 - 5
Babylon/babylon.scene.ts

@@ -445,10 +445,12 @@
 
             var eventPrefix = Tools.GetPointerPrefix();
             this._engine.getRenderingCanvas().addEventListener(eventPrefix + "move", this._onPointerMove, false);
-            this._engine.getRenderingCanvas().addEventListener(eventPrefix + "down", this._onPointerDown, false);
+            this._engine.getRenderingCanvas().addEventListener(eventPrefix + "down", this._onPointerDown, false);        
 
-            window.addEventListener("keydown", this._onKeyDown, false);
-            window.addEventListener("keyup", this._onKeyUp, false);
+            Tools.RegisterTopRootEvents([
+                { name: "keydown", handler: this._onKeyDown },
+                { name: "keyup", handler: this._onKeyUp }
+            ]);
         }
 
         public detachControl() {
@@ -456,8 +458,10 @@
             this._engine.getRenderingCanvas().removeEventListener(eventPrefix + "move", this._onPointerMove);
             this._engine.getRenderingCanvas().removeEventListener(eventPrefix + "down", this._onPointerDown);
 
-            window.removeEventListener("keydown", this._onKeyDown);
-            window.removeEventListener("keyup", this._onKeyUp);
+            Tools.UnregisterTopRootEvents([
+                { name: "keydown", handler: this._onKeyDown },
+                { name: "keyup", handler: this._onKeyUp }
+            ]);
         }
 
         // Ready

File diff ditekan karena terlalu besar
+ 174 - 13
babylon.2.0-beta.debug.js


File diff ditekan karena terlalu besar
+ 7 - 7
babylon.2.0-beta.js