You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

67 lines
1.7 KiB

  1. define([
  2. 'js/rendering/shaders/outline/vert',
  3. 'js/rendering/shaders/outline/frag'
  4. ], function (
  5. vertex,
  6. fragment
  7. ) {
  8. class OutlineFilter extends PIXI.Filter {
  9. constructor ({ thickness = 5, color = 0xFFFFFF, quality = 0.1, alpha = 1.0, knockout = false }) {
  10. const angleStep = Math.PI / 2;
  11. super(vertex, fragment.replace('$angleStep$', angleStep));
  12. this.uniforms.uThickness = new Float32Array([thickness, thickness]);
  13. this.uniforms.uColor = new Float32Array([1, 1, 1, 1]);
  14. this.uniforms.uAlpha = alpha;
  15. this.uniforms.uKnockout = knockout;
  16. const rgbColor = PIXI.utils.hex2rgb(color);
  17. this.uniforms.uColor = PIXI.utils.hex2rgb(rgbColor, this.uniforms.uColor);
  18. Object.assign(this, { thickness, color, quality, alpha, knockout });
  19. }
  20. apply (filterManager, input, output, clear) {
  21. this.uniforms.uThickness[0] = this.thickness / input._frame.width;
  22. this.uniforms.uThickness[1] = this.thickness / input._frame.height;
  23. this.uniforms.uAlpha = this.alpha;
  24. this.uniforms.uKnockout = this.knockout;
  25. this.uniforms.uColor = PIXI.utils.hex2rgb(this.color, this.uniforms.uColor);
  26. filterManager.applyFilter(this, input, output, clear);
  27. }
  28. get alpha () {
  29. return this._alpha;
  30. }
  31. set alpha (value) {
  32. this._alpha = value;
  33. }
  34. get color () {
  35. return PIXI.utils.rgb2hex(this.uniforms.uColor);
  36. }
  37. set color (value) {
  38. PIXI.utils.hex2rgb(value, this.uniforms.uColor);
  39. }
  40. get knockout () {
  41. return this._knockout;
  42. }
  43. set knockout (value) {
  44. this._knockout = value;
  45. }
  46. get thickness () {
  47. return this._thickness;
  48. }
  49. set thickness (value) {
  50. this._thickness = value;
  51. this.padding = value;
  52. }
  53. }
  54. return OutlineFilter;
  55. });