vrMultiviewToSingleviewPostProcess.ts 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  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. * Gets a string identifying the name of the class
  14. * @returns "VRMultiviewToSingleviewPostProcess" string
  15. */
  16. public getClassName(): string {
  17. return "VRMultiviewToSingleviewPostProcess";
  18. }
  19. /**
  20. * Initializes a VRMultiviewToSingleview
  21. * @param name name of the post process
  22. * @param camera camera to be applied to
  23. * @param scaleFactor scaling factor to the size of the output texture
  24. */
  25. constructor(name: string, camera: Camera, scaleFactor: number) {
  26. super(name, "vrMultiviewToSingleview", ["imageIndex"], ["multiviewSampler"], scaleFactor, camera, Texture.BILINEAR_SAMPLINGMODE);
  27. this.onSizeChangedObservable.add(() => {
  28. });
  29. this.onApplyObservable.add((effect: Effect) => {
  30. if (camera._scene.activeCamera && camera._scene.activeCamera.isLeftCamera) {
  31. effect.setInt("imageIndex", 0);
  32. }else {
  33. effect.setInt("imageIndex", 1);
  34. }
  35. effect.setTexture("multiviewSampler", camera._multiviewTexture);
  36. });
  37. }
  38. }