Browse Source

Fixed lerp node without context

Krzysztof Krysiński 2 weeks ago
parent
commit
cb4bffefb3

+ 14 - 4
src/PixiEditor.ChangeableDocument/Changeables/Graph/Nodes/LerpColorNode.cs

@@ -10,11 +10,11 @@ namespace PixiEditor.ChangeableDocument.Changeables.Graph.Nodes;
 [NodeInfo("Lerp")]
 public class LerpColorNode : Node // TODO: ILerpable as inputs? 
 {
-    public FuncOutputProperty<Half4> Result { get; } 
+    public FuncOutputProperty<Half4> Result { get; }
     public FuncInputProperty<Half4> From { get; }
     public FuncInputProperty<Half4> To { get; }
     public FuncInputProperty<Float1> Time { get; }
-    
+
     public LerpColorNode()
     {
         Result = CreateFuncOutput<Half4>("Result", "RESULT", Lerp);
@@ -28,8 +28,18 @@ public class LerpColorNode : Node // TODO: ILerpable as inputs?
         var from = arg.GetValue(From);
         var to = arg.GetValue(To);
         var time = arg.GetValue(Time);
-        
-        return arg.NewHalf4(ShaderMath.Lerp(from, to, time)); 
+
+        if (arg.HasContext)
+        {
+            return arg.NewHalf4(ShaderMath.Lerp(from, to, time));
+        }
+
+        var constFrom = (Color)from.GetConstant();
+        var constTo = (Color)to.GetConstant();
+        var constTime = (double)time.GetConstant();
+
+        Color result = Color.Lerp(constFrom, constTo, constTime);
+        return new Half4("") { ConstantValue = result };
     }
 
     protected override void OnExecute(RenderContext context)