blurPostProcess.d.ts 5.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. import type { Vector2 } from "../Maths/math.vector";
  2. import type { Nullable } from "../types";
  3. import type { PostProcessOptions } from "./postProcess";
  4. import { PostProcess } from "./postProcess";
  5. import type { Camera } from "../Cameras/camera";
  6. import type { Effect } from "../Materials/effect";
  7. import "../Shaders/kernelBlur.fragment";
  8. import "../Shaders/kernelBlur.vertex";
  9. import type { Scene } from "../scene";
  10. import type { AbstractEngine } from "../Engines/abstractEngine.js";
  11. /**
  12. * The Blur Post Process which blurs an image based on a kernel and direction.
  13. * Can be used twice in x and y directions to perform a gaussian blur in two passes.
  14. */
  15. export declare class BlurPostProcess extends PostProcess {
  16. private _blockCompilation;
  17. protected _kernel: number;
  18. protected _idealKernel: number;
  19. protected _packedFloat: boolean;
  20. private _staticDefines;
  21. /** The direction in which to blur the image. */
  22. direction: Vector2;
  23. /**
  24. * Sets the length in pixels of the blur sample region
  25. */
  26. set kernel(v: number);
  27. /**
  28. * Gets the length in pixels of the blur sample region
  29. */
  30. get kernel(): number;
  31. /**
  32. * Sets whether or not the blur needs to unpack/repack floats
  33. */
  34. set packedFloat(v: boolean);
  35. /**
  36. * Gets whether or not the blur is unpacking/repacking floats
  37. */
  38. get packedFloat(): boolean;
  39. /**
  40. * Gets a string identifying the name of the class
  41. * @returns "BlurPostProcess" string
  42. */
  43. getClassName(): string;
  44. /**
  45. * Creates a new instance BlurPostProcess
  46. * @param name The name of the effect.
  47. * @param direction The direction in which to blur the image.
  48. * @param kernel The size of the kernel to be used when computing the blur. eg. Size of 3 will blur the center pixel by 2 pixels surrounding it.
  49. * @param options The required width/height ratio to downsize to before computing the render pass. (Use 1.0 for full size)
  50. * @param camera The camera to apply the render pass to.
  51. * @param samplingMode The sampling mode to be used when computing the pass. (default: 0)
  52. * @param engine The engine which the post process will be applied. (default: current engine)
  53. * @param reusable If the post process can be reused on the same frame. (default: false)
  54. * @param textureType Type of textures used when performing the post process. (default: 0)
  55. * @param defines
  56. * @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)
  57. * @param textureFormat Format of textures used when performing the post process. (default: TEXTUREFORMAT_RGBA)
  58. */
  59. constructor(name: string, direction: Vector2, kernel: number, options: number | PostProcessOptions, camera: Nullable<Camera>, samplingMode?: number, engine?: AbstractEngine, reusable?: boolean, textureType?: number, defines?: string, _blockCompilation?: boolean, textureFormat?: number);
  60. /**
  61. * Updates the effect with the current post process compile time values and recompiles the shader.
  62. * @param defines Define statements that should be added at the beginning of the shader. (default: null)
  63. * @param uniforms Set of uniform variables that will be passed to the shader. (default: null)
  64. * @param samplers Set of Texture2D variables that will be passed to the shader. (default: null)
  65. * @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
  66. * @param onCompiled Called when the shader has been compiled.
  67. * @param onError Called if there is an error when compiling a shader.
  68. */
  69. updateEffect(defines?: Nullable<string>, uniforms?: Nullable<string[]>, samplers?: Nullable<string[]>, indexParameters?: any, onCompiled?: (effect: Effect) => void, onError?: (effect: Effect, errors: string) => void): void;
  70. protected _updateParameters(onCompiled?: (effect: Effect) => void, onError?: (effect: Effect, errors: string) => void): void;
  71. /**
  72. * Best kernels are odd numbers that when divided by 2, their integer part is even, so 5, 9 or 13.
  73. * Other odd kernels optimize correctly but require proportionally more samples, even kernels are
  74. * possible but will produce minor visual artifacts. Since each new kernel requires a new shader we
  75. * want to minimize kernel changes, having gaps between physical kernels is helpful in that regard.
  76. * The gaps between physical kernels are compensated for in the weighting of the samples
  77. * @param idealKernel Ideal blur kernel.
  78. * @returns Nearest best kernel.
  79. */
  80. protected _nearestBestKernel(idealKernel: number): number;
  81. /**
  82. * Calculates the value of a Gaussian distribution with sigma 3 at a given point.
  83. * @param x The point on the Gaussian distribution to sample.
  84. * @returns the value of the Gaussian function at x.
  85. */
  86. protected _gaussianWeight(x: number): number;
  87. /**
  88. * Generates a string that can be used as a floating point number in GLSL.
  89. * @param x Value to print.
  90. * @param decimalFigures Number of decimal places to print the number to (excluding trailing 0s).
  91. * @returns GLSL float string.
  92. */
  93. protected _glslFloat(x: number, decimalFigures?: number): string;
  94. /**
  95. * @internal
  96. */
  97. static _Parse(parsedPostProcess: any, targetCamera: Camera, scene: Scene, rootUrl: string): Nullable<BlurPostProcess>;
  98. }