Browse Source

New folks: oculus camera, filter post process, fixed convoltion post process

Deltakosh 11 years ago
parent
commit
fe01f440f1

+ 28 - 0
Babylon/Cameras/Controllers/babylon.globalAxisFactorsFilter.js

@@ -0,0 +1,28 @@
+"use strict";
+
+var BABYLON = BABYLON || {};
+
+(function () {
+	BABYLON.globalAxisFactorsFilter = function (scene, target, xFactor, yFactor, zFactor) {
+		BABYLON.inputFilter.call(this, scene,target);
+		this.xFactor = xFactor;
+		this.yFactor = yFactor;
+		this.zFactor = zFactor;
+
+		this._localToGlobalMatrix = new BABYLON.Matrix();
+		this._globalToLocalMatrix = new BABYLON.Matrix();
+		this._globalMovement = new BABYLON.Vector3(0, 0, 0);
+	};
+	BABYLON.globalAxisFactorsFilter.prototype = Object.create(BABYLON.inputFilter.prototype);
+	BABYLON.globalAxisFactorsFilter.prototype.moveRelative = function (relativeMovement) {
+		var orientation = this.getOrientation();
+		BABYLON.Matrix.RotationYawPitchRollToRef(orientation.yaw, orientation.pitch, orientation.roll, this._localToGlobalMatrix);
+		this._localToGlobalMatrix.invertToRef(this._globalToLocalMatrix);
+		BABYLON.Vector3.TransformNormalToRef(relativeMovement, this._localToGlobalMatrix, this._globalMovement);
+		this._globalMovement.x *= this.xFactor;
+		this._globalMovement.y *= this.yFactor;
+		this._globalMovement.z *= this.zFactor;
+		BABYLON.Vector3.TransformNormalToRef(this._globalMovement, this._globalToLocalMatrix, relativeMovement);
+		this.target.moveRelative(relativeMovement);
+	};
+})();

+ 24 - 0
Babylon/Cameras/Controllers/babylon.gravityInputController.js

@@ -0,0 +1,24 @@
+"use strict";
+
+var BABYLON = BABYLON || {};
+
+(function () {
+    BABYLON.GravityInputController = function (scene, target) {
+        BABYLON.inputController.call(this, scene, target);
+        this._fallSpeed = 1; // 1 meters per second
+        this._moveVectorGlobal = new BABYLON.Vector3(0, 0, 0);
+        this._moveVectorLocal = new BABYLON.Vector3(0, 0, 0);
+        this._invertMatrix = new BABYLON.Matrix();
+    };
+    BABYLON.GravityInputController.prototype = Object.create(BABYLON.inputController.prototype);
+    BABYLON.GravityInputController.prototype.update = function () {
+        var orientation = this.target.getOrientation();
+        BABYLON.Matrix.RotationYawPitchRollToRef(orientation.yaw, orientation.pitch, orientation.roll, this._invertMatrix);
+        this._invertMatrix.invert();
+        this._moveVectorGlobal.x = 0;
+        this._moveVectorGlobal.y = -this._fallSpeed * BABYLON.Tools.GetDeltaTime() / 1000.0;
+        this._moveVectorGlobal.z = 0;
+        BABYLON.Vector3.TransformNormalToRef(this._moveVectorGlobal,this._invertMatrix, this._moveVectorLocal);
+        this.target.moveRelative(this._moveVectorLocal);
+    };
+})();

+ 47 - 0
Babylon/Cameras/Controllers/babylon.inputCollisionFilter.js

@@ -0,0 +1,47 @@
+"use strict";
+
+var BABYLON = BABYLON || {};
+
+(function () {
+	BABYLON.inputCollisionFilter = function (scene, target, ellipsoid) {
+		BABYLON.inputFilter.call(this, scene, target);
+		this._orientationMatrix = new BABYLON.Matrix();
+		this._orientationMatrixInvert = new BABYLON.Matrix();
+		this._transformedDirection = new BABYLON.Vector3();
+		this._tempNewPosition = new BABYLON.Vector3();
+		this._tempNewPosition2 = new BABYLON.Vector3();
+		this._ellipsoid = ellipsoid || new BABYLON.Vector3(.5,.5,.5);
+		this._collider = new BABYLON.Collider();
+		this._collidedPosition = new BABYLON.Vector3(0, 0, 0);
+		this._cameraHeight = 1.7;
+		this._positionBottom = new BABYLON.Vector3(0, 0, 0);
+	};
+	BABYLON.inputCollisionFilter.prototype = Object.create(BABYLON.inputFilter.prototype);
+	BABYLON.inputCollisionFilter.prototype.moveRelative = function (relativeMovement) {
+		var rotation = this.getOrientation();
+		BABYLON.Matrix.RotationYawPitchRollToRef(rotation.yaw, rotation.pitch, rotation.roll, this._orientationMatrix);
+		BABYLON.Vector3.TransformNormalToRef(relativeMovement, this._orientationMatrix, this._transformedDirection);
+		this.getPosition().addToRef(this._transformedDirection, this._tempNewPosition);
+		//this._tempNewPosition.y -= this._ellipsoid.y;
+		this._collider.radius = this._ellipsoid;
+		var p = this.getPosition();
+		this._positionBottom.x = p.x;
+		this._positionBottom.y = p.y;
+		this._positionBottom.z = p.z;
+		this._positionBottom.y +=  this._ellipsoid.y - this._cameraHeight;
+
+		this.scene._getNewPosition(this._positionBottom, this._transformedDirection, this._collider, 3, this._collidedPosition);
+
+
+		this._collidedPosition.subtractToRef(this._positionBottom, this._tempNewPosition2);
+
+		if (this._tempNewPosition2.length() > BABYLON.Engine.collisionsEpsilon) {
+
+		    this._orientationMatrix.invertToRef(this._orientationMatrixInvert);
+		    BABYLON.Vector3.TransformNormalToRef(this._tempNewPosition2, this._orientationMatrixInvert, this._tempNewPosition);
+
+		    this.target.moveRelative(this._tempNewPosition);
+		}
+
+	};
+})();

