depthOfFieldMergePostProcess.js 3.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. import { PostProcess } from "./postProcess.js";
  2. import "../Shaders/depthOfFieldMerge.fragment.js";
  3. /**
  4. * The DepthOfFieldMergePostProcess merges blurred images with the original based on the values of the circle of confusion.
  5. */
  6. export class DepthOfFieldMergePostProcess extends PostProcess {
  7. /**
  8. * Gets a string identifying the name of the class
  9. * @returns "DepthOfFieldMergePostProcess" string
  10. */
  11. getClassName() {
  12. return "DepthOfFieldMergePostProcess";
  13. }
  14. /**
  15. * Creates a new instance of DepthOfFieldMergePostProcess
  16. * @param name The name of the effect.
  17. * @param originalFromInput Post process which's input will be used for the merge.
  18. * @param circleOfConfusion Circle of confusion post process which's output will be used to blur each pixel.
  19. * @param _blurSteps Blur post processes from low to high which will be mixed with the original image.
  20. * @param options The required width/height ratio to downsize to before computing the render pass.
  21. * @param camera The camera to apply the render pass to.
  22. * @param samplingMode The sampling mode to be used when computing the pass. (default: 0)
  23. * @param engine The engine which the post process will be applied. (default: current engine)
  24. * @param reusable If the post process can be reused on the same frame. (default: false)
  25. * @param textureType Type of textures used when performing the post process. (default: 0)
  26. * @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)
  27. */
  28. constructor(name, originalFromInput, circleOfConfusion, _blurSteps, options, camera, samplingMode, engine, reusable, textureType = 0, blockCompilation = false) {
  29. super(name, "depthOfFieldMerge", [], ["circleOfConfusionSampler", "blurStep0", "blurStep1", "blurStep2"], options, camera, samplingMode, engine, reusable, null, textureType, undefined, null, true);
  30. this._blurSteps = _blurSteps;
  31. this.externalTextureSamplerBinding = true;
  32. this.onApplyObservable.add((effect) => {
  33. effect.setTextureFromPostProcess("textureSampler", originalFromInput);
  34. effect.setTextureFromPostProcessOutput("circleOfConfusionSampler", circleOfConfusion);
  35. _blurSteps.forEach((step, index) => {
  36. effect.setTextureFromPostProcessOutput("blurStep" + (_blurSteps.length - index - 1), step);
  37. });
  38. });
  39. if (!blockCompilation) {
  40. this.updateEffect();
  41. }
  42. }
  43. /**
  44. * Updates the effect with the current post process compile time values and recompiles the shader.
  45. * @param defines Define statements that should be added at the beginning of the shader. (default: null)
  46. * @param uniforms Set of uniform variables that will be passed to the shader. (default: null)
  47. * @param samplers Set of Texture2D variables that will be passed to the shader. (default: null)
  48. * @param indexParameters The index parameters to be used for babylons include syntax "#include<kernelBlurVaryingDeclaration>[0..varyingCount]". (default: undefined) See usage in babylon.blurPostProcess.ts and kernelBlur.vertex.fx
  49. * @param onCompiled Called when the shader has been compiled.
  50. * @param onError Called if there is an error when compiling a shader.
  51. */
  52. updateEffect(defines = null, uniforms = null, samplers = null, indexParameters, onCompiled, onError) {
  53. if (!defines) {
  54. defines = "";
  55. defines += "#define BLUR_LEVEL " + (this._blurSteps.length - 1) + "\n";
  56. }
  57. super.updateEffect(defines, uniforms, samplers, indexParameters, onCompiled, onError);
  58. }
  59. }
  60. //# sourceMappingURL=depthOfFieldMergePostProcess.js.map