babylon.oculusDistortionCorrectionPostProcess.js 1.8 KB

1234567891011121314151617181920212223242526272829303132
  1. "use strict";
  2. var BABYLON = BABYLON || {};
  3. (function () {
  4. BABYLON.oculusDistortionCorrectionPostProcess = function (name, camera, isRightEye, cameraSettings) {
  5. BABYLON.PostProcess.call(this, name, "oculusDistortionCorrection", [
  6. 'LensCenter',
  7. 'Scale',
  8. 'ScaleIn',
  9. 'HmdWarpParam'
  10. ], null, cameraSettings.PostProcessScaleFactor, camera, BABYLON.Texture.BILINEAR_SAMPLINGMODE, null, null);
  11. this._isRightEye = isRightEye;
  12. this._distortionFactors = cameraSettings.DistortionK;
  13. this._postProcessScaleFactor = cameraSettings.PostProcessScaleFactor;
  14. this._lensCenterOffset = cameraSettings.LensCenterOffset;
  15. };
  16. BABYLON.oculusDistortionCorrectionPostProcess.prototype = Object.create(BABYLON.PostProcess.prototype);
  17. BABYLON.oculusDistortionCorrectionPostProcess.prototype.onSizeChanged = function () {
  18. this.aspectRatio = this.width * .5 / this.height;
  19. this._scaleIn = new BABYLON.Vector2(2, 2 / this.aspectRatio);
  20. this._scaleFactor = new BABYLON.Vector2(.5 * (1/this._postProcessScaleFactor), .5 * (1/this._postProcessScaleFactor) * this.aspectRatio);
  21. this._lensCenter = new BABYLON.Vector2(this._isRightEye ? 0.5 - this._lensCenterOffset * 0.5 : 0.5 + this._lensCenterOffset * 0.5, 0.5);
  22. };
  23. BABYLON.oculusDistortionCorrectionPostProcess.prototype.onApply = function (effect) {
  24. effect.setFloat2("LensCenter", this._lensCenter.x, this._lensCenter.y);
  25. effect.setFloat2("Scale", this._scaleFactor.x, this._scaleFactor.y);
  26. effect.setFloat2("ScaleIn", this._scaleIn.x, this._scaleIn.y);
  27. effect.setFloat4("HmdWarpParam", this._distortionFactors[0], this._distortionFactors[1], this._distortionFactors[2], this._distortionFactors[3]);
  28. };
  29. })();