Browse Source

Fixed most stuff except rasterize points

flabbet 1 year ago
parent
commit
184d79b5e8

+ 3 - 3
src/PixiEditor.ChangeableDocument/Changeables/Graph/Nodes/CombineSeparate/CombineColorNode.cs

@@ -13,11 +13,11 @@ public class CombineColorNode : Node
 
 
     public InputProperty<CombineSeparateColorMode> Mode { get; }
     public InputProperty<CombineSeparateColorMode> Mode { get; }
 
 
-    public FuncInputProperty<Float1> RH { get; }
+    public FuncInputProperty<Float1> R { get; }
 
 
-    public FuncInputProperty<Float1> GS { get; }
+    public FuncInputProperty<Float1> G { get; }
 
 
-    public FuncInputProperty<Float1> BVL { get; }
+    public FuncInputProperty<Float1> B { get; }
 
 
     public FuncInputProperty<Float1> A { get; }
     public FuncInputProperty<Float1> A { get; }
 
 

+ 18 - 0
src/PixiEditor.ChangeableDocument/Changeables/Graph/Nodes/CreatingNode.md

@@ -0,0 +1,18 @@
+# How to create a new node?
+
+This is a guide that will help with writing new nodes and will help
+with solving common problems that may occur during the process.
+
+
+# Creating shader nodes
+
+
+
+# Important notes
+
+1. Do not create new Textures directly unless they are disposed in the same execution context.
+Creating new textures without managing them properly will lead to memory leaks, performance issues, visual glitches and unexpected crashes.
+
+Use `RequestTexture` method, it handles node texture caching and management.
+
+2. For the love of god, do not enumerate over pixels in a loop unless it's absolutely necessary. Create a proper shader builder instead.

+ 3 - 2
src/PixiEditor.ChangeableDocument/Changeables/Graph/Nodes/Evaluator/ColorEvaluatorLeftNode.cs

@@ -1,6 +1,7 @@
 using PixiEditor.ChangeableDocument.Rendering;
 using PixiEditor.ChangeableDocument.Rendering;
 using PixiEditor.DrawingApi.Core;
 using PixiEditor.DrawingApi.Core;
 using PixiEditor.DrawingApi.Core.ColorsImpl;
 using PixiEditor.DrawingApi.Core.ColorsImpl;
+using PixiEditor.DrawingApi.Core.Shaders.Generation.Expressions;
 using PixiEditor.Numerics;
 using PixiEditor.Numerics;
 
 
 namespace PixiEditor.ChangeableDocument.Changeables.Graph.Nodes.Evaluator;
 namespace PixiEditor.ChangeableDocument.Changeables.Graph.Nodes.Evaluator;
