Nicolas Cannasse пре 11 година
родитељ
комит
76db6c88f1
1 измењених фајлова са 46 додато и 0 уклоњено
  1. 46 0
      h3d/pass/Copy.hx

+ 46 - 0
h3d/pass/Copy.hx

@@ -0,0 +1,46 @@
+package h3d.pass;
+
+private class CopyShader extends hxsl.Shader {
+
+	static var SRC = {
+		@input var input : {
+			position : Vec2,
+			uv : Vec2,
+		};
+		var output : {
+			position : Vec4,
+			color : Vec4,
+		};
+
+		@param var texture : Sampler2D;
+
+		function vertex() {
+			output.position = vec4(input.position, 0, 1);
+		}
+		function fragment() {
+			output.color = texture.get(input.uv);
+		}
+	}
+}
+
+class Copy extends ScreenFx<CopyShader> {
+
+	public function new() {
+		super(new CopyShader());
+	}
+
+	public function apply( from, to ) {
+		engine.setTarget(to);
+		shader.texture = from;
+		render();
+		shader.texture = null;
+		engine.setTarget(null);
+	}
+
+	static var inst : Copy;
+	public static function run( from : h3d.mat.Texture, to : h3d.mat.Texture ) {
+		if( inst == null ) inst = new Copy();
+		return inst.apply(from, to);
+	}
+
+}