Преглед на файлове

Nightly
Improved StandardRenderingPipeline

David Catuhe преди 8 години
родител
ревизия
d94e884c99

Файловите разлики са ограничени, защото са твърде много
+ 23 - 23
dist/preview release/babylon.core.js


Файловите разлики са ограничени, защото са твърде много
+ 1482 - 1475
dist/preview release/babylon.d.ts


Файловите разлики са ограничени, защото са твърде много
+ 34 - 34
dist/preview release/babylon.js


Файловите разлики са ограничени, защото са твърде много
+ 128 - 44
dist/preview release/babylon.max.js


Файловите разлики са ограничени, защото са твърде много
+ 33 - 33
dist/preview release/babylon.noworker.js


+ 31 - 2
src/Bones/babylon.bone.js

@@ -268,6 +268,8 @@ var BABYLON;
             this._rotateWithMatrix(rmat, space, mesh);
         };
         Bone.prototype.setAxisAngle = function (axis, angle, space, mesh) {
+            if (space === void 0) { space = BABYLON.Space.LOCAL; }
+            if (mesh === void 0) { mesh = null; }
             var rotMat = BABYLON.Tmp.Matrix[0];
             BABYLON.Matrix.RotationAxisToRef(axis, angle, rotMat);
             var rotMatInv = BABYLON.Tmp.Matrix[1];
@@ -275,6 +277,14 @@ var BABYLON;
             rotMatInv.multiplyToRef(rotMat, rotMat);
             this._rotateWithMatrix(rotMat, space, mesh);
         };
+        Bone.prototype.setRotationMatrix = function (rotMat, space, mesh) {
+            if (space === void 0) { space = BABYLON.Space.LOCAL; }
+            if (mesh === void 0) { mesh = null; }
+            var rotMatInv = BABYLON.Tmp.Matrix[1];
+            this._getNegativeRotationToRef(rotMatInv, space, mesh);
+            rotMatInv.multiplyToRef(rotMat, rotMat);
+            this._rotateWithMatrix(rotMat, space, mesh);
+        };
         Bone.prototype._rotateWithMatrix = function (rmat, space, mesh) {
             if (space === void 0) { space = BABYLON.Space.LOCAL; }
             if (mesh === void 0) { mesh = null; }
@@ -327,13 +337,16 @@ var BABYLON;
             if (space === void 0) { space = BABYLON.Space.LOCAL; }
             if (mesh === void 0) { mesh = null; }
             if (space == BABYLON.Space.WORLD) {
+                var scaleMatrix = BABYLON.Tmp.Matrix[2];
+                scaleMatrix.copyFrom(this._scaleMatrix);
                 rotMatInv.copyFrom(this.getAbsoluteTransform());
                 if (mesh) {
                     rotMatInv.multiplyToRef(mesh.getWorldMatrix(), rotMatInv);
+                    var meshScale = BABYLON.Tmp.Matrix[3];
+                    BABYLON.Matrix.ScalingToRef(mesh.scaling.x, mesh.scaling.y, mesh.scaling.z, meshScale);
+                    scaleMatrix.multiplyToRef(meshScale, scaleMatrix);
                 }
                 rotMatInv.invert();
-                var scaleMatrix = BABYLON.Tmp.Matrix[2];
-                scaleMatrix.copyFrom(this._scaleMatrix);
                 scaleMatrix.m[0] *= -1;
                 rotMatInv.multiplyToRef(scaleMatrix, rotMatInv);
             }
@@ -387,6 +400,10 @@ var BABYLON;
             }
             else {
                 this._absoluteTransform.copyFrom(this._matrix);
+                var poseMatrix = this._skeleton.getPoseMatrix();
+                if (poseMatrix) {
+                    this._absoluteTransform.multiplyToRef(poseMatrix, this._absoluteTransform);
+                }
             }
             var children = this.children;
             var len = children.length;
@@ -394,6 +411,18 @@ var BABYLON;
                 children[i].computeAbsoluteTransforms();
             }
         };
+        Bone.prototype.getDirection = function (localAxis) {
+            var result = BABYLON.Vector3.Zero();
+            this.getDirectionToRef(localAxis, result);
+            return result;
+        };
+        Bone.prototype.getDirectionToRef = function (localAxis, result) {
+            this._skeleton.computeAbsoluteTransforms();
+            BABYLON.Vector3.TransformNormalToRef(localAxis, this.getAbsoluteTransform(), result);
+            if (this._scaleVector.x != 1 || this._scaleVector.y != 1 || this._scaleVector.z != 1) {
+                result.normalize();
+            }
+        };
         return Bone;
     }(BABYLON.Node));
     BABYLON.Bone = Bone;

