vrMultiviewToSingleviewPostProcess.ts 1.4 KB

12345678910111213141516171819202122232425262728293031323334
  1. import { Camera } from "../Cameras/camera";
  2. import { Effect } from "../Materials/effect";
  3. import { Texture } from "../Materials/Textures/texture";
  4. import { PostProcess } from "./postProcess";
  5. import "../Shaders/vrMultiviewToSingleview.fragment";
  6. import "../Engines/Extensions/engine.multiview";
  7. /**
  8. * VRMultiviewToSingleview used to convert multiview texture arrays to standard textures for scenarios such as webVR
  9. * This will not be used for webXR as it supports displaying texture arrays directly
  10. */
  11. export class VRMultiviewToSingleviewPostProcess extends PostProcess {
  12. /**
  13. * Initializes a VRMultiviewToSingleview
  14. * @param name name of the post process
  15. * @param camera camera to be applied to
  16. * @param scaleFactor scaling factor to the size of the output texture
  17. */
  18. constructor(name: string, camera: Camera, scaleFactor: number) {
  19. super(name, "vrMultiviewToSingleview", ["imageIndex"], ["multiviewSampler"], scaleFactor, camera, Texture.BILINEAR_SAMPLINGMODE);
  20. this.onSizeChangedObservable.add(() => {
  21. });
  22. this.onApplyObservable.add((effect: Effect) => {
  23. if (camera._scene.activeCamera && camera._scene.activeCamera.isLeftCamera) {
  24. effect.setInt("imageIndex", 0);
  25. }else {
  26. effect.setInt("imageIndex", 1);
  27. }
  28. effect.setTexture("multiviewSampler", camera._multiviewTexture);
  29. });
  30. }
  31. }