+ 110 - 0
Babylon/Cameras/Controllers/babylon.inputController.js

@@ -0,0 +1,110 @@
+"use strict";
+
+var BABYLON = BABYLON || {};
+
+(function () {
+
+	BABYLON.inputControllerTarget = function () {
+		this._position = new BABYLON.Vector3(0, 0, 0);
+		this._orientation = { yaw: 0.0, pitch: 0.0, roll: 0.0 };
+	};
+
+	BABYLON.inputControllerTarget.prototype.getPosition = function () {
+		return this._position;
+	};
+	BABYLON.inputControllerTarget.prototype.getOrientation = function () {
+		return this._orientation;
+	};
+	BABYLON.inputControllerTarget.prototype.moveRelative = function (movementVector) {
+
+	};
+	
+	BABYLON.inputControllerTarget.prototype.rotateRelative = function (relativeOrientation) {
+
+	};
+
+	BABYLON.inputControllerMultiTarget = function (targets) {
+	    this.targets = targets;
+	    var mainTarget = this.targets[0];
+	    if (!mainTarget.controllers) {
+	        mainTarget.controllers = [this];
+	    } else {
+	        mainTarget.controllers.push(this);
+	    }
+	};
+
+	BABYLON.inputControllerMultiTarget.prototype.getPosition = function () {
+		return this.targets[0].getPosition();
+	};
+	BABYLON.inputControllerMultiTarget.prototype.getOrientation = function () {
+		return this.targets[0].getOrientation();
+	};
+	BABYLON.inputControllerMultiTarget.prototype.moveRelative = function (movementVector) {
+		for (var i = 0; i < this.targets.length; ++i) {
+			this.targets[i].moveRelative(movementVector);
+		}
+	};
+
+	BABYLON.inputControllerMultiTarget.prototype.rotateRelative = function (relativeOrientation) {
+		for (var i = 0; i < this.targets.length; ++i) {
+			this.targets[i].rotateRelative(relativeOrientation);
+		}
+	};
+
+	BABYLON.inputControllerMultiTarget.prototype.update = function () {
+		if (this.controllers) {
+			for (var i = 0; i < this.controllers.length; ++i) {
+				this.controllers[i].update();
+			}
+		}
+	};
+	
+	BABYLON.inputController = function (scene, target) {
+		this.scene = scene;
+		this.target = target;
+		if (!this.target.controllers) {
+			this.target.controllers = [this];
+		} else {
+			this.target.controllers.push(this);
+		}
+	};
+	BABYLON.inputController.prototype.attachToCanvas = function (canvas) {
+
+	};
+	BABYLON.inputController.prototype.detachFromCanvas = function (canvas) {
+
+	};
+	BABYLON.inputController.prototype.update = function () {
+
+	};
+
+	BABYLON.inputController.prototype.dispose = function () {
+
+	};
+
+	BABYLON.inputFilter = function (scene, target) {
+	    BABYLON.inputController.call(this, scene, target);
+	};
+	BABYLON.inputFilter.prototype = Object.create(BABYLON.inputController.prototype);
+	BABYLON.inputFilter.prototype.update = function () {
+	    if (this.controllers) {
+	        for (var i = 0; i < this.controllers.length; ++i) {
+	            this.controllers[i].update();
+	        }
+	    }
+	};
+
+	BABYLON.inputFilter.prototype.getPosition = function () {
+	    return this.target.getPosition();
+	};
+	BABYLON.inputFilter.prototype.getOrientation = function () {
+	    return this.target.getOrientation();
+	};
+	BABYLON.inputFilter.prototype.moveRelative = function (movementVector) {
+	    this.target.moveRelative(movementVector);
+	};
+
+	BABYLON.inputFilter.prototype.rotateRelative = function (relativeOrientation) {
+	    this.target.rotateRelative(relativeOrientation);
+	};
+})();

