فهرست منبع

fixed Glow : no alpha smooth by default

ncannasse 10 سال پیش
والد
کامیت
243e28fa3e
2فایلهای تغییر یافته به همراه9 افزوده شده و 2 حذف شده
  1. 4 1
      h2d/filter/Glow.hx
  2. 5 1
      h3d/shader/Blur.hx

+ 4 - 1
h2d/filter/Glow.hx

@@ -5,17 +5,20 @@ class Glow extends Blur {
 	public var color : Int;
 	public var alpha : Float;
 	public var knockout : Bool;
+	public var smooth : Bool;
 
-	public function new( color : Int = 0xFFFFFF, alpha = 1., quality = 1, passes = 1, sigma = 1. ) {
+	public function new( color : Int = 0xFFFFFF, alpha = 1., quality = 1, passes = 1, sigma = 1., smooth = false ) {
 		super(quality, passes, sigma);
 		this.color = color;
 		this.alpha = alpha;
+		this.smooth = smooth;
 		pass.shader.hasFixedColor = true;
 	}
 
 	override function draw( ctx : RenderContext, t : h2d.Tile ) {
 		pass.shader.fixedColor.setColor(color);
 		pass.shader.fixedColor.w = alpha;
+		pass.shader.smoothFixedColor = smooth;
 		var save = ctx.textures.allocTarget("glowSave", ctx, t.width, t.height, false);
 		h3d.pass.Copy.run(t.getTexture(), save, None);
 		pass.apply(t.getTexture(), ctx.textures.allocTarget("glowTmp", ctx, t.width, t.height, false));

+ 5 - 1
h3d/shader/Blur.hx

@@ -11,6 +11,7 @@ class Blur extends ScreenShader {
 		@param var pixel : Vec2;
 
 		@const var hasFixedColor : Bool;
+		@const var smoothFixedColor : Bool;
 		@param var fixedColor : Vec4;
 
 		function fragment() {
@@ -27,7 +28,10 @@ class Blur extends ScreenShader {
 			}
 			if( hasFixedColor ) {
 				output.color.rgb = fixedColor.rgb;
-				output.color.a *= fixedColor.a;
+				if( smoothFixedColor )
+					output.color.a *= fixedColor.a;
+				else
+					output.color.a = fixedColor.a * float(output.color.a > 0);
 			}
 		}
 	}