Home Reference Source

src/effects/NoiseEffect.js

  1. import { BlendFunction } from "../enums/index.js";
  2. import { Effect } from "./Effect.js";
  3.  
  4. import fragmentShader from "./glsl/noise.frag";
  5.  
  6. /**
  7. * A noise effect.
  8. */
  9.  
  10. export class NoiseEffect extends Effect {
  11.  
  12. /**
  13. * Constructs a new noise effect.
  14. *
  15. * @param {Object} [options] - The options.
  16. * @param {BlendFunction} [options.blendFunction=BlendFunction.SCREEN] - The blend function of this effect.
  17. * @param {Boolean} [options.premultiply=false] - Whether the noise should be multiplied with the input colors prior to blending.
  18. */
  19.  
  20. constructor({ blendFunction = BlendFunction.SCREEN, premultiply = false } = {}) {
  21.  
  22. super("NoiseEffect", fragmentShader, { blendFunction });
  23. this.premultiply = premultiply;
  24.  
  25. }
  26.  
  27. /**
  28. * Indicates whether noise will be multiplied with the input colors prior to blending.
  29. *
  30. * @type {Boolean}
  31. */
  32.  
  33. get premultiply() {
  34.  
  35. return this.defines.has("PREMULTIPLY");
  36.  
  37. }
  38.  
  39. set premultiply(value) {
  40.  
  41. if(this.premultiply !== value) {
  42.  
  43. if(value) {
  44.  
  45. this.defines.set("PREMULTIPLY", "1");
  46.  
  47. } else {
  48.  
  49. this.defines.delete("PREMULTIPLY");
  50.  
  51. }
  52.  
  53. this.setChanged();
  54.  
  55. }
  56.  
  57. }
  58.  
  59. /**
  60. * Indicates whether noise will be multiplied with the input colors prior to blending.
  61. *
  62. * @deprecated Use premultiply instead.
  63. * @return {Boolean} Whether noise is premultiplied.
  64. */
  65.  
  66. isPremultiplied() {
  67.  
  68. return this.premultiply;
  69.  
  70. }
  71.  
  72. /**
  73. * Controls whether noise should be multiplied with the input colors prior to blending.
  74. *
  75. * @deprecated Use premultiply instead.
  76. * @param {Boolean} value - Whether noise should be premultiplied.
  77. */
  78.  
  79. setPremultiplied(value) {
  80.  
  81. this.premultiply = value;
  82.  
  83. }
  84.  
  85. }