+ 133 - 0
Babylon/Cameras/Controllers/babylon.keyboardMoveController.js

@@ -0,0 +1,133 @@
+"use strict";
+
+var BABYLON = BABYLON || {};
+
+(function () {
+	BABYLON.keyboardMoveController = function (scene, target) {
+		BABYLON.inputController.call(this, scene, target);
+		this._keys = [];
+		this.keysUp = [38];
+		this.keysDown = [40];
+		this.keysLeft = [37];
+		this.keysRight = [39];
+		this._currentSpeed = new BABYLON.Vector3(0, 0, 0);
+		this._lastFrameSpeed = new BABYLON.Vector3(0, 0, 0);
+		this._currentAcceleration = new BABYLON.Vector3(0, 0, 0);
+		this._tempSpeed = new BABYLON.Vector3(0, 0, 0);
+		this._tempSpeed2 = new BABYLON.Vector3(0, 0, 0);
+		this.maxAbsoluteSpeed = 2; // 2 meters per second
+		this.maxAbsoluteAcceleration = 5; // 2 meters per second²
+		this._targetSpeed = new BABYLON.Vector3(0, 0, 0);
+	};
+	BABYLON.keyboardMoveController.prototype = Object.create(BABYLON.inputController.prototype);
+	BABYLON.keyboardMoveController.prototype.attachToCanvas = function (canvas) {
+		var that = this;
+		this._canvas = canvas;
+
+		this._onKeyDown = function (evt) {
+			if (that.keysUp.indexOf(evt.keyCode) !== -1 ||
+				that.keysDown.indexOf(evt.keyCode) !== -1 ||
+				that.keysLeft.indexOf(evt.keyCode) !== -1 ||
+				that.keysRight.indexOf(evt.keyCode) !== -1) {
+				var index = that._keys.indexOf(evt.keyCode);
+
+				if (index === -1) {
+					that._keys.push(evt.keyCode);
+				}
+			}
+		};
+
+		this._onKeyUp = function (evt) {
+			if (that.keysUp.indexOf(evt.keyCode) !== -1 ||
+				that.keysDown.indexOf(evt.keyCode) !== -1 ||
+				that.keysLeft.indexOf(evt.keyCode) !== -1 ||
+				that.keysRight.indexOf(evt.keyCode) !== -1) {
+				var index = that._keys.indexOf(evt.keyCode);
+
+				if (index >= 0) {
+					that._keys.splice(index, 1);
+				}
+			}
+		};
+
+		this._onLostFocus = function () {
+			that._keys = [];
+		};
+
+		window.addEventListener("keydown", this._onKeyDown, false);
+		window.addEventListener("keyup", this._onKeyUp, false);
+		window.addEventListener("blur", this._onLostFocus, false);
+	};
+	BABYLON.keyboardMoveController.prototype.detachFromCanvas = function (canvas) {
+		window.removeEventListener("keydown", this._onKeyDown, false);
+		window.removeEventListener("keyup", this._onKeyUp, false);
+		window.removeEventListener("blur", this._onLostFocus, false);
+	};
+	BABYLON.keyboardMoveController.prototype.updateCurrentSpeed = function () {
+		this._lastFrameSpeed.x = this._currentSpeed.x;
+		this._lastFrameSpeed.y = this._currentSpeed.y;
+		this._lastFrameSpeed.z = this._currentSpeed.z;
+		if (this._currentSpeed.equals(this._targetSpeed)) {
+			this._currentAcceleration.x = 0;
+			this._currentAcceleration.y = 0;
+			this._currentAcceleration.z = 0;
+			return;
+		}
+		var dt = BABYLON.Tools.GetDeltaTime()/1000.0;
+		
+		var dv = this._tempSpeed;
+		this._targetSpeed.subtractToRef(this._lastFrameSpeed, dv);
+		var absoluteAccToTarget = dv.length() / dt;
+		if (absoluteAccToTarget < this.maxAbsoluteAcceleration) {
+			this._currentSpeed.x = this._targetSpeed.x;
+			this._currentSpeed.y = this._targetSpeed.y;
+			this._currentSpeed.z = this._targetSpeed.z;
+			dv.normalize();
+			dv.scaleToRef(absoluteAccToTarget, this._currentAcceleration);
+		} else {
+			dv.normalize();
+			dv.scaleToRef(this.maxAbsoluteAcceleration, this._currentAcceleration);
+			dv.scaleInPlace(this.maxAbsoluteAcceleration * dt);
+		
+			this._currentSpeed.addInPlace(dv);
+		}
+	};
+	BABYLON.keyboardMoveController.prototype.update = function () {
+		this._targetSpeed.x = 0;
+		this._targetSpeed.y = 0;
+		this._targetSpeed.z = 0;
+		// update target speed from input
+		for (var index = 0; index < this._keys.length; index++) {
+			var keyCode = this._keys[index];
+			if (this.keysLeft.indexOf(keyCode) !== -1) {
+				this._targetSpeed.x -= 1;
+			} else if (this.keysUp.indexOf(keyCode) !== -1) {
+				this._targetSpeed.z += 1;
+			} else if (this.keysRight.indexOf(keyCode) !== -1) {
+				this._targetSpeed.x += 1;
+			} else if (this.keysDown.indexOf(keyCode) !== -1) {
+				this._targetSpeed.z -= 1;
+			}
+		}
+		if (this._targetSpeed.x != 0 || this._targetSpeed.z != 0) {
+			this._targetSpeed.normalize();
+			this._targetSpeed.scaleInPlace(this.maxAbsoluteSpeed);
+		}
+
+		this.updateCurrentSpeed();
+
+		if (this._lastFrameSpeed.x == 0 && this._lastFrameSpeed.z == 0 && this._currentAcceleration.x == 0 && this._currentAcceleration.z == 0) {
+			return;
+		}
+
+		// dv = (dt * v0) + 1/2 * dt² * a
+
+		var dt = BABYLON.Tools.GetDeltaTime() / 1000.0;
+		this._lastFrameSpeed.scaleToRef(dt, this._tempSpeed);
+		this._currentAcceleration.scaleToRef(dt * dt * 0.5, this._tempSpeed2);
+		this._tempSpeed.addInPlace(this._tempSpeed2);
+		if (this._tempSpeed.x != 0 || this._tempSpeed.z != 0) {
+			this.target.moveRelative(this._tempSpeed);
+		}
+	};
+})();

