stereoscopicInterlacePostProcess.ts 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. import { Nullable } from "../types";
  2. import { Vector2 } from "../Maths/math.vector";
  3. import { Camera } from "../Cameras/camera";
  4. import { Effect } from "../Materials/effect";
  5. import { PostProcess } from "./postProcess";
  6. import { Engine } from "../Engines/engine";
  7. import "../Shaders/stereoscopicInterlace.fragment";
  8. /**
  9. * StereoscopicInterlacePostProcessI used to render stereo views from a rigged camera with support for alternate line interlacing
  10. */
  11. export class StereoscopicInterlacePostProcessI extends PostProcess {
  12. private _stepSize: Vector2;
  13. private _passedProcess: Nullable<PostProcess>;
  14. /**
  15. * Initializes a StereoscopicInterlacePostProcessI
  16. * @param name The name of the effect.
  17. * @param rigCameras The rig cameras to be appled to the post process
  18. * @param isStereoscopicHoriz If the rendered results are horizontal or vertical
  19. * @param isStereoscopicInterlaced If the rendered results are alternate line interlaced
  20. * @param samplingMode The sampling mode to be used when computing the pass. (default: 0)
  21. * @param engine The engine which the post process will be applied. (default: current engine)
  22. * @param reusable If the post process can be reused on the same frame. (default: false)
  23. */
  24. constructor(name: string, rigCameras: Camera[], isStereoscopicHoriz: boolean, isStereoscopicInterlaced: boolean, samplingMode?: number, engine?: Engine, reusable?: boolean) {
  25. super(name, "stereoscopicInterlace", ['stepSize'], ['camASampler'], 1, rigCameras[1], samplingMode, engine, reusable, isStereoscopicInterlaced ? "#define IS_STEREOSCOPIC_INTERLACED 1" : isStereoscopicHoriz ? "#define IS_STEREOSCOPIC_HORIZ 1" : undefined);
  26. this._passedProcess = rigCameras[0]._rigPostProcess;
  27. this._stepSize = new Vector2(1 / this.width, 1 / this.height);
  28. this.onSizeChangedObservable.add(() => {
  29. this._stepSize = new Vector2(1 / this.width, 1 / this.height);
  30. });
  31. this.onApplyObservable.add((effect: Effect) => {
  32. effect.setTextureFromPostProcess("camASampler", this._passedProcess);
  33. effect.setFloat2("stepSize", this._stepSize.x, this._stepSize.y);
  34. });
  35. }
  36. }
  37. /**
  38. * StereoscopicInterlacePostProcess used to render stereo views from a rigged camera
  39. */
  40. export class StereoscopicInterlacePostProcess extends PostProcess {
  41. private _stepSize: Vector2;
  42. private _passedProcess: Nullable<PostProcess>;
  43. /**
  44. * Initializes a StereoscopicInterlacePostProcess
  45. * @param name The name of the effect.
  46. * @param rigCameras The rig cameras to be appled to the post process
  47. * @param isStereoscopicHoriz If the rendered results are horizontal or verticle
  48. * @param samplingMode The sampling mode to be used when computing the pass. (default: 0)
  49. * @param engine The engine which the post process will be applied. (default: current engine)
  50. * @param reusable If the post process can be reused on the same frame. (default: false)
  51. */
  52. constructor(name: string, rigCameras: Camera[], isStereoscopicHoriz: boolean, samplingMode?: number, engine?: Engine, reusable?: boolean) {
  53. super(name, "stereoscopicInterlace", ['stepSize'], ['camASampler'], 1, rigCameras[1], samplingMode, engine, reusable, isStereoscopicHoriz ? "#define IS_STEREOSCOPIC_HORIZ 1" : undefined);
  54. this._passedProcess = rigCameras[0]._rigPostProcess;
  55. this._stepSize = new Vector2(1 / this.width, 1 / this.height);
  56. this.onSizeChangedObservable.add(() => {
  57. this._stepSize = new Vector2(1 / this.width, 1 / this.height);
  58. });
  59. this.onApplyObservable.add((effect: Effect) => {
  60. effect.setTextureFromPostProcess("camASampler", this._passedProcess);
  61. effect.setFloat2("stepSize", this._stepSize.x, this._stepSize.y);
  62. });
  63. }
  64. }