Forráskód Böngészése

[shgraph] Added square/triangle wave, synced mini previews time with main preview

Clement Espeute 1 éve
szülő
commit
6a94aaf786

+ 7 - 0
hide/view/shadereditor/ShaderEditor.hx

@@ -1103,6 +1103,13 @@ class ShaderEditor extends hide.view.Graph {
 	}
 	}
 
 
 	function onMiniPreviewUpdate(dt: Float) {
 	function onMiniPreviewUpdate(dt: Float) {
+
+		@:privateAccess
+		if (sceneEditor?.scene?.s3d?.renderer?.ctx?.time != null) {
+			sceneEditor.scene.s3d.renderer.ctx.time = previewsScene.s3d.renderer.ctx.time;
+		}
+
+
 		var newBoxToPreview : Map<Box, Preview> = [];
 		var newBoxToPreview : Map<Box, Preview> = [];
 		for (box in listOfBoxes) {
 		for (box in listOfBoxes) {
 			var preview = boxToPreview.get(box);
 			var preview = boxToPreview.get(box);

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

@@ -2,7 +2,7 @@ package hrt.shgraph.nodes;
 
 
 using hxsl.Ast;
 using hxsl.Ast;
 
 
-@name("Pow")
+@name("Power")
 @description("The output is the result of x ^ b")
 @description("The output is the result of x ^ b")
 @width(80)
 @width(80)
 @group("Math")
 @group("Math")
@@ -10,7 +10,7 @@ class Pow extends ShaderNodeHxsl {
 
 
 	static var SRC = {
 	static var SRC = {
 		@sginput(0.0) var a : Dynamic;
 		@sginput(0.0) var a : Dynamic;
-		@sginput(0.0) var b : Dynamic;
+		@sginput(2.0) var b : Dynamic;
 		@sgoutput var output : Dynamic;
 		@sgoutput var output : Dynamic;
 		function fragment() {
 		function fragment() {
 			output = pow(a,b);
 			output = pow(a,b);

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

@@ -2,9 +2,9 @@ package hrt.shgraph.nodes;
 
 
 using hxsl.Ast;
 using hxsl.Ast;
 
 
-@name("Sqrt")
+@name("Square Root")
 @description("The output is the squre root A")
 @description("The output is the squre root A")
-@width(80)
+@width(120)
 @group("Math")
 @group("Math")
 @:keep
 @:keep
 class Sqrt extends ShaderNodeHxsl {
 class Sqrt extends ShaderNodeHxsl {

+ 18 - 0
hrt/shgraph/nodes/SquareWave.hx

@@ -0,0 +1,18 @@
+package hrt.shgraph.nodes;
+
+using hxsl.Ast;
+
+@name("Square Wave")
+@description("A square wave of period 1 oscilating between -1 and 1")
+@width(120)
+@group("Math")
+class SquareWave extends ShaderNodeHxsl {
+
+	static var SRC = {
+		@sginput(0.0) var a : Dynamic;
+		@sgoutput var output : Dynamic;
+		function fragment() {
+			output = 2*(2*floor(a)-floor(2*a))+1;
+		}
+	};
+}

+ 18 - 0
hrt/shgraph/nodes/TriangleWave.hx

@@ -0,0 +1,18 @@
+package hrt.shgraph.nodes;
+
+using hxsl.Ast;
+
+@name("Triangle Wave")
+@description("A triangle wave of period 1 oscilating between -1 and 1")
+@width(120)
+@group("Math")
+class TriangleWave extends ShaderNodeHxsl {
+
+	static var SRC = {
+		@sginput(0.0) var a : Dynamic;
+		@sgoutput var output : Dynamic;
+		function fragment() {
+			output = 2*2*abs(a-floor(a+0.5))-1;
+		}
+	};
+}