+ 53 - 0
Babylon/Cameras/Controllers/babylon.oculusController.js

@@ -0,0 +1,53 @@
+"use strict";
+
+var BABYLON = BABYLON || {};
+
+(function () {
+    BABYLON.OculusController = function (scene, target) {
+        BABYLON.inputController.call(this, scene, target);
+        this._deviceOrientationHandler = this.onOrientationEvent.bind(this);
+        this._tempOrientation = { yaw: 0.0, pitch: 0.0, roll: 0.0 };
+        this._relativeOrientation = { yaw: 0.0, pitch: 0.0, roll: 0.0 };
+        window.addEventListener("deviceorientation", this._deviceOrientationHandler);
+    };
+
+    BABYLON.OculusController.prototype = Object.create(BABYLON.inputController.prototype);
+
+    BABYLON.OculusController.prototype.onOrientationEvent = function (ev) {
+        this._tempOrientation.yaw = ev.alpha / 180 * Math.PI;
+        this._tempOrientation.pitch = ev.beta / 180 * Math.PI;
+        this._tempOrientation.roll = ev.gamma / 180 * Math.PI;
+
+        if (!this._lastOrientation) {
+            this._lastOrientation = Object.create(this._tempOrientation);
+        }
+        else {
+            this._relativeOrientation.yaw = this._tempOrientation.yaw - this._lastOrientation.yaw;
+            this._relativeOrientation.pitch = this._tempOrientation.pitch - this._lastOrientation.pitch;
+            this._relativeOrientation.roll = this._tempOrientation.roll - this._lastOrientation.roll;
+
+            var temp = this._tempOrientation;
+            this._tempOrientation = this._lastOrientation;
+            this._lastOrientation = temp;
+            this.target.rotateRelative(this._relativeOrientation);
+        }
+    };
+    BABYLON.OculusController.prototype.dispose = function () {
+        window.removeEventListener("deviceorientation", this._deviceOrientationHandler);
+    };
+
+    BABYLON.OculusController.CameraSettings_OculusRiftDevKit2013_Metric = {
+        HResolution: 1280,
+        VResolution: 800,
+        HScreenSize: 0.149759993,
+        VScreenSize: 0.0935999975,
+        VScreenCenter: 0.0467999987,
+        EyeToScreenDistance: 0.0410000011,
+        LensSeparationDistance: 0.0635000020,
+        InterpupillaryDistance: 0.0640000030,
+        DistortionK: [1.0, 0.219999999, 0.239999995, 0.0],
+        ChromaAbCorrection: [0.995999992, -0.00400000019, 1.01400006, 0.0],
+        PostProcessScaleFactor: 1.714605507808412,
+        LensCenterOffset: 0.151976421
+    };
+})();

+ 154 - 0
Babylon/Cameras/babylon.oculusOrientedCamera.js

