Skip to content

Commit

Permalink
Full compilation path working
Browse files Browse the repository at this point in the history
  • Loading branch information
EspeuteClement committed Aug 8, 2023
1 parent 288a6dd commit 74bb72f
Show file tree
Hide file tree
Showing 7 changed files with 55 additions and 27 deletions.
59 changes: 40 additions & 19 deletions hrt/shgraph/ShaderGraph.hx
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);

}
Expand Down
2 changes: 1 addition & 1 deletion hrt/shgraph/ShaderNode.hx
Original file line number Diff line number Diff line change
Expand Up @@ -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: []};
}
Expand Down
2 changes: 1 addition & 1 deletion hrt/shgraph/ShaderNodeHxsl.hx
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion hrt/shgraph/ShaderOutput.hx
Original file line number Diff line number Diff line change
Expand Up @@ -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]};
Expand Down
4 changes: 1 addition & 3 deletions hrt/shgraph/ShaderParam.hx
Original file line number Diff line number Diff line change
Expand Up @@ -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: []};
}
Expand Down
9 changes: 9 additions & 0 deletions hrt/shgraph/nodes/Multiply.hx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
}
4 changes: 2 additions & 2 deletions hrt/shgraph/nodes/SubGraph.hx
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 74bb72f

Please sign in to comment.