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.
 
 
 

66 lines
1.4 KiB

  1. define([
  2. 'pixi',
  3. 'js/rendering/shaders/outline/vert',
  4. 'js/rendering/shaders/outline/frag'
  5. ], function (
  6. pixi,
  7. vert,
  8. frag
  9. ) {
  10. let OutlineFilter = function (viewWidth, viewHeight, thickness, color) {
  11. thickness = thickness || 1;
  12. pixi.Filter.call(this,
  13. vert,
  14. frag.replace(/%THICKNESS%/gi, (1.0 / thickness).toFixed(7))
  15. );
  16. this.uniforms.pixelWidth = 0.002;//1.0 / (viewWidth || 1);
  17. this.uniforms.pixelHeight = 1.0 / (viewHeight || 1);
  18. this.uniforms.thickness = thickness;
  19. this.uniforms.outlineColor = new Float32Array([0, 0, 0, 1]);
  20. this.alpha = 0;
  21. if (color)
  22. this.color = color;
  23. };
  24. OutlineFilter.prototype = Object.create(pixi.Filter.prototype);
  25. OutlineFilter.prototype.constructor = OutlineFilter;
  26. Object.defineProperties(OutlineFilter.prototype, {
  27. color: {
  28. get: function () {
  29. return pixi.utils.rgb2hex(this.uniforms.outlineColor);
  30. },
  31. set: function (value) {
  32. pixi.utils.hex2rgb(value, this.uniforms.outlineColor);
  33. }
  34. },
  35. alpha: {
  36. set: function (value) {
  37. this.uniforms.alpha = value;
  38. }
  39. },
  40. viewWidth: {
  41. get: function () {
  42. return 1 / this.uniforms.pixelWidth;
  43. },
  44. set: function (value) {
  45. this.uniforms.pixelWidth = 1 / value;
  46. }
  47. },
  48. viewHeight: {
  49. get: function () {
  50. return 1 / this.uniforms.pixelHeight;
  51. },
  52. set: function (value) {
  53. this.uniforms.pixelHeight = 1 / value;
  54. }
  55. }
  56. });
  57. return OutlineFilter;
  58. });