@@ -0,0 +1,154 @@
+"use strict";
+
+var BABYLON = BABYLON || {};
+
+(function () {
+    BABYLON.OculusOrientedCamera = function (name, position, scene, isLeftEye, ovrSettings, neutralOrientation) {
+        BABYLON.Camera.call(this, name, position, scene);
+        this._referenceDirection = new BABYLON.Vector3(0, 0, 1);
+        this._referenceUp = new BABYLON.Vector3(0, 1, 0);
+        this._actualDirection = new BABYLON.Vector3(1, 0, 0);
+        this._actualUp = new BABYLON.Vector3(0, 1, 0);
+        this._currentTargetPoint = new BABYLON.Vector3(0, 0, 0);
+        this._currentOrientation = Object.create(neutralOrientation || { yaw: 0.0, pitch: 0.0, roll: 0.0 });
+        this._currentViewMatrix = new BABYLON.Matrix();
+        this._currentOrientationMatrix = new BABYLON.Matrix();
+        this._tempMatrix = new BABYLON.Matrix();
+        
+        if (isLeftEye) {
+            this.viewport = new BABYLON.Viewport(0, 0, 0.5, 1.0);
+        } else {
+            this.viewport = new BABYLON.Viewport(0.5, 0, 0.5, 1.0);
+        }
+
+        this._aspectRatioAspectRatio = ovrSettings.HResolution / (2 * ovrSettings.VResolution);
+        this._aspectRatioFov = (2 * Math.atan((ovrSettings.PostProcessScaleFactor * ovrSettings.VScreenSize) / (2 * ovrSettings.EyeToScreenDistance)));
+        var hMeters = (ovrSettings.HScreenSize / 4) - (ovrSettings.LensSeparationDistance / 2);
+        var h = (4 * hMeters) / ovrSettings.HScreenSize;
+        this._hMatrix = BABYLON.Matrix.Translation(isLeftEye ? h : -h, 0, 0);
+
+        this._projectionMatrix = new BABYLON.Matrix();
+        this._preViewMatrix = BABYLON.Matrix.Translation(isLeftEye ? .5 * ovrSettings.InterpupillaryDistance : -.5 * ovrSettings.InterpupillaryDistance, 0, 0);
+        new BABYLON.oculusDistortionCorrectionPostProcess("Oculus Distortion", this, !isLeftEye, ovrSettings);
+        this.resetProjectionMatrix();
+        this.resetViewMatrix();
+    };
+    
+    BABYLON.OculusOrientedCamera.BuildOculusStereoCamera = function (scene, name, canvas, minZ, maxZ, position, neutralOrientation, useFXAA, disableGravity,disableCollisions, ovrSettings) {
+        position = position || new BABYLON.Vector2(0, 0);
+        neutralOrientation = neutralOrientation || { yaw: 0.0, pitch: 0.0, roll: 0.0 };
+        //var controller =  new BABYLON.OculusController();
+        ovrSettings = ovrSettings || BABYLON.OculusController.CameraSettings_OculusRiftDevKit2013_Metric;
+
+        var leftCamera = new BABYLON.OculusOrientedCamera(name + "_left", position, scene, true, ovrSettings, neutralOrientation);
+        leftCamera.minZ = minZ;
+        leftCamera.maxZ = maxZ;
+        if (useFXAA) {
+            new BABYLON.FxaaPostProcess("fxaa_left", 1.0, leftCamera);
+        }
+
+        var rightCamera = new BABYLON.OculusOrientedCamera(name + "_right", position, scene, false, ovrSettings, neutralOrientation);
+        rightCamera.minZ = minZ;
+        rightCamera.maxZ = maxZ;
+        if (useFXAA) {
+            new BABYLON.FxaaPostProcess("fxaa_right", 1.0, rightCamera);
+        }
+        scene.activeCameras = [];
+        scene.activeCameras.push(leftCamera);
+        scene.activeCameras.push(rightCamera);
+        leftCamera.attachControl(canvas);
+        rightCamera.attachControl(canvas);
+        var multiTarget = new BABYLON.inputControllerMultiTarget([leftCamera, rightCamera]);
+        var controller = new BABYLON.OculusController(scene, multiTarget);
+        var moveTarget = multiTarget;
+        if (!disableCollisions) {
+            var collisionFilter = new BABYLON.inputCollisionFilter(scene, multiTarget);
+            moveTarget = collisionFilter;
+        }
+        if (!disableGravity) {
+
+            var globalAxisFactorFilter = new BABYLON.globalAxisFactorsFilter(scene, moveTarget, 1, 0, 1);
+            var gravityController = new BABYLON.GravityInputController(scene, moveTarget);
+            moveTarget = globalAxisFactorFilter;
+        }
+        var moveController = new BABYLON.keyboardMoveController(scene, moveTarget);
+        moveController.attachToCanvas(canvas);
+        var result = {
+            leftCamera: leftCamera, rightCamera: rightCamera, intermediateControllerTarget: multiTarget,
+            oculusController: controller,
+            keyboardController: moveController
+        };
+        result.dispose = function () {
+            this.leftCamera.detachControl(canvas);
+            this.rightCamera.detachControl(canvas);
+            this.leftCamera.dispose();
+            this.rightCamera.dispose();
+            this.oculusController.dispose();
+            this.keyboardController.detachFromCanvas(canvas);
+            this.keyboardController.dispose();
+        }.bind(result);
+        return result;
+    };
+    
+    BABYLON.OculusOrientedCamera.prototype = Object.create(BABYLON.Camera.prototype);
+
+    BABYLON.OculusOrientedCamera.prototype.resetViewMatrix = function () {
+        BABYLON.Matrix.RotationYawPitchRollToRef(
+            this._currentOrientation.yaw,
+            this._currentOrientation.pitch,
+            -this._currentOrientation.roll
+            , this._currentOrientationMatrix);
+
+        BABYLON.Vector3.TransformNormalToRef(this._referenceDirection, this._currentOrientationMatrix, this._actualDirection);
+        BABYLON.Vector3.TransformNormalToRef(this._referenceUp, this._currentOrientationMatrix, this._actualUp);
+
+        BABYLON.Vector3.FromFloatsToRef(this.position.x + this._actualDirection.x, this.position.y + this._actualDirection.y, this.position.z + this._actualDirection.z, this._currentTargetPoint);
+        BABYLON.Matrix.LookAtLHToRef(this.position, this._currentTargetPoint, this._actualUp, this._tempMatrix);
+        this._tempMatrix.multiplyToRef(this._preViewMatrix, this._currentViewMatrix);
+        return this._currentViewMatrix;
+    };
+    BABYLON.OculusOrientedCamera.prototype.getViewMatrix = function () {
+
+        return this._currentViewMatrix;
+    };
+
+    BABYLON.OculusOrientedCamera.prototype._update = function () {
+        if (this.controllers) {
+            for (var i = 0; i < this.controllers.length; ++i) {
+                this.controllers[i].update();
+            }
+        }
+    };
+
+    BABYLON.OculusOrientedCamera.prototype.resetProjectionMatrix = function () {
+        BABYLON.Matrix.PerspectiveFovLHToRef(this._aspectRatioFov, this._aspectRatioAspectRatio, this.minZ, this.maxZ, this._tempMatrix);
+        this._tempMatrix.multiplyToRef(this._hMatrix, this._projectionMatrix);
+        return this._projectionMatrix;
+    };
+
+    BABYLON.OculusOrientedCamera.prototype.getProjectionMatrix = function (force) {
+        return this._projectionMatrix;
+    };
+
+    // implementation of inputControllerTarget
+    BABYLON.OculusOrientedCamera.prototype.getOrientation = function () {
+        return this._currentOrientation;
+    };
+    BABYLON.OculusOrientedCamera.prototype.getPosition = function () {
+        return this.position;
+    };
+    BABYLON.OculusOrientedCamera.prototype.moveRelative = function (movementVector) {
+        if (!this._tempMoveVector) {
+            this._tempMoveVector = new BABYLON.Vector3(0, 0, 0);
+        }
+        BABYLON.Vector3.TransformNormalToRef(movementVector, this._currentOrientationMatrix, this._tempMoveVector);
+        this.position.addInPlace(this._tempMoveVector);
+        this.resetViewMatrix();
+    };
+    BABYLON.OculusOrientedCamera.prototype.rotateRelative = function (rotation) {
+        this._currentOrientation.yaw += rotation.yaw;
+        this._currentOrientation.pitch += rotation.pitch;
+        this._currentOrientation.roll += rotation.roll;
+        this.resetViewMatrix();
+    };
+})();