+ 7 - 0
src/Bones/babylon.skeleton.js

@@ -342,6 +342,13 @@ var BABYLON;
                 this._lastAbsoluteTransformsUpdateId = renderId;
             }
         };
+        Skeleton.prototype.getPoseMatrix = function () {
+            var poseMatrix;
+            if (this._meshesWithPoseMatrix.length > 0) {
+                poseMatrix = this._meshesWithPoseMatrix[0].getPoseMatrix();
+            }
+            return poseMatrix;
+        };
         return Skeleton;
     }());
     BABYLON.Skeleton = Skeleton;

+ 7 - 0
src/Cameras/Inputs/babylon.arcrotatecamera.input.pointers.js

@@ -9,6 +9,7 @@ var BABYLON;
     var eventPrefix = BABYLON.Tools.GetPointerPrefix();
     var ArcRotateCameraPointersInput = (function () {
         function ArcRotateCameraPointersInput() {
+            this.buttons = [0, 1, 2];
             this.angularSensibilityX = 1000.0;
             this.angularSensibilityY = 1000.0;
             this.pinchPrecision = 6.0;
@@ -24,6 +25,9 @@ var BABYLON;
             var previousPinchDistance = 0;
             this._pointerInput = function (p, s) {
                 var evt = p.event;
+                if (p.type !== BABYLON.PointerEventTypes.POINTERMOVE && _this.buttons.indexOf(evt.button) === -1) {
+                    return;
+                }
                 if (p.type === BABYLON.PointerEventTypes.POINTERDOWN) {
                     try {
                         evt.srcElement.setPointerCapture(evt.pointerId);
@@ -195,6 +199,9 @@ var BABYLON;
         };
         __decorate([
             BABYLON.serialize()
+        ], ArcRotateCameraPointersInput.prototype, "buttons", void 0);
+        __decorate([
+            BABYLON.serialize()
         ], ArcRotateCameraPointersInput.prototype, "angularSensibilityX", void 0);
         __decorate([
             BABYLON.serialize()

+ 7 - 0
src/Cameras/Inputs/babylon.freecamera.input.mouse.js

@@ -10,6 +10,7 @@ var BABYLON;
         function FreeCameraMouseInput(touchEnabled) {
             if (touchEnabled === void 0) { touchEnabled = true; }
             this.touchEnabled = touchEnabled;
+            this.buttons = [0, 1, 2];
             this.angularSensibility = 2000.0;
         }
         FreeCameraMouseInput.prototype.attachControl = function (element, noPreventDefault) {
@@ -21,6 +22,9 @@ var BABYLON;
                     if (!_this.touchEnabled && evt.pointerType === "touch") {
                         return;
                     }
+                    if (p.type !== BABYLON.PointerEventTypes.POINTERMOVE && _this.buttons.indexOf(evt.button) === -1) {
+                        return;
+                    }
                     if (p.type === BABYLON.PointerEventTypes.POINTERDOWN) {
                         try {
                             evt.srcElement.setPointerCapture(evt.pointerId);
@@ -108,6 +112,9 @@ var BABYLON;
         };
         __decorate([
             BABYLON.serialize()
+        ], FreeCameraMouseInput.prototype, "buttons", void 0);
+        __decorate([
+            BABYLON.serialize()
         ], FreeCameraMouseInput.prototype, "angularSensibility", void 0);
         return FreeCameraMouseInput;
     }());

+ 3 - 13
src/Debug/babylon.skeletonViewer.js

@@ -89,14 +89,14 @@ var BABYLON;
                         points = [BABYLON.Vector3.Zero(), BABYLON.Vector3.Zero()];
                         this._debugLines[boneNum] = points;
                     }
-                    this._getBonePosition(points[0], childBone, meshMat);
-                    this._getBonePosition(points[1], parentBone, meshMat);
+                    childBone.getAbsolutePositionToRef(this.mesh, points[0]);
+                    parentBone.getAbsolutePositionToRef(this.mesh, points[1]);
                     boneNum++;
                 }
             };
             SkeletonViewer.prototype.update = function () {
                 if (this.autoUpdateBonesMatrices) {
-                    this._updateBoneMatrix(this.skeleton.bones[0]);
+                    this.skeleton.computeAbsoluteTransforms();
                 }
                 if (this.skeleton.bones[0].length === undefined) {
                     this._getLinesForBonesNoLength(this.skeleton.bones, this.mesh.getWorldMatrix());
@@ -113,16 +113,6 @@ var BABYLON;
                 }
                 this._debugMesh.color = this.color;
             };
-            SkeletonViewer.prototype._updateBoneMatrix = function (bone) {
-                if (bone.getParent()) {
-                    bone.getLocalMatrix().multiplyToRef(bone.getParent().getAbsoluteTransform(), bone.getAbsoluteTransform());
-                }
-                var children = bone.children;
-                var len = children.length;
-                for (var i = 0; i < len; i++) {
-                    this._updateBoneMatrix(children[i]);
-                }
-            };
             SkeletonViewer.prototype.dispose = function () {
                 if (this._debugMesh) {
                     this.isEnabled = false;

+ 18 - 0
src/Math/babylon.math.js

@@ -2480,6 +2480,24 @@ var BABYLON;
             result.m[14] = temp3 * plane.d;
             result.m[15] = 1.0;
         };
+        Matrix.FromXYZAxesToRef = function (xaxis, yaxis, zaxis, mat) {
+            mat.m[0] = xaxis.x;
+            mat.m[1] = xaxis.y;
+            mat.m[2] = xaxis.z;
+            mat.m[3] = 0;
+            mat.m[4] = yaxis.x;
+            mat.m[5] = yaxis.y;
+            mat.m[6] = yaxis.z;
+            mat.m[7] = 0;
+            mat.m[8] = zaxis.x;
+            mat.m[9] = zaxis.y;
+            mat.m[10] = zaxis.z;
+            mat.m[11] = 0;
+            mat.m[12] = 0;
+            mat.m[13] = 0;
+            mat.m[14] = 0;
+            mat.m[15] = 1;
+        };
         Matrix._tempQuaternion = new Quaternion();
         Matrix._xAxis = Vector3.Zero();
         Matrix._yAxis = Vector3.Zero();

+ 51 - 28
src/PostProcess/babylon.standardRenderingPipeline.js

@@ -26,25 +26,26 @@ var BABYLON;
             this.textureAdderPostProcess = null;
             this.textureAdderFinalPostProcess = null;
             this.lensFlarePostProcess = null;
-            this.lensFlareShiftPostProcess = null;
             this.lensFlareComposePostProcess = null;
             this.depthOfFieldPostProcess = null;
-            this.motionBlurPostProcess = null;
             // Values
             this.brightThreshold = 1.0;
+            this.blurWidth = 2.0;
             this.gaussianCoefficient = 0.25;
             this.gaussianMean = 1.0;
             this.gaussianStandardDeviation = 1.0;
             this.exposure = 1.0;
             this.lensTexture = null;
             this.lensColorTexture = null;
-            this.lensFlareStrength = 1.0;
-            this.lensFlareGhostDispersal = 1.0;
-            this.lensFlareHaloWidth = 0.4;
-            this.lensFlareDistortionStrength = 4.0;
+            this.lensFlareStrength = 20.0;
+            this.lensFlareGhostDispersal = 1.4;
+            this.lensFlareHaloWidth = 0.7;
+            this.lensFlareDistortionStrength = 16.0;
             this.lensStarTexture = null;
             this.lensFlareDirtTexture = null;
             this.depthOfFieldDistance = 10.0;
+            // IAnimatable
+            this.animations = [];
             this._depthRenderer = null;
             // Getters and setters
             this._depthOfFieldEnabled = true;
@@ -71,7 +72,7 @@ var BABYLON;
             // Create texture adder post-process
             this._createTextureAdderPostProcess(scene, ratio);
             // Create depth-of-field source post-process
-            this.textureAdderFinalPostProcess = new BABYLON.PostProcess("HDRTextureAdderPostProcess", "standard", [], [], ratio, null, BABYLON.Texture.BILINEAR_SAMPLINGMODE, scene.getEngine(), true, "#define PASS_POST_PROCESS", BABYLON.Engine.TEXTURETYPE_UNSIGNED_INT);
+            this.textureAdderFinalPostProcess = new BABYLON.PostProcess("HDRDepthOfFieldSource", "standard", [], [], ratio, null, BABYLON.Texture.BILINEAR_SAMPLINGMODE, scene.getEngine(), true, "#define PASS_POST_PROCESS", BABYLON.Engine.TEXTURETYPE_UNSIGNED_INT);
             this.addEffect(new BABYLON.PostProcessRenderEffect(scene.getEngine(), "HDRDepthOfFieldSource", function () { return _this.textureAdderFinalPostProcess; }, true));
             // Create lens flare post-process
             this._createLensFlarePostProcess(scene, ratio);
@@ -122,7 +123,6 @@ var BABYLON;
                     this._scene.postProcessRenderPipelineManager.enableEffectInPipeline(this._name, "HDRGaussianBlurH" + blurIndex, this._scene.cameras);
                     this._scene.postProcessRenderPipelineManager.enableEffectInPipeline(this._name, "HDRGaussianBlurV" + blurIndex, this._scene.cameras);
                     this._scene.postProcessRenderPipelineManager.enableEffectInPipeline(this._name, "HDRLensFlareCompose", this._scene.cameras);
-                    this._depthRenderer = this._scene.enableDepthRenderer();
                 }
                 else if (!enabled && this._lensFlareEnabled) {
                     this._scene.postProcessRenderPipelineManager.disableEffectInPipeline(this._name, "HDRLensFlare", this._scene.cameras);
@@ -182,7 +182,7 @@ var BABYLON;
             var _this = this;
             var blurOffsets = new Array(9);
             var blurWeights = new Array(9);
-            var uniforms = ["blurOffsets", "blurWeights"];
+            var uniforms = ["blurOffsets", "blurWeights", "blurWidth"];
             var callback = function (height) {
                 return function (effect) {
                     // Weights
@@ -204,6 +204,7 @@ var BABYLON;
                     }
                     effect.setArray("blurOffsets", blurOffsets);
                     effect.setArray("blurWeights", blurWeights);
+                    effect.setFloat("blurWidth", _this.blurWidth);
                 };
             };
             // Create horizontal gaussian blur post-processes
@@ -235,41 +236,41 @@ var BABYLON;
         // Create lens flare post-process
         StandardRenderingPipeline.prototype._createLensFlarePostProcess = function (scene, ratio) {
             var _this = this;
-            this.lensFlarePostProcess = new BABYLON.PostProcess("HDRLensFlare", "standard", ["strength", "ghostDispersal", "haloWidth"], ["lensColorSampler"], ratio / 8, null, BABYLON.Texture.BILINEAR_SAMPLINGMODE, scene.getEngine(), true, "#define LENS_FLARE", BABYLON.Engine.TEXTURETYPE_UNSIGNED_INT);
-            this.lensFlareShiftPostProcess = new BABYLON.PostProcess("HDRLensFlareShift", "standard", ["resolution", "distortionStrength"], [], ratio / 8, null, BABYLON.Texture.BILINEAR_SAMPLINGMODE, scene.getEngine(), false, "#define LENS_FLARE_SHIFT", BABYLON.Engine.TEXTURETYPE_UNSIGNED_INT);
-            this._createGaussianBlurPostProcesses(scene, ratio / 8, 4);
-            this.lensFlareComposePostProcess = new BABYLON.PostProcess("HDRLensFlareCompose", "standard", ["viewMatrix", "scaleBias1", "scaleBias2"], ["otherSampler", "lensDirtSampler", "lensStarSampler"], ratio, null, BABYLON.Texture.BILINEAR_SAMPLINGMODE, scene.getEngine(), false, "#define LENS_FLARE_COMPOSE", BABYLON.Engine.TEXTURETYPE_UNSIGNED_INT);
+            this.lensFlarePostProcess = new BABYLON.PostProcess("HDRLensFlare", "standard", ["strength", "ghostDispersal", "haloWidth", "resolution", "distortionStrength"], ["lensColorSampler"], ratio / 2, null, BABYLON.Texture.BILINEAR_SAMPLINGMODE, scene.getEngine(), true, "#define LENS_FLARE", BABYLON.Engine.TEXTURETYPE_UNSIGNED_INT);
+            this.addEffect(new BABYLON.PostProcessRenderEffect(scene.getEngine(), "HDRLensFlare", function () { return _this.lensFlarePostProcess; }, false));
+            this._createGaussianBlurPostProcesses(scene, ratio / 4, 4);
+            this.lensFlareComposePostProcess = new BABYLON.PostProcess("HDRLensFlareCompose", "standard", ["lensStarMatrix"], ["otherSampler", "lensDirtSampler", "lensStarSampler"], ratio, null, BABYLON.Texture.BILINEAR_SAMPLINGMODE, scene.getEngine(), false, "#define LENS_FLARE_COMPOSE", BABYLON.Engine.TEXTURETYPE_UNSIGNED_INT);
+            this.addEffect(new BABYLON.PostProcessRenderEffect(scene.getEngine(), "HDRLensFlareCompose", function () { return _this.lensFlareComposePostProcess; }, false));
             var resolution = new BABYLON.Vector2(0, 0);
             // Lens flare
             this.lensFlarePostProcess.onApply = function (effect) {
-                effect.setTextureFromPostProcess("textureSampler", _this.textureAdderPostProcess);
+                effect.setTextureFromPostProcess("textureSampler", _this.gaussianBlurHPostProcesses[0]);
                 effect.setTexture("lensColorSampler", _this.lensColorTexture);
                 effect.setFloat("strength", _this.lensFlareStrength);
                 effect.setFloat("ghostDispersal", _this.lensFlareGhostDispersal);
                 effect.setFloat("haloWidth", _this.lensFlareHaloWidth);
-            };
-            // Shift
-            this.lensFlareShiftPostProcess.onApply = function (effect) {
-                resolution.x = _this.lensFlareShiftPostProcess.width;
-                resolution.y = _this.lensFlareShiftPostProcess.height;
+                // Shift
+                resolution.x = _this.lensFlarePostProcess.width;
+                resolution.y = _this.lensFlarePostProcess.height;
                 effect.setVector2("resolution", resolution);
                 effect.setFloat("distortionStrength", _this.lensFlareDistortionStrength);
             };
             // Compose
-            var scaleBias1 = BABYLON.Matrix.GetAsMatrix3x3(BABYLON.Matrix.FromValues(2.0, 0.0, -1.0, 0.0, 0.0, 2.0, -1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0));
-            var scaleBias2 = BABYLON.Matrix.GetAsMatrix3x3(BABYLON.Matrix.FromValues(0.5, 0.0, 0.5, 0.0, 0.0, 0.5, 0.5, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0));
+            var scaleBias1 = BABYLON.Matrix.FromValues(2.0, 0.0, -1.0, 0.0, 0.0, 2.0, -1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0);
+            var scaleBias2 = BABYLON.Matrix.FromValues(0.5, 0.0, 0.5, 0.0, 0.0, 0.5, 0.5, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0);
             this.lensFlareComposePostProcess.onApply = function (effect) {
                 effect.setTextureFromPostProcess("otherSampler", _this.textureAdderFinalPostProcess);
                 effect.setTexture("lensDirtSampler", _this.lensFlareDirtTexture);
                 effect.setTexture("lensStarSampler", _this.lensStarTexture);
-                effect.setMatrix("viewMatrix", _this._scene.activeCamera.getViewMatrix());
-                effect.setMatrix3x3("scaleBias1", scaleBias1);
-                effect.setMatrix3x3("scaleBias2", scaleBias2);
+                // Lens start rotation matrix
+                var camerax = _this._scene.activeCamera.getViewMatrix().getRow(0);
+                var cameraz = _this._scene.activeCamera.getViewMatrix().getRow(2);
+                var camRot = BABYLON.Vector3.Dot(camerax.toVector3(), new BABYLON.Vector3(1.0, 0.0, 0.0)) + BABYLON.Vector3.Dot(cameraz.toVector3(), new BABYLON.Vector3(0.0, 0.0, 1.0));
+                camRot *= 4.0;
+                var starRotation = BABYLON.Matrix.FromValues(Math.cos(camRot) * 0.5, -Math.sin(camRot), 0.0, 0.0, Math.sin(camRot), Math.cos(camRot) * 0.5, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0);
+                var lensStarMatrix = scaleBias2.multiply(starRotation).multiply(scaleBias1);
+                effect.setMatrix("lensStarMatrix", lensStarMatrix);
             };
-            // Add to pipeline
-            this.addEffect(new BABYLON.PostProcessRenderEffect(scene.getEngine(), "HDRLensFlare", function () { return _this.lensFlarePostProcess; }, false));
-            this.addEffect(new BABYLON.PostProcessRenderEffect(scene.getEngine(), "HDRLensFlareShift", function () { return _this.lensFlareShiftPostProcess; }, false));
-            this.addEffect(new BABYLON.PostProcessRenderEffect(scene.getEngine(), "HDRLensFlareCompose", function () { return _this.lensFlareComposePostProcess; }, false));
         };
         // Create depth-of-field post-process
         StandardRenderingPipeline.prototype._createDepthOfFieldPostProcess = function (scene, ratio) {
@@ -283,6 +284,28 @@ var BABYLON;
             // Add to pipeline
             this.addEffect(new BABYLON.PostProcessRenderEffect(scene.getEngine(), "HDRDepthOfField", function () { return _this.depthOfFieldPostProcess; }, true));
         };
+        // Dispose
+        StandardRenderingPipeline.prototype.dispose = function () {
+            for (var i = 0; i < this._scene.cameras.length; i++) {
+                var camera = this._scene.cameras[i];
+                this.originalPostProcess.dispose(camera);
+                this.downSampleX4PostProcess.dispose(camera);
+                this.brightPassPostProcess.dispose(camera);
+                this.textureAdderPostProcess.dispose(camera);
+                for (var j = 0; j < this.gaussianBlurHPostProcesses.length; j++) {
+                    this.gaussianBlurHPostProcesses[j].dispose(camera);
+                }
+                for (var j = 0; j < this.gaussianBlurVPostProcesses.length; j++) {
+                    this.gaussianBlurVPostProcesses[j].dispose(camera);
+                }
+                this.textureAdderFinalPostProcess.dispose(camera);
+                this.lensFlarePostProcess.dispose(camera);
+                this.lensFlareComposePostProcess.dispose(camera);
+                this.depthOfFieldPostProcess.dispose(camera);
+            }
+            this._scene.postProcessRenderPipelineManager.detachCamerasFromRenderPipeline(this._name, this._scene.cameras);
+            _super.prototype.dispose.call(this);
+        };
         return StandardRenderingPipeline;
     }(BABYLON.PostProcessRenderPipeline));
     BABYLON.StandardRenderingPipeline = StandardRenderingPipeline;

+ 74 - 35
src/PostProcess/babylon.standardRenderingPipeline.ts

@@ -1,5 +1,5 @@
 module BABYLON {
-    export class StandardRenderingPipeline extends PostProcessRenderPipeline implements IDisposable {
+    export class StandardRenderingPipeline extends PostProcessRenderPipeline implements IDisposable, IAnimatable {
         /**
         * Public members
         */
@@ -14,16 +14,14 @@
         public textureAdderFinalPostProcess: PostProcess = null;
 
         public lensFlarePostProcess: PostProcess = null;
-        public lensFlareShiftPostProcess: PostProcess = null;
         public lensFlareComposePostProcess: PostProcess = null;
 
         public depthOfFieldPostProcess: PostProcess = null;
 
-        public motionBlurPostProcess: PostProcess = null;
-
         // Values
         public brightThreshold: number = 1.0;
 
+        public blurWidth: number = 2.0;
         public gaussianCoefficient: number = 0.25;
         public gaussianMean: number = 1.0;
         public gaussianStandardDeviation: number = 1.0;
@@ -32,15 +30,18 @@
         public lensTexture: Texture = null;
 
         public lensColorTexture: Texture = null;
-        public lensFlareStrength: number = 1.0;
-        public lensFlareGhostDispersal: number = 1.0;
-        public lensFlareHaloWidth: number = 0.4;
-        public lensFlareDistortionStrength: number = 4.0;
+        public lensFlareStrength: number = 20.0;
+        public lensFlareGhostDispersal: number = 1.4;
+        public lensFlareHaloWidth: number = 0.7;
+        public lensFlareDistortionStrength: number = 16.0;
         public lensStarTexture: Texture = null;
         public lensFlareDirtTexture: Texture = null;
 
         public depthOfFieldDistance: number = 10.0;
 
+        // IAnimatable
+        public animations: Animation[] = [];
+
         /**
         * Private members
         */
@@ -83,7 +84,6 @@
                 this._scene.postProcessRenderPipelineManager.enableEffectInPipeline(this._name, "HDRGaussianBlurH" + blurIndex, this._scene.cameras);
                 this._scene.postProcessRenderPipelineManager.enableEffectInPipeline(this._name, "HDRGaussianBlurV" + blurIndex, this._scene.cameras);
                 this._scene.postProcessRenderPipelineManager.enableEffectInPipeline(this._name, "HDRLensFlareCompose", this._scene.cameras);
-                this._depthRenderer = this._scene.enableDepthRenderer();
             }
             else if (!enabled && this._lensFlareEnabled) {
                 this._scene.postProcessRenderPipelineManager.disableEffectInPipeline(this._name, "HDRLensFlare", this._scene.cameras);
@@ -140,7 +140,7 @@
             this._createTextureAdderPostProcess(scene, ratio);
 
             // Create depth-of-field source post-process
-            this.textureAdderFinalPostProcess = new PostProcess("HDRTextureAdderPostProcess", "standard", [], [], ratio, null, Texture.BILINEAR_SAMPLINGMODE, scene.getEngine(), true, "#define PASS_POST_PROCESS", Engine.TEXTURETYPE_UNSIGNED_INT);
+            this.textureAdderFinalPostProcess = new PostProcess("HDRDepthOfFieldSource", "standard", [], [], ratio, null, Texture.BILINEAR_SAMPLINGMODE, scene.getEngine(), true, "#define PASS_POST_PROCESS", Engine.TEXTURETYPE_UNSIGNED_INT);
             this.addEffect(new PostProcessRenderEffect(scene.getEngine(), "HDRDepthOfFieldSource", () => { return this.textureAdderFinalPostProcess; }, true));
 
             // Create lens flare post-process
@@ -216,7 +216,7 @@
         private _createGaussianBlurPostProcesses(scene: Scene, ratio: number, indice: number): void {
             var blurOffsets = new Array<number>(9);
             var blurWeights = new Array<number>(9);
-            var uniforms: string[] = ["blurOffsets", "blurWeights"];
+            var uniforms: string[] = ["blurOffsets", "blurWeights", "blurWidth"];
 
             var callback = (height: boolean) => {
                 return (effect: Effect) => {
@@ -243,6 +243,7 @@
 
                     effect.setArray("blurOffsets", blurOffsets);
                     effect.setArray("blurWeights", blurWeights);
+                    effect.setFloat("blurWidth", this.blurWidth);
                 };
             };
 
@@ -281,60 +282,69 @@
 
         // Create lens flare post-process
         private _createLensFlarePostProcess(scene: Scene, ratio: number): void {
-            this.lensFlarePostProcess = new PostProcess("HDRLensFlare", "standard", ["strength", "ghostDispersal", "haloWidth"], ["lensColorSampler"], ratio / 8, null, Texture.BILINEAR_SAMPLINGMODE, scene.getEngine(), true, "#define LENS_FLARE", Engine.TEXTURETYPE_UNSIGNED_INT);
-            this.lensFlareShiftPostProcess = new PostProcess("HDRLensFlareShift", "standard", ["resolution", "distortionStrength"], [], ratio / 8, null, Texture.BILINEAR_SAMPLINGMODE, scene.getEngine(), false, "#define LENS_FLARE_SHIFT", Engine.TEXTURETYPE_UNSIGNED_INT);
-            this._createGaussianBlurPostProcesses(scene, ratio / 8, 4);
-            this.lensFlareComposePostProcess = new PostProcess("HDRLensFlareCompose", "standard", ["viewMatrix", "scaleBias1", "scaleBias2"], ["otherSampler", "lensDirtSampler", "lensStarSampler"], ratio, null, Texture.BILINEAR_SAMPLINGMODE, scene.getEngine(), false, "#define LENS_FLARE_COMPOSE", Engine.TEXTURETYPE_UNSIGNED_INT);
+            this.lensFlarePostProcess = new PostProcess("HDRLensFlare", "standard", ["strength", "ghostDispersal", "haloWidth", "resolution", "distortionStrength"], ["lensColorSampler"], ratio / 2, null, Texture.BILINEAR_SAMPLINGMODE, scene.getEngine(), true, "#define LENS_FLARE", Engine.TEXTURETYPE_UNSIGNED_INT);
+            this.addEffect(new PostProcessRenderEffect(scene.getEngine(), "HDRLensFlare", () => { return this.lensFlarePostProcess; }, false));
+
+            this._createGaussianBlurPostProcesses(scene, ratio / 4, 4);
+
+            this.lensFlareComposePostProcess = new PostProcess("HDRLensFlareCompose", "standard", ["lensStarMatrix"], ["otherSampler", "lensDirtSampler", "lensStarSampler"], ratio, null, Texture.BILINEAR_SAMPLINGMODE, scene.getEngine(), false, "#define LENS_FLARE_COMPOSE", Engine.TEXTURETYPE_UNSIGNED_INT);
+            this.addEffect(new PostProcessRenderEffect(scene.getEngine(), "HDRLensFlareCompose", () => { return this.lensFlareComposePostProcess; }, false));
 
             var resolution = new Vector2(0, 0);
 
             // Lens flare
             this.lensFlarePostProcess.onApply = (effect: Effect) => {
-                effect.setTextureFromPostProcess("textureSampler", this.textureAdderPostProcess);
+                effect.setTextureFromPostProcess("textureSampler", this.gaussianBlurHPostProcesses[0]);
                 effect.setTexture("lensColorSampler", this.lensColorTexture);
                 effect.setFloat("strength", this.lensFlareStrength);
                 effect.setFloat("ghostDispersal", this.lensFlareGhostDispersal);
                 effect.setFloat("haloWidth", this.lensFlareHaloWidth);
-            };
 
-            // Shift
-            this.lensFlareShiftPostProcess.onApply = (effect: Effect) => {
-                resolution.x = this.lensFlareShiftPostProcess.width;
-                resolution.y = this.lensFlareShiftPostProcess.height;
+                // Shift
+                resolution.x = this.lensFlarePostProcess.width;
+                resolution.y = this.lensFlarePostProcess.height;
                 effect.setVector2("resolution", resolution);
 
                 effect.setFloat("distortionStrength", this.lensFlareDistortionStrength);
             };
 
             // Compose
-            var scaleBias1 = Matrix.GetAsMatrix3x3(Matrix.FromValues(
+            var scaleBias1 = Matrix.FromValues(
                 2.0, 0.0, -1.0, 0.0,
                 0.0, 2.0, -1.0, 0.0,
                 0.0, 0.0, 1.0, 0.0,
-                0.0, 0.0, 0.0, 0.0
-            ));
+                0.0, 0.0, 0.0, 1.0
+            );
 
-            var scaleBias2 = Matrix.GetAsMatrix3x3(Matrix.FromValues(
+            var scaleBias2 = Matrix.FromValues(
                 0.5, 0.0, 0.5, 0.0,
                 0.0, 0.5, 0.5, 0.0,
                 0.0, 0.0, 1.0, 0.0,
-                0.0, 0.0, 0.0, 0.0
-            ));
+                0.0, 0.0, 0.0, 1.0
+            );
 
             this.lensFlareComposePostProcess.onApply = (effect: Effect) => {
                 effect.setTextureFromPostProcess("otherSampler", this.textureAdderFinalPostProcess);
                 effect.setTexture("lensDirtSampler", this.lensFlareDirtTexture);
                 effect.setTexture("lensStarSampler", this.lensStarTexture);
 
-                effect.setMatrix("viewMatrix", this._scene.activeCamera.getViewMatrix());
-                effect.setMatrix3x3("scaleBias1", scaleBias1);
-                effect.setMatrix3x3("scaleBias2", scaleBias2);
-            };
+                // Lens start rotation matrix
+                var camerax = this._scene.activeCamera.getViewMatrix().getRow(0);
+                var cameraz = this._scene.activeCamera.getViewMatrix().getRow(2);
+                var camRot = Vector3.Dot(camerax.toVector3(), new Vector3(1.0, 0.0, 0.0)) + Vector3.Dot(cameraz.toVector3(), new Vector3(0.0, 0.0, 1.0));
+                camRot *= 4.0;
 
-            // Add to pipeline
-            this.addEffect(new PostProcessRenderEffect(scene.getEngine(), "HDRLensFlare", () => { return this.lensFlarePostProcess; }, false));
-            this.addEffect(new PostProcessRenderEffect(scene.getEngine(), "HDRLensFlareShift", () => { return this.lensFlareShiftPostProcess; }, false));
-            this.addEffect(new PostProcessRenderEffect(scene.getEngine(), "HDRLensFlareCompose", () => { return this.lensFlareComposePostProcess; }, false));
+                var starRotation = Matrix.FromValues(
+                    Math.cos(camRot) * 0.5, -Math.sin(camRot), 0.0, 0.0,
+                    Math.sin(camRot), Math.cos(camRot) * 0.5, 0.0, 0.0,
+                    0.0, 0.0, 1.0, 0.0,
+                    0.0, 0.0, 0.0, 1.0
+                );
+
+                var lensStarMatrix = scaleBias2.multiply(starRotation).multiply(scaleBias1);
+
+                effect.setMatrix("lensStarMatrix", lensStarMatrix);
+            };
         }
 
         // Create depth-of-field post-process
@@ -350,5 +360,34 @@
             // Add to pipeline
             this.addEffect(new PostProcessRenderEffect(scene.getEngine(), "HDRDepthOfField", () => { return this.depthOfFieldPostProcess; }, true));
         }
+
+        // Dispose
+        public dispose(): void {
+            for (var i = 0; i < this._scene.cameras.length; i++) {
+                var camera = this._scene.cameras[i];
+
+                this.originalPostProcess.dispose(camera);
+                this.downSampleX4PostProcess.dispose(camera);
+                this.brightPassPostProcess.dispose(camera);
+                this.textureAdderPostProcess.dispose(camera);
+
+                for (var j = 0; j < this.gaussianBlurHPostProcesses.length; j++) {
+                    this.gaussianBlurHPostProcesses[j].dispose(camera);
+                }
+
+                for (var j = 0; j < this.gaussianBlurVPostProcesses.length; j++) {
+                    this.gaussianBlurVPostProcesses[j].dispose(camera);
+                }
+
+                this.textureAdderFinalPostProcess.dispose(camera);
+                this.lensFlarePostProcess.dispose(camera);
+                this.lensFlareComposePostProcess.dispose(camera);
+                this.depthOfFieldPostProcess.dispose(camera);
+            }
+
+            this._scene.postProcessRenderPipelineManager.detachCamerasFromRenderPipeline(this._name, this._scene.cameras);
+
+            super.dispose();
+        }
     }
 }