depthOfFieldBlurPostProcess.js 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. import { __decorate } from "../tslib.es6.js";
  2. import { Texture } from "../Materials/Textures/texture.js";
  3. import { BlurPostProcess } from "./blurPostProcess.js";
  4. import { RegisterClass } from "../Misc/typeStore.js";
  5. import { serialize } from "../Misc/decorators.js";
  6. /**
  7. * The DepthOfFieldBlurPostProcess applied a blur in a give direction.
  8. * This blur differs from the standard BlurPostProcess as it attempts to avoid blurring pixels
  9. * based on samples that have a large difference in distance than the center pixel.
  10. * See section 2.6.2 http://fileadmin.cs.lth.se/cs/education/edan35/lectures/12dof.pdf
  11. */
  12. export class DepthOfFieldBlurPostProcess extends BlurPostProcess {
  13. /**
  14. * Gets a string identifying the name of the class
  15. * @returns "DepthOfFieldBlurPostProcess" string
  16. */
  17. getClassName() {
  18. return "DepthOfFieldBlurPostProcess";
  19. }
  20. /**
  21. * Creates a new instance DepthOfFieldBlurPostProcess
  22. * @param name The name of the effect.
  23. * @param scene The scene the effect belongs to.
  24. * @param direction The direction the blur should be applied.
  25. * @param kernel The size of the kernel used to blur.
  26. * @param options The required width/height ratio to downsize to before computing the render pass.
  27. * @param camera The camera to apply the render pass to.
  28. * @param circleOfConfusion The circle of confusion + depth map to be used to avoid blurring across edges
  29. * @param imageToBlur The image to apply the blur to (default: Current rendered frame)
  30. * @param samplingMode The sampling mode to be used when computing the pass. (default: 0)
  31. * @param engine The engine which the post process will be applied. (default: current engine)
  32. * @param reusable If the post process can be reused on the same frame. (default: false)
  33. * @param textureType Type of textures used when performing the post process. (default: 0)
  34. * @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)
  35. * @param textureFormat Format of textures used when performing the post process. (default: TEXTUREFORMAT_RGBA)
  36. */
  37. constructor(name, scene, direction, kernel, options, camera, circleOfConfusion, imageToBlur = null, samplingMode = Texture.BILINEAR_SAMPLINGMODE, engine, reusable, textureType = 0, blockCompilation = false, textureFormat = 5) {
  38. super(name, direction, kernel, options, camera,
  39. // eslint-disable-next-line @typescript-eslint/no-unused-vars
  40. (samplingMode = 2), engine, reusable, textureType, `#define DOF 1\n`, blockCompilation, textureFormat);
  41. this.direction = direction;
  42. this.externalTextureSamplerBinding = !!imageToBlur;
  43. this.onApplyObservable.add((effect) => {
  44. if (imageToBlur != null) {
  45. effect.setTextureFromPostProcess("textureSampler", imageToBlur);
  46. }
  47. effect.setTextureFromPostProcessOutput("circleOfConfusionSampler", circleOfConfusion);
  48. });
  49. }
  50. }
  51. __decorate([
  52. serialize()
  53. ], DepthOfFieldBlurPostProcess.prototype, "direction", void 0);
  54. RegisterClass("BABYLON.DepthOfFieldBlurPostProcess", DepthOfFieldBlurPostProcess);
  55. //# sourceMappingURL=depthOfFieldBlurPostProcess.js.map