Browse Source

[shgraph] Fix globals declaration in shadergraph

Clément Espeute 1 year ago
parent
commit
b1710e6a72
2 changed files with 8 additions and 3 deletions
  1. 6 1
      hrt/shgraph/NodeGenContext.hx
  2. 2 2
      hrt/shgraph/Variables.hx

+ 6 - 1
hrt/shgraph/NodeGenContext.hx

@@ -128,7 +128,12 @@ class NodeGenContext {
 					def = {v: v, defValue: defValue, __init__: null};
 					if (parent != null) {
 						var p = Variables.Globals[parent];
-						v.parent = globalVars.getOrPut(p.name, {v : {id : hxsl.Tools.allocVarId(), name: p.name, type: TStruct([]), kind: kind}, defValue: null, __init__: null}).v;
+						switch (p.varkind) {
+							case KVar(kind, _, _):
+								v.parent = globalVars.getOrPut(p.name, {v : {id : hxsl.Tools.allocVarId(), name: p.name, type: TStruct([]), kind: kind}, defValue: null, __init__: null}).v;
+							default:
+								throw "Parent var must be a KVar";
+						}
 						switch(v.parent.type) {
 							case TStruct(arr):
 								arr.push(v);

+ 2 - 2
hrt/shgraph/Variables.hx

@@ -56,8 +56,8 @@ class Variables {
 
 		g[CalculatedUV] 		= {type: TVec(2, VFloat), 	name: "calculatedUV", varkind: KVar(Var)};
 
-		g[Time] 				= {type: TFloat, 	name: "time", 			varkind: KVar(Local, Global)};
-		g[PixelSize]			= {type: TVec(2, VFloat), 	name: "pixelSize", 		varkind: KVar(Local, Global)};
+		g[Time] 				= {type: TFloat, 	name: "time", 			varkind: KVar(Global, Global)};
+		g[PixelSize]			= {type: TVec(2, VFloat), 	name: "pixelSize", 		varkind: KVar(Global, Global)};
 		g[Global] 				= {type: TVoid, 	name: "global", 		varkind: KVar(Global)};
 
 		g[Input]			= {type: TVoid, name: "input", varkind: KVar(Input)};