Glow.hx 966 B

123456789101112131415161718192021222324252627282930313233343536
  1. package h2d.filter;
  2. class Glow extends Blur {
  3. public var color : Int;
  4. public var alpha : Float;
  5. public var knockout : Bool;
  6. public var smoothColor : Bool;
  7. public function new( color : Int = 0xFFFFFF, alpha = 1., radius = 1., gain = 1., quality = 1., smoothColor = false ) {
  8. super(radius, gain, quality);
  9. this.color = color;
  10. this.alpha = alpha;
  11. this.smoothColor = smoothColor;
  12. pass.shader.hasFixedColor = true;
  13. }
  14. function setParams() {
  15. pass.shader.fixedColor.setColor(color);
  16. pass.shader.fixedColor.w = alpha;
  17. pass.shader.smoothFixedColor = smoothColor;
  18. }
  19. override function draw( ctx : RenderContext, t : h2d.Tile ) {
  20. setParams();
  21. var save = ctx.textures.allocTarget("glowSave", t.width, t.height, false);
  22. h3d.pass.Copy.run(t.getTexture(), save, None);
  23. pass.apply(ctx, t.getTexture());
  24. if( knockout )
  25. h3d.pass.Copy.run(save, t.getTexture(), Erase);
  26. else
  27. h3d.pass.Copy.run(save, t.getTexture(), Alpha);
  28. return t;
  29. }
  30. }