Bläddra i källkod

Adding Blur node to tex graph. Adding ctx to tex node.

clementlandrin 1 år sedan
förälder
incheckning
95c57e1300
3 ändrade filer med 58 tillägg och 2 borttagningar
  1. 12 1
      hrt/texgraph/TexNode.hx
  2. 45 0
      hrt/texgraph/nodes/Blur.hx
  3. 1 1
      hrt/texgraph/nodes/WhiteNoise.hx

+ 12 - 1
hrt/texgraph/TexNode.hx

@@ -38,6 +38,16 @@ implements hide.view.GraphInterface.IGraphNode
 	public var outputFormat = hxd.PixelFormat.RGBA;
 
 
+	var ctx(get, null) : h3d.impl.RenderContext;
+	function get_ctx() {
+		#if editor
+		var s2d = editor.previewsScene.s2d;
+		return @:privateAccess s2d.ctx;
+		#else
+		return null;
+		#end
+	}
+
 	static public function register(key : String, cl : Class<TexNode>) : Bool {
 		registeredNodes.set(key, cl);
 		return true;
@@ -211,7 +221,8 @@ implements hide.view.GraphInterface.IGraphNode
 	}
 
 	function createTexture() : h3d.mat.Texture {
-		var tex = new h3d.mat.Texture(outputWidth, outputHeight, null, outputFormat);
+		var tex = new h3d.mat.Texture(outputWidth, outputHeight, [Target], outputFormat);
+		tex.clear(0);
 		return tex;
 	}
 }

+ 45 - 0
hrt/texgraph/nodes/Blur.hx

@@ -0,0 +1,45 @@
+package hrt.texgraph.nodes;
+
+@name("Blur")
+@description("Blur texture")
+@width(100)
+@group("Operation")
+class Blur extends TexNode {
+	var inputs = [
+		{ name : "input1", type: h3d.mat.Texture }
+	];
+	var outputs = [
+		{ name : "output", type: h3d.mat.Texture }
+	];
+
+	@prop var radius : Float = 10;
+
+	override function apply(vars : Dynamic) : Array<h3d.mat.Texture> {
+		var out = createTexture();
+
+		var blurPass = new h3d.pass.Blur(radius);
+		blurPass.apply(ctx, cast getInputData(vars, 0), out);
+
+		return [ out ];
+	}
+
+	#if editor
+	override function getSpecificParametersHTML() {
+		var el = new hide.Element('
+		<div class="fields">
+			<label>Radius</label>
+			<input type="range" id="radius"/>
+		</div>');
+
+		var radiusEl = el.find("#radius");
+		radiusEl.val(radius);
+		radiusEl.on("mousemove", function(e) {
+			this.radius = Std.parseFloat(radiusEl.val());
+			var substanceEditor = Std.downcast(editor.editor, hide.view.textureeditor.TextureEditor);
+			substanceEditor.generate();
+		});
+
+		return el;
+	}
+	#end
+}

+ 1 - 1
hrt/texgraph/nodes/WhiteNoise.hx

@@ -30,7 +30,7 @@ class WhiteNoise extends TexNode {
 
 	override function apply(vars : Dynamic) : Array<h3d.mat.Texture> {
 		var engine = h3d.Engine.getCurrent();
-		var out = new h3d.mat.Texture(outputWidth, outputHeight, null, outputFormat);
+		var out = createTexture();
 
 		var shader = new WhiteNoiseShader();
 		shader.tex = out;