@@ -9,14 +10,14 @@ namespace PixiEditor.ChangeableDocument.Changeables.Graph.Nodes.Evaluator;
 [PairNode(typeof(ColorEvaluatorRightNode), "ColorEvaluatorZone", true)]
 [PairNode(typeof(ColorEvaluatorRightNode), "ColorEvaluatorZone", true)]
 public class ColorEvaluatorLeftNode : Node
 public class ColorEvaluatorLeftNode : Node
 {
 {
-    public FuncOutputProperty<VecD> Position { get; }
+    public FuncOutputProperty<Float2> Position { get; }
 
 
     public ColorEvaluatorLeftNode()
     public ColorEvaluatorLeftNode()
     {
     {
         Position = CreateFuncOutput("Position", "UV", c => c.Position);
         Position = CreateFuncOutput("Position", "UV", c => c.Position);
     }
     }
     
     
-    protected override Surface? OnExecute(RenderingContext context)
+    protected override Texture? OnExecute(RenderingContext context)
     {
     {
         return null;
         return null;
     }
     }

+ 5 - 4
src/PixiEditor.ChangeableDocument/Changeables/Graph/Nodes/Evaluator/ColorEvaluatorRightNode.cs

@@ -1,6 +1,7 @@
 using PixiEditor.ChangeableDocument.Rendering;
 using PixiEditor.ChangeableDocument.Rendering;
 using PixiEditor.DrawingApi.Core;
 using PixiEditor.DrawingApi.Core;
 using PixiEditor.DrawingApi.Core.ColorsImpl;
 using PixiEditor.DrawingApi.Core.ColorsImpl;
+using PixiEditor.DrawingApi.Core.Shaders.Generation.Expressions;
 
 
 namespace PixiEditor.ChangeableDocument.Changeables.Graph.Nodes.Evaluator;
 namespace PixiEditor.ChangeableDocument.Changeables.Graph.Nodes.Evaluator;
 
 
@@ -8,17 +9,17 @@ namespace PixiEditor.ChangeableDocument.Changeables.Graph.Nodes.Evaluator;
 [PairNode(typeof(ColorEvaluatorLeftNode), "ColorEvaluatorZone")]
 [PairNode(typeof(ColorEvaluatorLeftNode), "ColorEvaluatorZone")]
 public class ColorEvaluatorRightNode : Node
 public class ColorEvaluatorRightNode : Node
 {
 {
-    public FuncOutputProperty<Color> Output { get; }
+    public FuncOutputProperty<Half4> Output { get; }
 
 
-    public FuncInputProperty<Color> Input { get; }
+    public FuncInputProperty<Half4> Input { get; }
 
 
     public ColorEvaluatorRightNode()
     public ColorEvaluatorRightNode()
     {
     {
         Output = CreateFuncOutput("Output", "COLOR", c => Input.Value(c));
         Output = CreateFuncOutput("Output", "COLOR", c => Input.Value(c));
-        Input = CreateFuncInput("Input", "COLOR", Colors.Black);
+        Input = CreateFuncInput<Half4>("Input", "COLOR", Colors.Black);
     }
     }
     
     
-    protected override Surface? OnExecute(RenderingContext context)
+    protected override Texture? OnExecute(RenderingContext context)
     {
     {
         return null;
         return null;
     }
     }

+ 1 - 1
src/PixiEditor.ChangeableDocument/Changeables/Graph/Nodes/Points/DistributePointsNode.cs

@@ -22,7 +22,7 @@ public class DistributePointsNode : Node
         Seed = CreateInput("Seed", "SEED", 0);
         Seed = CreateInput("Seed", "SEED", 0);
     }
     }
 
 
-    protected override Surface? OnExecute(RenderingContext context)
+    protected override Texture? OnExecute(RenderingContext context)
     {
     {
         Points.Value = GetPointsRandomly();
         Points.Value = GetPointsRandomly();
         
         

+ 15 - 16
src/PixiEditor.ChangeableDocument/Changeables/Graph/Nodes/Points/RasterizePointsNode.cs

@@ -2,6 +2,9 @@
 using PixiEditor.ChangeableDocument.Rendering;
 using PixiEditor.ChangeableDocument.Rendering;
 using PixiEditor.DrawingApi.Core;
 using PixiEditor.DrawingApi.Core;
 using PixiEditor.DrawingApi.Core.ColorsImpl;
 using PixiEditor.DrawingApi.Core.ColorsImpl;
+using PixiEditor.DrawingApi.Core.Shaders.Generation;
+using PixiEditor.DrawingApi.Core.Shaders.Generation.Expressions;
+using PixiEditor.DrawingApi.Core.Surfaces;
 using PixiEditor.DrawingApi.Core.Surfaces.PaintImpl;
 using PixiEditor.DrawingApi.Core.Surfaces.PaintImpl;
 using PixiEditor.Numerics;
 using PixiEditor.Numerics;
 
 
@@ -10,22 +13,22 @@ namespace PixiEditor.ChangeableDocument.Changeables.Graph.Nodes.Points;
 [NodeInfo("RasterizePoints", "RASTERIZE_POINTS")]
 [NodeInfo("RasterizePoints", "RASTERIZE_POINTS")]
 public class RasterizePointsNode : Node
 public class RasterizePointsNode : Node
 {
 {
-    private Paint _paint = new();
+    private Paint _paint = new() { Color = Colors.White };
 
 
-    public OutputProperty<Surface> Image { get; }
+    public OutputProperty<Texture> Image { get; }
 
 
     public InputProperty<PointList> Points { get; }
     public InputProperty<PointList> Points { get; }
 
 
-    public FuncInputProperty<Color> Color { get; }
+    public FuncInputProperty<Half4> Color { get; }
 
 
     public RasterizePointsNode()
     public RasterizePointsNode()
     {
     {
-        Image = CreateOutput<Surface>("Image", "IMAGE", null);
+        Image = CreateOutput<Texture>("Image", "IMAGE", null);
         Points = CreateInput("Points", "POINTS", PointList.Empty);
         Points = CreateInput("Points", "POINTS", PointList.Empty);
-        Color = CreateFuncInput("Color", "COLOR", Colors.White);
+        Color = CreateFuncInput<Half4>("Color", "COLOR", Colors.White);
     }
     }
 
 
-    protected override Surface? OnExecute(RenderingContext context)
+    protected override Texture? OnExecute(RenderingContext context)
     {
     {
         var points = Points.Value;
         var points = Points.Value;
 
 
@@ -33,16 +36,12 @@ public class RasterizePointsNode : Node
             return null;
             return null;
 
 
         var size = context.DocumentSize;
         var size = context.DocumentSize;
-        var image = new Surface(size);
-
-        var colorFunc = Color.Value;
-        var funcContext = new FuncContext();
-        foreach (var point in points)
-        {
-            funcContext.UpdateContext(point, context.DocumentSize);
-            _paint.Color = colorFunc(funcContext);
-            image.DrawingSurface.Canvas.DrawPixel((VecI)point.Multiply(size), _paint);
-        }
+        var image = RequestTexture(0, size);
+
+        image.DrawingSurface.Canvas.DrawPoints(
+            PointMode.Points, 
+            points.Select(x => new Point((float)x.X, (float)x.Y)).ToArray(),
+            _paint);
 
 
         Image.Value = image;
         Image.Value = image;
         
         

+ 1 - 1
src/PixiEditor.ChangeableDocument/Changeables/Graph/Nodes/Points/RemoveClosePointsNode.cs

@@ -23,7 +23,7 @@ public class RemoveClosePointsNode : Node
         Seed = CreateInput("Seed", "SEED", 0);
         Seed = CreateInput("Seed", "SEED", 0);
     }
     }
     
     
-    protected override Surface? OnExecute(RenderingContext context)
+    protected override Texture? OnExecute(RenderingContext context)
     {
     {
         var distance = MinDistance.Value;
         var distance = MinDistance.Value;