babylon.depthOfFieldBlurPostProcess.ts 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. module BABYLON {
  2. /**
  3. * The DepthOfFieldBlurPostProcess applied a blur in a give direction.
  4. * This blur differs from the standard BlurPostProcess as it attempts to avoid blurring pixels
  5. * based on samples that have a large difference in distance than the center pixel.
  6. * See section 2.6.2 http://fileadmin.cs.lth.se/cs/education/edan35/lectures/12dof.pdf
  7. */
  8. export class DepthOfFieldBlurPostProcess extends BlurPostProcess {
  9. /**
  10. * Creates a new instance CircleOfConfusionPostProcess
  11. * @param name The name of the effect.
  12. * @param scene The scene the effect belongs to.
  13. * @param direction The direction the blur should be applied.
  14. * @param kernel The size of the kernel used to blur.
  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 circleOfConfusion The circle of confusion + depth map to be used to avoid blurring accross edges
  18. * @param imageToBlur The image to apply the blur to (default: Current rendered frame)
  19. * @param samplingMode The sampling mode to be used when computing the pass. (default: 0)
  20. * @param engine The engine which the post process will be applied. (default: current engine)
  21. * @param reusable If the post process can be reused on the same frame. (default: false)
  22. * @param textureType Type of textures used when performing the post process. (default: 0)
  23. * @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)
  24. */
  25. constructor(name: string, scene: Scene, public direction: Vector2, kernel: number, options: number | PostProcessOptions, camera: Nullable<Camera>, circleOfConfusion:PostProcess, imageToBlur:Nullable<PostProcess> = null, samplingMode: number = Texture.BILINEAR_SAMPLINGMODE, engine?: Engine, reusable?: boolean, textureType: number = Engine.TEXTURETYPE_UNSIGNED_INT, blockCompilation = false) {
  26. super(name, direction, kernel, options, camera, samplingMode = Texture.BILINEAR_SAMPLINGMODE, engine, reusable, textureType = Engine.TEXTURETYPE_UNSIGNED_INT, `#define DOF 1\r\n`, blockCompilation);
  27. this.onApplyObservable.add((effect: Effect) => {
  28. if(imageToBlur != null){
  29. effect.setTextureFromPostProcess("textureSampler", imageToBlur);
  30. }
  31. effect.setTextureFromPostProcessOutput("circleOfConfusionSampler", circleOfConfusion);
  32. if(scene.activeCamera){
  33. effect.setFloat2('cameraMinMaxZ', scene.activeCamera.minZ, scene.activeCamera.maxZ);
  34. }
  35. });
  36. }
  37. }
  38. }