passPostProcess.ts 4.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. import { Nullable } from "../types";
  2. import { Constants } from "../Engines/constants";
  3. import { Camera } from "../Cameras/camera";
  4. import { PostProcess, PostProcessOptions } from "./postProcess";
  5. import { Engine } from "../Engines/engine";
  6. import "../Shaders/pass.fragment";
  7. import "../Shaders/passCube.fragment";
  8. /**
  9. * PassPostProcess which produces an output the same as it's input
  10. */
  11. export class PassPostProcess extends PostProcess {
  12. /**
  13. * Creates the PassPostProcess
  14. * @param name The name of the effect.
  15. * @param options The required width/height ratio to downsize to before computing the render pass.
  16. * @param camera The camera to apply the render pass to.
  17. * @param samplingMode The sampling mode to be used when computing the pass. (default: 0)
  18. * @param engine The engine which the post process will be applied. (default: current engine)
  19. * @param reusable If the post process can be reused on the same frame. (default: false)
  20. * @param textureType The type of texture to be used when performing the post processing.
  21. * @param blockCompilation If compilation of the shader should not be done in the constructor. The updateEffect method can be used to compile the shader at a later time. (default: false)
  22. */
  23. constructor(name: string, options: number | PostProcessOptions, camera: Nullable<Camera> = null, samplingMode?: number, engine?: Engine, reusable?: boolean, textureType: number = Constants.TEXTURETYPE_UNSIGNED_INT, blockCompilation = false) {
  24. super(name, "pass", null, null, options, camera, samplingMode, engine, reusable, undefined, textureType, undefined, null, blockCompilation);
  25. }
  26. }
  27. /**
  28. * PassCubePostProcess which produces an output the same as it's input (which must be a cube texture)
  29. */
  30. export class PassCubePostProcess extends PostProcess {
  31. private _face = 0;
  32. /**
  33. * Gets or sets the cube face to display.
  34. * * 0 is +X
  35. * * 1 is -X
  36. * * 2 is +Y
  37. * * 3 is -Y
  38. * * 4 is +Z
  39. * * 5 is -Z
  40. */
  41. public get face(): number {
  42. return this._face;
  43. }
  44. public set face(value: number) {
  45. if (value < 0 || value > 5) {
  46. return;
  47. }
  48. this._face = value;
  49. switch (this._face) {
  50. case 0:
  51. this.updateEffect("#define POSITIVEX");
  52. break;
  53. case 1:
  54. this.updateEffect("#define NEGATIVEX");
  55. break;
  56. case 2:
  57. this.updateEffect("#define POSITIVEY");
  58. break;
  59. case 3:
  60. this.updateEffect("#define NEGATIVEY");
  61. break;
  62. case 4:
  63. this.updateEffect("#define POSITIVEZ");
  64. break;
  65. case 5:
  66. this.updateEffect("#define NEGATIVEZ");
  67. break;
  68. }
  69. }
  70. /**
  71. * Creates the PassCubePostProcess
  72. * @param name The name of the effect.
  73. * @param options The required width/height ratio to downsize to before computing the render pass.
  74. * @param camera The camera to apply the render pass to.
  75. * @param samplingMode The sampling mode to be used when computing the pass. (default: 0)
  76. * @param engine The engine which the post process will be applied. (default: current engine)
  77. * @param reusable If the post process can be reused on the same frame. (default: false)
  78. * @param textureType The type of texture to be used when performing the post processing.
  79. * @param blockCompilation If compilation of the shader should not be done in the constructor. The updateEffect method can be used to compile the shader at a later time. (default: false)
  80. */
  81. constructor(name: string, options: number | PostProcessOptions, camera: Nullable<Camera> = null, samplingMode?: number, engine?: Engine, reusable?: boolean, textureType: number = Constants.TEXTURETYPE_UNSIGNED_INT, blockCompilation = false) {
  82. super(name, "passCube", null, null, options, camera, samplingMode, engine, reusable, "#define POSITIVEX", textureType, undefined, null, blockCompilation);
  83. }
  84. }
  85. Engine._RescalePostProcessFactory = (engine: Engine) => {
  86. return new PassPostProcess("rescale", 1, null, Engine.TEXTURE_BILINEAR_SAMPLINGMODE, engine, false, Engine.TEXTURETYPE_UNSIGNED_INT);
  87. };