Ver Fonte

Full compilation path working

Clement Espeute há 2 anos atrás
pai
commit
feb02b2842

+ 40 - 19
hrt/shgraph/ShaderGraph.hx

@@ -179,7 +179,7 @@ class ShaderGraph {
 		if (prevConn != null)
 			connections.remove(prevConn);
 
-		node.instance.inputs2.set(edge.nameInput, connection);
+		node.instance.inputs2.set(toName, connection);
 
 		var subShaderIn = Std.downcast(node.instance, hrt.shgraph.nodes.SubGraph);
 		var subShaderOut = Std.downcast(output.instance, hrt.shgraph.nodes.SubGraph);
@@ -222,6 +222,11 @@ class ShaderGraph {
 		var node = this.nodes.get(idNode);
 		this.nodes.get(node.instance.getInput(nameInput).node.id).outputs.remove(node);
 		node.instance.setInput(nameInput, null);
+
+		var toGen = node.instance.getShaderDef();
+		var toName = toGen.inVars[node.instance.getInputInfoKeys().indexOf(nameInput)].name;
+
+		node.instance.inputs2.remove(toName);
 		if (update) {
 			updateOutputs(node);
 		}
@@ -419,15 +424,7 @@ class ShaderGraph {
 
 			var outputs = getOutputs(currentNode);
 
-			var inputVars : Map<String, TVar> = [];
-			for (input in currentNode.instance.inputs2) {
-				if (input.to != currentNode) throw "node connection missmatch";
-				var outputs = getOutputs(input.from);
-				var outputVar = outputs[input.fromName];
-				if (outputVar == null) throw "null tvar";
 
-				inputVars.set(input.toName, outputVar);
-			}
 
 			/*if (Std.downcast(currentNode.instance, ShaderOutput) != null) {
 				var outputNode : ShaderOutput = cast currentNode.instance;
@@ -484,26 +481,50 @@ class ShaderGraph {
 			}*/
 			/*else*/
 			{
-				var def = currentNode.instance.getShaderDef();
+				var def = currentNode.instance.getShaderDef(getNewVarId);
 				var expr = def.expr;
 
+				/*var inputVars : Map<String, TVar> = [];
+
+				for (input in currentNode.instance.inputs2) {
+					if (input.to != currentNode) throw "node connection missmatch";
+					var outputs = getOutputs(input.from);
+					var outputVar = outputs[input.fromName];
+					if (outputVar == null) throw "null tvar";
+
+					inputVars.set(input.toName, outputVar);
+				}*/
+
 				var outputDecls : Array<TVar> = [];
 				for (nodeVar in def.externVars) {
 					if (nodeVar.qualifiers != null) {
 						if (nodeVar.qualifiers.has(SgInput)) {
-							var ourInputVar = inputVars.get(nodeVar.name);
+							var connection = currentNode.instance.inputs2.get(nodeVar.name);
+
 							var replacement : TExpr = null;
-							if (ourInputVar != null) {
-								replacement = convertToType(nodeVar.type,  {e: TVar(ourInputVar), p:pos, t: ourInputVar.type});
+
+							if (connection != null) {
+								var outputs = getOutputs(connection.from);
+								var outputVar = outputs[connection.fromName];
+								if (outputVar == null) throw "null tvar";
+								replacement = convertToType(nodeVar.type,  {e: TVar(outputVar), p:pos, t: outputVar.type});
 							}
 							else {
-								var id = getNewVarId();
-								var outVar = {id: id, name: nodeVar.name, type: nodeVar.type, kind : Param, qualifiers: [SgInput]};
-								replacement = {e: TVar(outVar), p:pos, t: nodeVar.type};
-								graphInputVars.push(outVar);
-								externs.push(outVar);
-								inits.push({variable: outVar, value:new h3d.Vector()});
+								var shParam = Std.downcast(currentNode.instance, ShaderParam);
+								if (shParam != null) {
+									var id = getNewVarId();
+									var outVar = {id: id, name: nodeVar.name, type: nodeVar.type, kind : Param, qualifiers: [SgInput]};
+									replacement = {e: TVar(outVar), p:pos, t: nodeVar.type};
+									graphInputVars.push(outVar);
+									externs.push(outVar);
+									var param = getParameter(shParam.parameterId);
+									inits.push({variable: outVar, value: param.defaultValue});
+								}
+								else {
+									replacement = convertToType(nodeVar.type, {e: TConst(CFloat(0.5)), p: pos, t:TFloat});
+								}
 							}
+
 							expr = replaceVar(expr, nodeVar, replacement);
 
 						}

+ 1 - 1
hrt/shgraph/ShaderNode.hx

@@ -39,7 +39,7 @@ class ShaderNode {
 		return outputs;
 	}
 
-	public function getShaderDef() : ShaderGraph.ShaderNodeDef {
+	public function getShaderDef(?getNewVarId: () -> Int) : ShaderGraph.ShaderNodeDef {
 		throw "Shouln't be called";
 		return {expr: null, inVars: [], outVars: [], inits: [], externVars: []};
 	}

+ 1 - 1
hrt/shgraph/ShaderNodeHxsl.hx

@@ -5,7 +5,7 @@ class ShaderNodeHxsl extends ShaderNode {
 
 	static var nodeCache : Map<String, ShaderGraph.ShaderNodeDef> = [];
 
-	override public function getShaderDef() : ShaderGraph.ShaderNodeDef {
+	override public function getShaderDef(?getNewVarId: () -> Int) : ShaderGraph.ShaderNodeDef {
 		var cl = Type.getClass(this);
 		var className = Type.getClassName(cl);
 		var def = nodeCache.get(className);

+ 1 - 1
hrt/shgraph/ShaderOutput.hx

@@ -18,7 +18,7 @@ class ShaderOutput extends ShaderNode {
 		return [];
 	}
 
-	override function getShaderDef():hrt.shgraph.ShaderGraph.ShaderNodeDef {
+	override function getShaderDef(?getNewVarId: () -> Int):hrt.shgraph.ShaderGraph.ShaderNodeDef {
 		var pos : Position = {file: "", min: 0, max: 0};
 
 		var inVar : TVar = {name: "input", id:0, type: this.variable.type, kind: Param, qualifiers: [SgInput]};

+ 1 - 3
hrt/shgraph/ShaderParam.hx

@@ -19,15 +19,13 @@ class ShaderParam extends ShaderNode {
 		return outputs;
 	}
 
-	override function getShaderDef():hrt.shgraph.ShaderGraph.ShaderNodeDef {
+	override function getShaderDef(?getNewVarId: () -> Int):hrt.shgraph.ShaderGraph.ShaderNodeDef {
 		var pos : Position = {file: "", min: 0, max: 0};
 
 		var inVar : TVar = {name: this.variable.name, id:0, type: this.variable.type, kind: Param, qualifiers: [SgInput]};
 		var output : TVar = {name: "output", id:1, type: this.variable.type, kind: Local, qualifiers: [SgOutput]};
 		var finalExpr : TExpr = {e: TBinop(OpAssign, {e:TVar(output), p:pos, t:output.type}, {e: TVar(inVar), p: pos, t: output.type}), p: pos, t: output.type};
 
-		//var param = getParameter(inputNode.parameterId);
-		//inits.push({variable: inVar, value: param.defaultValue});
 
 		return {expr: finalExpr, inVars: [], outVars:[output], externVars: [inVar, output], inits: []};
 	}

+ 9 - 0
hrt/shgraph/nodes/Multiply.hx

@@ -12,4 +12,13 @@ class Multiply extends Operation {
 		super(OpMult);
 	}
 
+	static var SRC = {
+		@sginput var a : Vec4;
+		@sginput var b : Vec4;
+		@sgoutput var output : Vec4;
+		function fragment() {
+			var c = a + b * 0.00001;
+			output = c;
+		}
+	}
 }

+ 2 - 2
hrt/shgraph/nodes/SubGraph.hx

@@ -36,9 +36,9 @@ class SubGraph extends ShaderNode {
 		return outputs;
 	}
 
-	override public function getShaderDef():hrt.shgraph.ShaderGraph.ShaderNodeDef {
+	override public function getShaderDef(?getNewVarId: () -> Int):hrt.shgraph.ShaderGraph.ShaderNodeDef {
 		var shader = new ShaderGraph(pathShaderGraph);
-		var gen = shader.generate2();
+		var gen = shader.generate2(getNewVarId);
 
 		for (tvar in gen.externVars) {
 			if (tvar.qualifiers != null) {