babylon.grainPostProcess.ts 2.0 KB

12345678910111213141516171819202122232425262728293031323334
  1. module BABYLON {
  2. /**
  3. * The GrainPostProcess adds noise to the image at mid luminance levels
  4. */
  5. export class GrainPostProcess extends PostProcess {
  6. /**
  7. * The intensity of the grain added (default: 30)
  8. */
  9. public intensity:number = 30;
  10. /**
  11. * If the grain should be randomized on every frame
  12. */
  13. public animated:boolean = false;
  14. /**
  15. * Creates a new instance of @see GrainPostProcess
  16. * @param name The name of the effect.
  17. * @param options The required width/height ratio to downsize to before computing the render pass.
  18. * @param camera The camera to apply the render pass to.
  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, options: number | PostProcessOptions, camera: Nullable<Camera>, samplingMode?: number, engine?: Engine, reusable?: boolean, textureType: number = Engine.TEXTURETYPE_UNSIGNED_INT, blockCompilation = false) {
  26. super(name, "grain", ["intensity", "animatedSeed"], [], options, camera, samplingMode, engine, reusable, null, textureType, undefined, null, blockCompilation);
  27. this.onApplyObservable.add((effect: Effect) => {
  28. effect.setFloat('intensity', this.intensity);
  29. effect.setFloat('animatedSeed', this.animated ? Math.random() + 1 : 1);
  30. })
  31. }
  32. }
  33. }