babylon.vrDistortionCorrectionPostProcess.js 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. var __extends = (this && this.__extends) || function (d, b) {
  2. for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
  3. function __() { this.constructor = d; }
  4. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  5. };
  6. var BABYLON;
  7. (function (BABYLON) {
  8. var VRDistortionCorrectionPostProcess = (function (_super) {
  9. __extends(VRDistortionCorrectionPostProcess, _super);
  10. //ANY
  11. function VRDistortionCorrectionPostProcess(name, camera, isRightEye, vrMetrics) {
  12. var _this = this;
  13. _super.call(this, name, "vrDistortionCorrection", [
  14. 'LensCenter',
  15. 'Scale',
  16. 'ScaleIn',
  17. 'HmdWarpParam'
  18. ], null, vrMetrics.postProcessScaleFactor, camera, BABYLON.Texture.BILINEAR_SAMPLINGMODE, null, null);
  19. this._isRightEye = isRightEye;
  20. this._distortionFactors = vrMetrics.distortionK;
  21. this._postProcessScaleFactor = vrMetrics.postProcessScaleFactor;
  22. this._lensCenterOffset = vrMetrics.lensCenterOffset;
  23. this.onSizeChanged = function () {
  24. _this.aspectRatio = _this.width * .5 / _this.height;
  25. _this._scaleIn = new BABYLON.Vector2(2, 2 / _this.aspectRatio);
  26. _this._scaleFactor = new BABYLON.Vector2(.5 * (1 / _this._postProcessScaleFactor), .5 * (1 / _this._postProcessScaleFactor) * _this.aspectRatio);
  27. _this._lensCenter = new BABYLON.Vector2(_this._isRightEye ? 0.5 - _this._lensCenterOffset * 0.5 : 0.5 + _this._lensCenterOffset * 0.5, 0.5);
  28. };
  29. this.onApply = function (effect) {
  30. effect.setFloat2("LensCenter", _this._lensCenter.x, _this._lensCenter.y);
  31. effect.setFloat2("Scale", _this._scaleFactor.x, _this._scaleFactor.y);
  32. effect.setFloat2("ScaleIn", _this._scaleIn.x, _this._scaleIn.y);
  33. effect.setFloat4("HmdWarpParam", _this._distortionFactors[0], _this._distortionFactors[1], _this._distortionFactors[2], _this._distortionFactors[3]);
  34. };
  35. }
  36. return VRDistortionCorrectionPostProcess;
  37. })(BABYLON.PostProcess);
  38. BABYLON.VRDistortionCorrectionPostProcess = VRDistortionCorrectionPostProcess;
  39. })(BABYLON || (BABYLON = {}));