Browse Source

Added step and smooth step

flabbet 7 months ago
parent
commit
45daecdcbe

+ 1 - 1
src/Drawie

@@ -1 +1 @@
-Subproject commit 2571a7503807445d75f04d7e628751725d6f15c7
+Subproject commit a64659f76d57708b78180b3769c48e9def2f2bf4

+ 5 - 0
src/PixiEditor.ChangeableDocument/Changeables/Graph/Nodes/MathNode.cs

@@ -6,6 +6,7 @@ using PixiEditor.ChangeableDocument.Rendering;
 using Drawie.Backend.Core;
 using Drawie.Backend.Core;
 using Drawie.Backend.Core.Shaders.Generation;
 using Drawie.Backend.Core.Shaders.Generation;
 using Drawie.Backend.Core.Shaders.Generation.Expressions;
 using Drawie.Backend.Core.Shaders.Generation.Expressions;
+using PixiEditor.Common;
 
 
 namespace PixiEditor.ChangeableDocument.Changeables.Graph.Nodes;
 namespace PixiEditor.ChangeableDocument.Changeables.Graph.Nodes;
 
 
@@ -68,6 +69,8 @@ public class MathNode : Node
                 MathNodeMode.Modulo => ShaderMath.Modulo(x, y),
                 MathNodeMode.Modulo => ShaderMath.Modulo(x, y),
                 MathNodeMode.Min => ShaderMath.Min(x, y),
                 MathNodeMode.Min => ShaderMath.Min(x, y),
                 MathNodeMode.Max => ShaderMath.Max(x, y),
                 MathNodeMode.Max => ShaderMath.Max(x, y),
+                MathNodeMode.Step => ShaderMath.Step(x, y),
+                MathNodeMode.SmoothStep => ShaderMath.SmoothStep(x, y, z),
             };
             };
 
 
             if (Clamp.Value)
             if (Clamp.Value)
@@ -110,6 +113,8 @@ public class MathNode : Node
             MathNodeMode.Modulo => xConst % yConst,
             MathNodeMode.Modulo => xConst % yConst,
             MathNodeMode.Min => Math.Min(xConst, yConst),
             MathNodeMode.Min => Math.Min(xConst, yConst),
             MathNodeMode.Max => Math.Max(xConst, yConst),
             MathNodeMode.Max => Math.Max(xConst, yConst),
+            MathNodeMode.Step => xConst > yConst ? 1 : 0,
+            MathNodeMode.SmoothStep => MathEx.SmoothStep(xConst, yConst, zConst),
         };
         };
         
         
         if (Clamp.Value)
         if (Clamp.Value)

+ 7 - 2
src/PixiEditor.ChangeableDocument/Enums/MathNodeMode.cs

@@ -56,6 +56,10 @@ public enum MathNodeMode
     Min,
     Min,
     [Description("MAX")]
     [Description("MAX")]
     Max,
     Max,
+    [Description("STEP")]
+    Step,
+    [Description("SMOOTH_STEP")]
+    SmoothStep,
 }
 }
 
 
 public static class MathNodeModeExtensions
 public static class MathNodeModeExtensions
@@ -71,9 +75,10 @@ public static class MathNodeModeExtensions
         mode != MathNodeMode.Ceil &&
         mode != MathNodeMode.Ceil &&
         mode != MathNodeMode.Round &&
         mode != MathNodeMode.Round &&
         mode != MathNodeMode.NaturalLogarithm;
         mode != MathNodeMode.NaturalLogarithm;
-    
 
 
-    public static bool UsesZValue(this MathNodeMode mode) => mode is MathNodeMode.Compare;
+
+    public static bool UsesZValue(this MathNodeMode mode) =>
+        mode is MathNodeMode.Compare or MathNodeMode.SmoothStep;
 
 
     public static (string x, string y, string z) GetNaming(this MathNodeMode mode) => mode switch
     public static (string x, string y, string z) GetNaming(this MathNodeMode mode) => mode switch
     {
     {

+ 10 - 0
src/PixiEditor.Common/MathEx.cs

@@ -0,0 +1,10 @@
+namespace PixiEditor.Common;
+
+public static class MathEx
+{
+    public static double SmoothStep(double edge0, double edge1, double x)
+    {
+        x = Math.Clamp((x - edge0) / (edge1 - edge0), 0, 1);
+        return x * x * (3 - 2 * x);
+    }
+}

+ 2 - 0
src/PixiEditor/Data/Localization/Languages/en.json

@@ -758,6 +758,8 @@
   "CEIL": "Ceil",
   "CEIL": "Ceil",
   "ROUND": "Round",
   "ROUND": "Round",
   "MODULO": "Modulo",
   "MODULO": "Modulo",
+  "STEP": "Step",
+  "SMOOTH_STEP": "Smoothstep",
   "PIXEL_ART_TOOLSET": "Pixel Art",
   "PIXEL_ART_TOOLSET": "Pixel Art",
   "VECTOR_TOOLSET": "Vector",
   "VECTOR_TOOLSET": "Vector",
   "VECTOR_LAYER": "Vector Layer",
   "VECTOR_LAYER": "Vector Layer",

+ 0 - 14
src/PixiEditor/Helpers/MathUtil.cs

@@ -1,14 +0,0 @@
-namespace PixiEditor.Helpers;
-
-public static class MathUtil
-{
-    public static double DegreesToRadians(double angle)
-    {
-        return angle * Math.PI / 180;
-    }
-
-    public static double RadiansToDegrees(double angle)
-    {
-        return angle * 180 / Math.PI;
-    }
-}