Ver Fonte

ShaderGraph: fixes + floor & fract nodes

Tom Spira há 6 anos atrás
pai
commit
429dadfc0d

+ 2 - 5
hide/view/shadereditor/ShaderEditor.hx

@@ -740,6 +740,7 @@ class ShaderEditor extends hide.view.Graph {
 				return;
 			}
 			error("Compilation of shader failed > " + e);
+			trace(e.stack);
 			if (newShader != null)
 				for (m in obj.getMaterials())
 					m.mainPass.removeShader(newShader);
@@ -1195,11 +1196,7 @@ class ShaderEditor extends hide.view.Graph {
 	}
 	
 	override function getDefaultContent() {
-		var p = {
-			type : "hlshader",
-			html : "",
-			json : {},
-		};
+		var p = { nodes: [], edges: [], parameters: [] };
 		return haxe.io.Bytes.ofString(ide.toJSON(p));
 	}
 

+ 11 - 3
hrt/shgraph/ShaderFunction.hx

@@ -17,9 +17,17 @@ class ShaderFunction extends ShaderNode {
 		var varArgs = [];
 
 		for (k in getInputInfoKeys()) {
-			args.push({ name: k, type: getInput(k).getType() });
-			var wantedType = ShaderType.getType(getInputInfo(k).type);
-			varArgs.push(getInput(k).getVar((wantedType != null) ? wantedType : null));
+			if (getInputInfo(k).hasProperty && getInput(k) == null) {
+				var value = Reflect.field(this, "prop_"+k);
+				if (value == null)
+					value = 0;
+				args.push({ name: k, type: TFloat });
+				varArgs.push(new NodeVar(new hrt.shgraph.nodes.FloatConst(value), "output").getVar());
+			} else {
+				args.push({ name: k, type: getInput(k).getType() });
+				var wantedType = ShaderType.getType(getInputInfo(k).type);
+				varArgs.push(getInput(k).getVar((wantedType != null) ? wantedType : null));
+			}
 		}
 
 		return {

+ 24 - 0
hrt/shgraph/nodes/Floor.hx

@@ -0,0 +1,24 @@
+package hrt.shgraph.nodes;
+
+using hxsl.Ast;
+
+@name("Floor")
+@description("The nearest integer less than or equal to X")
+@width(80)
+@group("Math")
+class Floor extends ShaderFunction {
+
+	@input("x") var x = SType.Number;
+
+	public function new() {
+		super(Floor);
+	}
+
+	override public function computeOutputs() {
+		if (x != null && !x.isEmpty())
+			addOutput("output", x.getType());
+		else
+			removeOutput("output");
+	}
+
+}

+ 24 - 0
hrt/shgraph/nodes/Fract.hx

@@ -0,0 +1,24 @@
+package hrt.shgraph.nodes;
+
+using hxsl.Ast;
+
+@name("Fract")
+@description("The fractional part of X")
+@width(80)
+@group("Math")
+class Fract extends ShaderFunction {
+
+	@input("x") var x = SType.Number;
+
+	public function new() {
+		super(Fract);
+	}
+
+	override public function computeOutputs() {
+		if (x != null && !x.isEmpty())
+			addOutput("output", x.getType());
+		else
+			removeOutput("output");
+	}
+
+}

+ 1 - 1
hrt/shgraph/nodes/Mod.hx

@@ -9,7 +9,7 @@ using hxsl.Ast;
 class Mod extends ShaderFunction {
 
 	@input("x") var x = SType.Float;
-	@input("mod") var mod = SType.Float;
+	@input("mod", true) var mod = SType.Float;
 
 	public function new() {
 		super(Mod);

+ 3 - 0
hrt/shgraph/nodes/SubGraph.hx

@@ -259,6 +259,9 @@ class SubGraph extends ShaderNode {
 						e.stopPropagation();
 					});
 					parentRange.parent().css("width", 50);
+					if (p.defaultValue != null) {
+						range.value = p.defaultValue;
+					}
 					range.onChange = function(moving) {
 						p.defaultValue = range.value;
 					};