Browse Source

Made UV of Sample Image actually useful

flabbet 1 year ago
parent
commit
ed3b258b2b

+ 13 - 0
src/PixiEditor.ChangeableDocument/Changeables/Graph/Context/FuncContext.cs

@@ -115,4 +115,17 @@ public class FuncContext
 
 
         return getFrom.Value(this);
         return getFrom.Value(this);
     }
     }
+
+    public Float2 GetValue(FuncInputProperty<Float2> getFrom)
+    {
+        if (getFrom.Connection == null || !IsFuncType(getFrom))
+        {
+            Float2 value = getFrom.Value(this);
+            value.VariableName = $"float2_{Builder.GetUniqueNameNumber()}";
+            Builder.AddUniform(value.VariableName, value.ConstantValue);
+            return value;
+        }
+
+        return getFrom.Value(this);
+    }
 }
 }

+ 5 - 3
src/PixiEditor.ChangeableDocument/Changeables/Graph/Nodes/SampleImageNode.cs

@@ -13,14 +13,14 @@ public class SampleImageNode : Node
 {
 {
     public InputProperty<Texture?> Image { get; }
     public InputProperty<Texture?> Image { get; }
 
 
-    public FuncOutputProperty<Float2> Coordinate { get; }
+    public FuncInputProperty<Float2> Coordinate { get; }
 
 
     public FuncOutputProperty<Half4> Color { get; }
     public FuncOutputProperty<Half4> Color { get; }
 
 
     public SampleImageNode()
     public SampleImageNode()
     {
     {
         Image = CreateInput<Texture>(nameof(Texture), "IMAGE", null);
         Image = CreateInput<Texture>(nameof(Texture), "IMAGE", null);
-        Coordinate = CreateFuncOutput(nameof(Coordinate), "UV", ctx => ctx.Position);
+        Coordinate = CreateFuncInput<Float2>(nameof(Coordinate), "UV", VecD.Zero);
         Color = CreateFuncOutput(nameof(Color), "COLOR", GetColor);
         Color = CreateFuncOutput(nameof(Color), "COLOR", GetColor);
     }
     }
 
 
@@ -33,7 +33,9 @@ public class SampleImageNode : Node
             return new Half4("");
             return new Half4("");
         }
         }
 
 
-        return context.SampleTexture(Image.Value, context.Position);
+        Float2 uv = context.GetValue(Coordinate);
+
+        return context.SampleTexture(Image.Value, uv);
     }
     }
 
 
     protected override Texture? OnExecute(RenderingContext context)
     protected override Texture? OnExecute(RenderingContext context)