babylon.depthOfFieldBlurPostProcess.ts 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  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 of @see 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 depthMap The 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. */
  24. constructor(name: string, scene: Scene, public direction: Vector2, kernel: number, options: number | PostProcessOptions, camera: Nullable<Camera>, depthMap:RenderTargetTexture, imageToBlur:Nullable<PostProcess> = null, samplingMode: number = Texture.BILINEAR_SAMPLINGMODE, engine?: Engine, reusable?: boolean, textureType: number = Engine.TEXTURETYPE_UNSIGNED_INT) {
  25. super(name, direction, kernel, options, camera, samplingMode = Texture.BILINEAR_SAMPLINGMODE, engine, reusable, textureType = Engine.TEXTURETYPE_UNSIGNED_INT);
  26. this._staticDefines += `#define DOF 1\r\n`;
  27. this.onApplyObservable.add((effect: Effect) => {
  28. // TODO: setTextureFromPostProcess seems to be setting the input texture instead of output of the post process passed in
  29. if(imageToBlur != null){
  30. effect.setTextureFromPostProcess("textureSampler", imageToBlur);
  31. }
  32. effect.setTexture("depthSampler", depthMap);
  33. if(scene.activeCamera){
  34. effect.setFloat2('cameraMinMaxZ', scene.activeCamera.minZ, scene.activeCamera.maxZ);
  35. }
  36. });
  37. }
  38. }
  39. }