Explorar o código

added colorKey

ncannasse %!s(int64=12) %!d(string=hai) anos
pai
achega
e738121a26
Modificáronse 1 ficheiros con 15 adicións e 1 borrados
  1. 15 1
      h2d/Drawable.hx

+ 15 - 1
h2d/Drawable.hx

@@ -57,9 +57,12 @@ private class DrawableShader extends h3d.impl.Shader {
 		var multMapFactor : Float;
 		var multMap : Texture;
 		var multUV : Float4;
+		var hasColorKey : Bool;
+		var colorKey : Int;
 
 		function fragment( tex : Texture ) {
-			var col = tex.get(sinusDeform != null ? [tuv.x + sin(tuv.y*sinusDeform.y + sinusDeform.x) * sinusDeform.z, tuv.y] : tuv, filter = ! !filter, wrap=tileWrap);
+			var col = tex.get(sinusDeform != null ? [tuv.x + sin(tuv.y * sinusDeform.y + sinusDeform.x) * sinusDeform.z, tuv.y] : tuv, filter = ! !filter, wrap = tileWrap);
+			if( hasColorKey ) kill(abs(col.rgb - colorKey.rgb).length() - 0.001);
 			if( killAlpha ) kill(col.a - 0.001);
 			if( hasVertexAlpha ) col.a *= talpha;
 			if( hasVertexColor ) col *= tcolor;
@@ -148,6 +151,8 @@ class Drawable extends Sprite {
 	public var multiplyMap(default, set) : h2d.Tile;
 	public var multiplyFactor(get, set) : Float;
 	
+	public var colorKey(get, set) : Int;
+	
 	public var writeAlpha : Bool;
 	
 	function new(parent) {
@@ -257,6 +262,15 @@ class Drawable extends Sprite {
 	inline function set_killAlpha(v) {
 		return shader.killAlpha = v;
 	}
+
+	inline function get_colorKey() {
+		return shader.colorKey;
+	}
+	
+	inline function set_colorKey(v) {
+		shader.hasColorKey = true;
+		return shader.colorKey = v;
+	}
 	
 	function drawTile( engine, tile ) {
 		setupShader(engine, tile, HAS_SIZE | HAS_UV_POS | HAS_UV_SCALE);