+ 1 - 1
Babylon/LensFlare/babylon.lensFlareSystem.js

@@ -164,7 +164,7 @@ var BABYLON = BABYLON || {};
             var y = centerY - (distY * flare.position);
             var y = centerY - (distY * flare.position);
             
             
             var cw = flare.size;
             var cw = flare.size;
-            var ch = flare.size * engine.getAspectRatio();
+            var ch = flare.size * engine.getAspectRatio(this._scene.activeCamera);
             var cx = 2 * (x / globalViewport.width) - 1.0;
             var cx = 2 * (x / globalViewport.width) - 1.0;
             var cy = 1.0 - 2 * (y / globalViewport.height);
             var cy = 1.0 - 2 * (y / globalViewport.height);
             
             

+ 4 - 0
Babylon/Materials/babylon.effect.js

@@ -193,6 +193,10 @@ var BABYLON = BABYLON || {};
         this._valueCache[uniformName][2] = z;
         this._valueCache[uniformName][2] = z;
         this._valueCache[uniformName][3] = w;
         this._valueCache[uniformName][3] = w;
     };
     };
+    
+    BABYLON.Effect.prototype.setArray = function (uniformName, array) {
+        this._engine.setArray(this.getUniform(uniformName), array);
+    };
 
 
     BABYLON.Effect.prototype.setMatrices = function (uniformName, matrices) {
     BABYLON.Effect.prototype.setMatrices = function (uniformName, matrices) {
         this._engine.setMatrices(this.getUniform(uniformName), matrices);
         this._engine.setMatrices(this.getUniform(uniformName), matrices);

+ 5 - 0
Babylon/Mesh/babylon.mesh.js

@@ -896,6 +896,11 @@ var BABYLON = BABYLON || {};
             this._indexBuffer = null;
             this._indexBuffer = null;
         }
         }
 
 
