babylon.chromaticAberrationPostProcess.ts 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. module BABYLON {
  2. /**
  3. * The ChromaticAberrationPostProcess separates the rgb channels in an image to produce chromatic distortion around the edges of the screen
  4. */
  5. export class ChromaticAberrationPostProcess extends PostProcess {
  6. /**
  7. * The amount of seperation of rgb channels (default: 30)
  8. */
  9. aberrationAmount = 30;
  10. /**
  11. * The amount the effect will increase for pixels closer to the edge of the screen. (default: 0)
  12. */
  13. radialIntensity = 0;
  14. /**
  15. * The normilized direction in which the rgb channels should be seperated. If set to 0,0 radial direction will be used. (default: Vector2(0.707,0.707))
  16. */
  17. direction = new Vector2(0.707,0.707);
  18. /**
  19. * The center position where the radialIntensity should be around. [0.5,0.5 is center of screen, 1,1 is top right corder] (default: Vector2(0.5 ,0.5))
  20. */
  21. centerPosition = new Vector2(0.5,0.5);
  22. /**
  23. * Creates a new instance ChromaticAberrationPostProcess
  24. * @param name The name of the effect.
  25. * @param screenWidth The width of the screen to apply the effect on.
  26. * @param screenHeight The height of the screen to apply the effect on.
  27. * @param options The required width/height ratio to downsize to before computing the render pass.
  28. * @param camera The camera to apply the render pass to.
  29. * @param samplingMode The sampling mode to be used when computing the pass. (default: 0)
  30. * @param engine The engine which the post process will be applied. (default: current engine)
  31. * @param reusable If the post process can be reused on the same frame. (default: false)
  32. * @param textureType Type of textures used when performing the post process. (default: 0)
  33. * @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)
  34. */
  35. constructor(name: string, screenWidth:number, screenHeight:number, options: number | PostProcessOptions, camera: Nullable<Camera>, samplingMode?: number, engine?: Engine, reusable?: boolean, textureType: number = Engine.TEXTURETYPE_UNSIGNED_INT, blockCompilation = false) {
  36. super(name, "chromaticAberration", ["chromatic_aberration", "screen_width", "screen_height", "direction", "radialIntensity", "centerPosition"], [], options, camera, samplingMode, engine, reusable, null, textureType, undefined, null, blockCompilation);
  37. this.onApplyObservable.add((effect: Effect) => {
  38. effect.setFloat('chromatic_aberration', this.aberrationAmount);
  39. effect.setFloat('screen_width', screenWidth);
  40. effect.setFloat('screen_height', screenHeight);
  41. effect.setFloat('radialIntensity', this.radialIntensity);
  42. effect.setFloat2('direction', this.direction.x,this.direction.y);
  43. effect.setFloat2('centerPosition', this.centerPosition.x,this.centerPosition.y);
  44. })
  45. }
  46. }
  47. }