Source: filters/alpha/AlphaFilter.js

filters/alpha/AlphaFilter.js

  1. import * as core from '../../core';
  2. import { readFileSync } from 'fs';
  3. import { join } from 'path';
  4. /**
  5. * Simplest filter - applies alpha
  6. *
  7. * Use this instead of Container's alpha property to avoid visual layering of individual elements.
  8. * AlphaFilter applies alpha evenly across the entire display object and any opaque elements it contains.
  9. * If elements are not opaque, they will blend with each other anyway.
  10. *
  11. * Very handy if you want to use common features of all filters:
  12. *
  13. * 1. Assign a blendMode to this filter, blend all elements inside display object with background.
  14. *
  15. * 2. To use clipping in display coordinates, assign a filterArea to the same container that has this filter.
  16. *
  17. * @class
  18. * @extends PIXI.Filter
  19. * @memberof PIXI.filters
  20. */
  21. export default class AlphaFilter extends core.Filter
  22. {
  23. /**
  24. * @param {number} [alpha=1] Amount of alpha from 0 to 1, where 0 is transparent
  25. */
  26. constructor(alpha = 1.0)
  27. {
  28. super(
  29. // vertex shader
  30. readFileSync(join(__dirname, '../fragments/default.vert'), 'utf8'),
  31. // fragment shader
  32. readFileSync(join(__dirname, './alpha.frag'), 'utf8')
  33. );
  34. this.alpha = alpha;
  35. this.glShaderKey = 'alpha';
  36. }
  37. /**
  38. * Coefficient for alpha multiplication
  39. *
  40. * @member {number}
  41. * @default 1
  42. */
  43. get alpha()
  44. {
  45. return this.uniforms.uAlpha;
  46. }
  47. set alpha(value) // eslint-disable-line require-jsdoc
  48. {
  49. this.uniforms.uAlpha = value;
  50. }
  51. }