+        // Physics
+        if (this.getPhysicsImpostor() != BABYLON.PhysicsEngine.NoImpostor) {
+            this.setPhysicsState({ impostor: BABYLON.PhysicsEngine.NoImpostor });
+        }
+
         // Remove from scene
         // Remove from scene
         var index = this._scene.meshes.indexOf(this);
         var index = this._scene.meshes.indexOf(this);
         this._scene.meshes.splice(index, 1);
         this._scene.meshes.splice(index, 1);

+ 13 - 4
Babylon/PostProcess/babylon.convolutionPostProcess.js

@@ -3,16 +3,25 @@
 var BABYLON = BABYLON || {};
 var BABYLON = BABYLON || {};
 
 
 (function () {
 (function () {
-    BABYLON.ConvolutionPostProcess = function (name, kernelMatrix, ratio, camera, samplingMode, engine, reusable) {
-        BABYLON.PostProcess.call(this, name, "convolution", ["kernelMatrix"], null, ratio, camera, samplingMode, engine, reusable);
+    BABYLON.ConvolutionPostProcess = function (name, kernel, ratio, camera, samplingMode, engine, reusable) {
+        BABYLON.PostProcess.call(this, name, "convolution", ["kernel", "screenSize"], null, ratio, camera, samplingMode, engine, reusable);
         
         
-        this.kernelMatrix = kernelMatrix;
+        this.kernel = kernel;
         var that = this;
         var that = this;
         this.onApply = function (effect) {
         this.onApply = function (effect) {
-            effect.setMatrix("kernelMatrix", that.kernelMatrix);
+            effect.setFloat2("screenSize", that.width, that.height);
+            effect.setArray("kernel", that.kernel);
         };
         };
     };
     };
     
     
     BABYLON.ConvolutionPostProcess.prototype = Object.create(BABYLON.PostProcess.prototype);
     BABYLON.ConvolutionPostProcess.prototype = Object.create(BABYLON.PostProcess.prototype);
+    
+    // Based on http://en.wikipedia.org/wiki/Kernel_(image_processing)
+    BABYLON.ConvolutionPostProcess.EdgeDetect0Kernel = [1, 0, -1, 0, 0, 0, -1, 0, 1];
+    BABYLON.ConvolutionPostProcess.EdgeDetect1Kernel = [0, 1, 0, 1, -4, 1, 0, 1, 0];
+    BABYLON.ConvolutionPostProcess.EdgeDetect2Kernel = [-1, -1, -1, -1, 8, -1, -1, -1, -1];
+    BABYLON.ConvolutionPostProcess.SharpenKernel = [0, -1, 0, -1, 5, -1, 0, -1, 0];
+    BABYLON.ConvolutionPostProcess.EmbossKernel = [-2, -1, 0, -1, 1, 1, 0, 1, 2];
+    BABYLON.ConvolutionPostProcess.GaussianKernel = [0, 1, 0, 1, 1, 1, 0, 1, 0];
 
 
 })();
 })();

+ 18 - 0
Babylon/PostProcess/babylon.filterPostProcess.js

@@ -0,0 +1,18 @@
+"use strict";
+
+var BABYLON = BABYLON || {};
+
+(function () {
+    BABYLON.FilterPostProcess = function (name, kernelMatrix, ratio, camera, samplingMode, engine, reusable) {
+        BABYLON.PostProcess.call(this, name, "filter", ["kernelMatrix"], null, ratio, camera, samplingMode, engine, reusable);
+        
+        this.kernelMatrix = kernelMatrix;
+        var that = this;
+        this.onApply = function (effect) {
+            effect.setMatrix("kernelMatrix", that.kernelMatrix);
+        };
+    };
+    
+    BABYLON.FilterPostProcess.prototype = Object.create(BABYLON.PostProcess.prototype);
+
+})();

+ 30 - 5
Babylon/Shaders/convolution.fragment.fx

@@ -6,12 +6,37 @@ precision mediump float;
 varying vec2 vUV;
 varying vec2 vUV;
 uniform sampler2D textureSampler;
 uniform sampler2D textureSampler;
 
 
