passPostProcess.ts 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  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. import { _TypeStore } from '../Misc/typeStore';
  9. import { SerializationHelper } from '../Misc/decorators';
  10. declare type Scene = import("../scene").Scene;
  11. /**
  12. * PassPostProcess which produces an output the same as it's input
  13. */
  14. export class PassPostProcess extends PostProcess {
  15. /**
  16. * Gets a string identifying the name of the class
  17. * @returns "PassPostProcess" string
  18. */
  19. public getClassName(): string {
  20. return "PassPostProcess";
  21. }
  22. /**
  23. * Creates the PassPostProcess
  24. * @param name The name of the effect.
  25. * @param options The required width/height ratio to downsize to before computing the render pass.
  26. * @param camera The camera to apply the render pass to.
  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. * @param textureType The type of texture to be used when performing the post processing.
  31. * @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)
  32. */
  33. constructor(name: string, options: number | PostProcessOptions, camera: Nullable<Camera> = null, samplingMode?: number, engine?: Engine, reusable?: boolean, textureType: number = Constants.TEXTURETYPE_UNSIGNED_INT, blockCompilation = false) {
  34. super(name, "pass", null, null, options, camera, samplingMode, engine, reusable, undefined, textureType, undefined, null, blockCompilation);
  35. }
  36. /** @hidden */
  37. public static _Parse(parsedPostProcess: any, targetCamera: Camera, scene: Scene, rootUrl: string) {
  38. return SerializationHelper.Parse(() => {
  39. return new PassPostProcess(
  40. parsedPostProcess.name,
  41. parsedPostProcess.options, targetCamera,
  42. parsedPostProcess.renderTargetSamplingMode,
  43. scene.getEngine(), parsedPostProcess.reusable);
  44. }, parsedPostProcess, scene, rootUrl);
  45. }
  46. }
  47. _TypeStore.RegisteredTypes["BABYLON.PassPostProcess"] = PassPostProcess;
  48. /**
  49. * PassCubePostProcess which produces an output the same as it's input (which must be a cube texture)
  50. */
  51. export class PassCubePostProcess extends PostProcess {
  52. private _face = 0;
  53. /**
  54. * Gets or sets the cube face to display.
  55. * * 0 is +X
  56. * * 1 is -X
  57. * * 2 is +Y
  58. * * 3 is -Y
  59. * * 4 is +Z
  60. * * 5 is -Z
  61. */
  62. public get face(): number {
  63. return this._face;
  64. }
  65. public set face(value: number) {
  66. if (value < 0 || value > 5) {
  67. return;
  68. }
  69. this._face = value;
  70. switch (this._face) {
  71. case 0:
  72. this.updateEffect("#define POSITIVEX");
  73. break;
  74. case 1:
  75. this.updateEffect("#define NEGATIVEX");
  76. break;
  77. case 2:
  78. this.updateEffect("#define POSITIVEY");
  79. break;
  80. case 3:
  81. this.updateEffect("#define NEGATIVEY");
  82. break;
  83. case 4:
  84. this.updateEffect("#define POSITIVEZ");
  85. break;
  86. case 5:
  87. this.updateEffect("#define NEGATIVEZ");
  88. break;
  89. }
  90. }
  91. /**
  92. * Gets a string identifying the name of the class
  93. * @returns "PassCubePostProcess" string
  94. */
  95. public getClassName(): string {
  96. return "PassCubePostProcess";
  97. }
  98. /**
  99. * Creates the PassCubePostProcess
  100. * @param name The name of the effect.
  101. * @param options The required width/height ratio to downsize to before computing the render pass.
  102. * @param camera The camera to apply the render pass to.
  103. * @param samplingMode The sampling mode to be used when computing the pass. (default: 0)
  104. * @param engine The engine which the post process will be applied. (default: current engine)
  105. * @param reusable If the post process can be reused on the same frame. (default: false)
  106. * @param textureType The type of texture to be used when performing the post processing.
  107. * @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)
  108. */
  109. constructor(name: string, options: number | PostProcessOptions, camera: Nullable<Camera> = null, samplingMode?: number, engine?: Engine, reusable?: boolean, textureType: number = Constants.TEXTURETYPE_UNSIGNED_INT, blockCompilation = false) {
  110. super(name, "passCube", null, null, options, camera, samplingMode, engine, reusable, "#define POSITIVEX", textureType, undefined, null, blockCompilation);
  111. }
  112. /** @hidden */
  113. public static _Parse(parsedPostProcess: any, targetCamera: Camera, scene: Scene, rootUrl: string) {
  114. return SerializationHelper.Parse(() => {
  115. return new PassCubePostProcess(
  116. parsedPostProcess.name,
  117. parsedPostProcess.options, targetCamera,
  118. parsedPostProcess.renderTargetSamplingMode,
  119. scene.getEngine(), parsedPostProcess.reusable);
  120. }, parsedPostProcess, scene, rootUrl);
  121. }
  122. }
  123. Engine._RescalePostProcessFactory = (engine: Engine) => {
  124. return new PassPostProcess("rescale", 1, null, Constants.TEXTURE_BILINEAR_SAMPLINGMODE, engine, false, Constants.TEXTURETYPE_UNSIGNED_INT);
  125. };