diff --git a/hrt/shgraph/ShaderGraph.hx b/hrt/shgraph/ShaderGraph.hx index 8926d2bf9..135d73af3 100644 --- a/hrt/shgraph/ShaderGraph.hx +++ b/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 = []; - 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 = []; + + 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 = []; 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); } diff --git a/hrt/shgraph/ShaderNode.hx b/hrt/shgraph/ShaderNode.hx index 86a7bfe66..444dea420 100644 --- a/hrt/shgraph/ShaderNode.hx +++ b/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: []}; } diff --git a/hrt/shgraph/ShaderNodeHxsl.hx b/hrt/shgraph/ShaderNodeHxsl.hx index 2fd022616..ed391bd7b 100644 --- a/hrt/shgraph/ShaderNodeHxsl.hx +++ b/hrt/shgraph/ShaderNodeHxsl.hx @@ -5,7 +5,7 @@ class ShaderNodeHxsl extends ShaderNode { static var nodeCache : Map = []; - 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); diff --git a/hrt/shgraph/ShaderOutput.hx b/hrt/shgraph/ShaderOutput.hx index df81e9a33..3aa7f542d 100644 --- a/hrt/shgraph/ShaderOutput.hx +++ b/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]}; diff --git a/hrt/shgraph/ShaderParam.hx b/hrt/shgraph/ShaderParam.hx index e5857ade7..59fb1a2d2 100644 --- a/hrt/shgraph/ShaderParam.hx +++ b/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: []}; } diff --git a/hrt/shgraph/nodes/Multiply.hx b/hrt/shgraph/nodes/Multiply.hx index b4fbce1a2..a80fabb66 100644 --- a/hrt/shgraph/nodes/Multiply.hx +++ b/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; + } + } } \ No newline at end of file diff --git a/hrt/shgraph/nodes/SubGraph.hx b/hrt/shgraph/nodes/SubGraph.hx index cae2522f8..67db9afdc 100644 --- a/hrt/shgraph/nodes/SubGraph.hx +++ b/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) {