-uniform mat4 kernelMatrix;
+uniform vec2 screenSize;
+uniform float kernel[9];
 
 
-void main(void) 
+void main(void)
 {
 {
-	vec3 baseColor = texture2D(textureSampler, vUV).rgb;
-	vec3 updatedColor = (kernelMatrix * vec4(baseColor, 1.0)).rgb;
+	vec2 onePixel = vec2(1.0, 1.0) / screenSize;
+	vec4 colorSum =
+		texture2D(textureSampler, vUV + onePixel * vec2(-1, -1)) * kernel[0] +
+		texture2D(textureSampler, vUV + onePixel * vec2(0, -1)) * kernel[1] +
+		texture2D(textureSampler, vUV + onePixel * vec2(1, -1)) * kernel[2] +
+		texture2D(textureSampler, vUV + onePixel * vec2(-1, 0)) * kernel[3] +
+		texture2D(textureSampler, vUV + onePixel * vec2(0, 0)) * kernel[4] +
+		texture2D(textureSampler, vUV + onePixel * vec2(1, 0)) * kernel[5] +
+		texture2D(textureSampler, vUV + onePixel * vec2(-1, 1)) * kernel[6] +
+		texture2D(textureSampler, vUV + onePixel * vec2(0, 1)) * kernel[7] +
+		texture2D(textureSampler, vUV + onePixel * vec2(1, 1)) * kernel[8];
 
 
-	gl_FragColor = vec4(updatedColor, 1.0);
+	float kernelWeight =
+		kernel[0] +
+		kernel[1] +
+		kernel[2] +
+		kernel[3] +
+		kernel[4] +
+		kernel[5] +
+		kernel[6] +
+		kernel[7] +
+		kernel[8];
+
+	if (kernelWeight <= 0.0) {
+		kernelWeight = 1.0;
+	}
+
+	gl_FragColor = vec4((colorSum / kernelWeight).rgb, 1);
 }
 }

+ 17 - 0
Babylon/Shaders/filter.fragment.fx

@@ -0,0 +1,17 @@
+#ifdef GL_ES
+precision mediump float;
+#endif
+
+// Samplers
+varying vec2 vUV;
+uniform sampler2D textureSampler;
+
+uniform mat4 kernelMatrix;
+
+void main(void)
+{
+	vec3 baseColor = texture2D(textureSampler, vUV).rgb;
+	vec3 updatedColor = (kernelMatrix * vec4(baseColor, 1.0)).rgb;
+
+	gl_FragColor = vec4(updatedColor, 1.0);
+}

+ 12 - 2
Babylon/babylon.engine.js

@@ -3,12 +3,15 @@
 var BABYLON = BABYLON || {};
 var BABYLON = BABYLON || {};
 
 
 (function () {
 (function () {
-    BABYLON.Engine = function (canvas, antialias) {
+    BABYLON.Engine = function (canvas, antialias, options) {
         this._renderingCanvas = canvas;
         this._renderingCanvas = canvas;
 
 
+        options = options || {};
+        options.antialias = antialias;
+
         // GL
         // GL
         try {
         try {
-            this._gl = canvas.getContext("webgl", { antialias: antialias }) || canvas.getContext("experimental-webgl", { antialias: antialias });
+            this._gl = canvas.getContext("webgl", options) || canvas.getContext("experimental-webgl", options);
         } catch (e) {
         } catch (e) {
             throw new Error("WebGL not supported");
             throw new Error("WebGL not supported");
         }
         }
@@ -455,6 +458,13 @@ var BABYLON = BABYLON || {};
 
 
         this._currentEffect = effect;
         this._currentEffect = effect;
     };
     };
+    
+    BABYLON.Engine.prototype.setArray = function (uniform, array) {
+        if (!uniform)
+            return;
+
+        this._gl.uniform1fv(uniform, array);
+    };
 
 
     BABYLON.Engine.prototype.setMatrices = function (uniform, matrices) {
     BABYLON.Engine.prototype.setMatrices = function (uniform, matrices) {
         if (!uniform)
         if (!uniform)

+ 1 - 0
Tools/BuildOurOwnBabylonJS/BuildOurOwnBabylonJS/babylonJS.xml

@@ -12,6 +12,7 @@
   <script src="Babylon/LensFlare/babylon.lensFlareSystem.js"></script>
   <script src="Babylon/LensFlare/babylon.lensFlareSystem.js"></script>
   <script src="Babylon/LensFlare/babylon.lensFlare.js"></script>
   <script src="Babylon/LensFlare/babylon.lensFlare.js"></script>
   <script src="Babylon/PostProcess/babylon.fxaaPostProcess.js"></script>
   <script src="Babylon/PostProcess/babylon.fxaaPostProcess.js"></script>
+  <script src="Babylon/PostProcess/babylon.filterPostProcess.js"></script>
   <script src="Babylon/PostProcess/babylon.convolutionPostProcess.js"></script>
   <script src="Babylon/PostProcess/babylon.convolutionPostProcess.js"></script>
   <script src="Babylon/PostProcess/babylon.blackAndWhitePostProcess.js"></script>
   <script src="Babylon/PostProcess/babylon.blackAndWhitePostProcess.js"></script>
   <script src="Babylon/PostProcess/babylon.refractionPostProcess.js"></script>
   <script src="Babylon/PostProcess/babylon.refractionPostProcess.js"></script>

File diff suppressed because it is too large
+ 5 - 3
babylon.1.9.0.js