Outline.hx 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. package h3d.pass;
  2. @ignore("shader")
  3. class Outline extends ScreenFx<h3d.shader.Outline2D> {
  4. public var size : Float;
  5. public var color : Int;
  6. public var alpha : Float = 1.;
  7. public var quality : Float;
  8. public var multiplyAlpha : Bool;
  9. public function new(size = 4.0, color = 0x000000, quality = 0.3, multiplyAlpha = true) {
  10. super(new h3d.shader.Outline2D());
  11. this.size = size;
  12. this.color = color;
  13. this.quality = quality;
  14. this.multiplyAlpha = multiplyAlpha;
  15. }
  16. public function apply(ctx : h3d.impl.RenderContext, src : h3d.mat.Texture, ?output : h3d.mat.Texture) {
  17. if (output == null)
  18. output = src;
  19. var tmp = ctx.textures.allocTarget(src.name + "OutlineTmp", src.width, src.height, false, src.format);
  20. shader.color.setColor(color);
  21. shader.color.a = alpha;
  22. shader.size.set(size / src.width, size / src.height);
  23. shader.samples = Std.int(Math.max(quality * 100, 1));
  24. shader.multiplyAlpha = multiplyAlpha ? 0 : 1;
  25. shader.texture = src;
  26. engine.pushTarget(tmp);
  27. render();
  28. engine.popTarget();
  29. shader.texture = tmp;
  30. var outDepth = output.depthBuffer;
  31. output.depthBuffer = null;
  32. engine.pushTarget(output);
  33. render();
  34. engine.popTarget();
  35. output.depthBuffer = outDepth;
  36. }
  37. }