浏览代码

added outline 2d alpha

Nicolas Cannasse 5 年之前
父节点
当前提交
286bffca52
共有 4 个文件被更改,包括 16 次插入31 次删除
  1. 3 1
      h2d/domkit/BaseComponents.hx
  2. 5 1
      h2d/filter/Outline.hx
  3. 7 28
      h3d/pass/Outline.hx
  4. 1 1
      h3d/shader/Outline2D.hx

+ 3 - 1
h2d/domkit/BaseComponents.hx

@@ -256,7 +256,9 @@ class CustomParser extends CssValue.ValueParser {
 			#if macro
 				true;
 			#else
-				new h2d.filter.Outline(s, c);
+				var f = new h2d.filter.Outline(s, c);
+				f.alpha = (c >>> 24) / 255;
+				f;
 			#end
 		case VCall("brightness",[v]):
 			var v = parseFloatPercent(v);

+ 5 - 1
h2d/filter/Outline.hx

@@ -5,15 +5,19 @@ class Outline extends Filter {
 	public var color(get, set) : Int;
 	public var quality(get, set) : Float;
 	public var multiplyAlpha(get, set) : Bool;
+	public var alpha(get, set) : Float;
 
 	var pass : h3d.pass.Outline;
 
-	public function new(size = 4.0, color = 0xFF000000, quality = 0.3, multiplyAlpha = true) {
+	public function new(size = 4.0, color = 0x000000, quality = 0.3, multiplyAlpha = true) {
 		super();
 		smooth = true;
 		pass = new h3d.pass.Outline(size, color, quality, multiplyAlpha);
 	}
 
+	inline function get_alpha() return pass.alpha;
+	inline function set_alpha(v) return pass.alpha = v;
+
 	inline function get_size() return pass.size;
 
 	inline function set_size(v) return pass.size = v;

+ 7 - 28
h3d/pass/Outline.hx

@@ -2,12 +2,13 @@ package h3d.pass;
 
 @ignore("shader")
 class Outline extends ScreenFx<h3d.shader.Outline2D> {
-	public var size(default, set) : Float;
-	public var color(default, set) : Int;
-	public var quality(default, set) : Float;
-	public var multiplyAlpha(default, set) : Bool;
+	public var size : Float;
+	public var color : Int;
+	public var alpha : Float = 1.;
+	public var quality : Float;
+	public var multiplyAlpha : Bool;
 
-	public function new(size = 4.0, color = 0xFF000000, quality = 0.3, multiplyAlpha = true) {
+	public function new(size = 4.0, color = 0x000000, quality = 0.3, multiplyAlpha = true) {
 		super(new h3d.shader.Outline2D());
 		this.size = size;
 		this.color = color;
@@ -20,6 +21,7 @@ class Outline extends ScreenFx<h3d.shader.Outline2D> {
 			output = src;
 		var tmp = ctx.textures.allocTarget(src.name + "OutlineTmp", src.width, src.height, false, src.format);
 		shader.color.setColor(color);
+		shader.color.a = alpha;
 		shader.size.set(size / src.width, size / src.height);
 		shader.samples = Std.int(Math.max(quality * 100, 1));
 		shader.multiplyAlpha = multiplyAlpha ? 0 : 1;
@@ -38,27 +40,4 @@ class Outline extends ScreenFx<h3d.shader.Outline2D> {
 		output.depthBuffer = outDepth;
 	}
 
-	function set_size(s) {
-		if (size == s)
-			return s;
-		return size = s;
-	}
-
-	function set_color(c) {
-		if (color == c)
-			return c;
-		return color = c;
-	}
-
-	function set_quality(q) {
-		if (quality == q)
-			return q;
-		return quality = q;
-	}
-
-	function set_multiplyAlpha(m) {
-		if (multiplyAlpha == m)
-			return m;
-		return multiplyAlpha = m;
-	}
 }

+ 1 - 1
h3d/shader/Outline2D.hx

@@ -25,7 +25,7 @@ class Outline2D extends ScreenShader {
 			var resultAlpha = max(maxAlpha, ownColor.a);
 			var resultColor = ownColor.rgb + color.rgb * (1. - ownColor.a);
 			var out = resultColor * max(float(multiplyAlpha), resultAlpha);
-			output.color = vec4(out, resultAlpha);
+			output.color = vec4(out, resultAlpha * mix(color.a, 1, ownColor.a));
 		}
 	};
 }