stereoscopicInterlacePostProcess.ts 4.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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. * Gets a string identifying the name of the class
  16. * @returns "StereoscopicInterlacePostProcessI" string
  17. */
  18. public getClassName(): string {
  19. return "StereoscopicInterlacePostProcessI";
  20. }
  21. /**
  22. * Initializes a StereoscopicInterlacePostProcessI
  23. * @param name The name of the effect.
  24. * @param rigCameras The rig cameras to be appled to the post process
  25. * @param isStereoscopicHoriz If the rendered results are horizontal or vertical
  26. * @param isStereoscopicInterlaced If the rendered results are alternate line interlaced
  27. * @param samplingMode The sampling mode to be used when computing the pass. (default: 0)
  28. * @param engine The engine which the post process will be applied. (default: current engine)
  29. * @param reusable If the post process can be reused on the same frame. (default: false)
  30. */
  31. constructor(name: string, rigCameras: Camera[], isStereoscopicHoriz: boolean, isStereoscopicInterlaced: boolean, samplingMode?: number, engine?: Engine, reusable?: boolean) {
  32. super(name, "stereoscopicInterlace", ['stepSize'], ['camASampler'], 1, rigCameras[1], samplingMode, engine, reusable, isStereoscopicInterlaced ? "#define IS_STEREOSCOPIC_INTERLACED 1" : isStereoscopicHoriz ? "#define IS_STEREOSCOPIC_HORIZ 1" : undefined);
  33. this._passedProcess = rigCameras[0]._rigPostProcess;
  34. this._stepSize = new Vector2(1 / this.width, 1 / this.height);
  35. this.onSizeChangedObservable.add(() => {
  36. this._stepSize = new Vector2(1 / this.width, 1 / this.height);
  37. });
  38. this.onApplyObservable.add((effect: Effect) => {
  39. effect.setTextureFromPostProcess("camASampler", this._passedProcess);
  40. effect.setFloat2("stepSize", this._stepSize.x, this._stepSize.y);
  41. });
  42. }
  43. }
  44. /**
  45. * StereoscopicInterlacePostProcess used to render stereo views from a rigged camera
  46. */
  47. export class StereoscopicInterlacePostProcess extends PostProcess {
  48. private _stepSize: Vector2;
  49. private _passedProcess: Nullable<PostProcess>;
  50. /**
  51. * Gets a string identifying the name of the class
  52. * @returns "StereoscopicInterlacePostProcess" string
  53. */
  54. public getClassName(): string {
  55. return "StereoscopicInterlacePostProcess";
  56. }
  57. /**
  58. * Initializes a StereoscopicInterlacePostProcess
  59. * @param name The name of the effect.
  60. * @param rigCameras The rig cameras to be appled to the post process
  61. * @param isStereoscopicHoriz If the rendered results are horizontal or verticle
  62. * @param samplingMode The sampling mode to be used when computing the pass. (default: 0)
  63. * @param engine The engine which the post process will be applied. (default: current engine)
  64. * @param reusable If the post process can be reused on the same frame. (default: false)
  65. */
  66. constructor(name: string, rigCameras: Camera[], isStereoscopicHoriz: boolean, samplingMode?: number, engine?: Engine, reusable?: boolean) {
  67. super(name, "stereoscopicInterlace", ['stepSize'], ['camASampler'], 1, rigCameras[1], samplingMode, engine, reusable, isStereoscopicHoriz ? "#define IS_STEREOSCOPIC_HORIZ 1" : undefined);
  68. this._passedProcess = rigCameras[0]._rigPostProcess;
  69. this._stepSize = new Vector2(1 / this.width, 1 / this.height);
  70. this.onSizeChangedObservable.add(() => {
  71. this._stepSize = new Vector2(1 / this.width, 1 / this.height);
  72. });
  73. this.onApplyObservable.add((effect: Effect) => {
  74. effect.setTextureFromPostProcess("camASampler", this._passedProcess);
  75. effect.setFloat2("stepSize", this._stepSize.x, this._stepSize.y);
  76. });
  77. }
  78. }