Browse Source

added glow filter knockout

Nicolas Cannasse 10 years ago
parent
commit
5ac959435e
2 changed files with 25 additions and 14 deletions
  1. 5 1
      h2d/filter/Glow.hx
  2. 20 13
      samples/filters/Main.hx

+ 5 - 1
h2d/filter/Glow.hx

@@ -4,6 +4,7 @@ class Glow extends Blur {
 
 	public var color : Int;
 	public var alpha : Float;
+	public var knockout : Bool;
 
 	public function new( color : Int = 0xFFFFFF, alpha = 1., quality = 1, passes = 1, sigma = 1. ) {
 		super(quality, passes, sigma);
@@ -18,7 +19,10 @@ class Glow extends Blur {
 		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));
-		h3d.pass.Copy.run(save, t.getTexture(), Alpha);
+		if( knockout )
+			h3d.pass.Copy.run(save, t.getTexture(), Erase);
+		else
+			h3d.pass.Copy.run(save, t.getTexture(), Alpha);
 		return t;
 	}
 

+ 20 - 13
samples/filters/Main.hx

@@ -18,16 +18,15 @@ class Main extends hxd.App {
 
 
 		disp = hxd.Res.normalmap.toTile();
-
-		setFilters(4);
+		setFilters(6);
 
 		var help = new h2d.Text(hxd.Res.customFont.toFont(), s2d);
 		help.x = help.y = 5;
-		help.text = "1:Blur 2:Glow 3:DropShadow 4:Displacement +/-:Scale";
+		help.text = "1:Blur 2:Glow 3:DropShadow 4:Displacement 5:Glow(Knockout) 6:Mix +/-:Scale";
 	}
 
 	override function update(dt:Float) {
-		for( i in 1...5 )
+		for( i in 1...7 )
 			if( K.isPressed(K.NUMBER_0 + i) )
 				setFilters(i);
 		if( K.isPressed(K.NUMPAD_ADD) ) {
@@ -37,27 +36,35 @@ class Main extends hxd.App {
 		if( K.isPressed(K.NUMPAD_SUB) ) {
 			spr.scale(1 / 1.25);
 			bmp.scale(1.25);
+			if( spr.scaleX < 1 ) {
+				spr.setScale(1);
+				bmp.setScale(1);
+			}
 		}
 		bmp.x = -bmp.tile.width * 0.5 * bmp.scaleX;
 		bmp.y = -bmp.tile.height * 0.5 * bmp.scaleY;
-		disp.scrollDiscrete(0.01 * dt, 0.02 * dt);
+		disp.scrollDiscrete(0.02 * dt, 0.04 * dt);
 	}
 
 	function setFilters(i) {
-		var scale = 4;
 		switch( i ) {
 		case 1:
-			spr.filters = [new h2d.filter.Blur(2, 3, 100)];
+			spr.filters = [new h2d.filter.Blur(2, 1, 100)];
 		case 2:
-			spr.filters = [new h2d.filter.Glow(0xFF00FF, 100, 1)];
+			spr.filters = [new h2d.filter.Glow(0xFF00FF, 100, 2)];
 		case 3:
-			spr.filters = [new h2d.filter.DropShadow()];
+			spr.filters = [new h2d.filter.DropShadow(8,Math.PI/4,0,1,2,2)];
 		case 4:
-			scale = 1;
-			spr.filters = [new h2d.filter.Displacement(disp)];
+			spr.filters = [new h2d.filter.Displacement(disp,2.5,2.5)];
+		case 5:
+			var g = new h2d.filter.Glow(0xFF00FF, 100, 2);
+			g.knockout = true;
+			spr.filters = [g];
+		case 6:
+			var g = new h2d.filter.Glow(0xFFA500, 50, 2, 2);
+			g.knockout = true;
+			spr.filters = [g, new h2d.filter.Displacement(disp,3,3), new h2d.filter.Blur(3,2,0.8), new h2d.filter.DropShadow(8, Math.PI/4,0,1,3,3,0.5)];
 		}
-		spr.setScale(scale);
-		bmp.setScale(1 / scale);
 	}
 
 	static function main() {