Browse Source

To texture node and adjusted shader node

flabbet 10 months ago
parent
commit
1b98d816a6

+ 26 - 14
src/PixiEditor.ChangeableDocument/Changeables/Graph/Nodes/ModifyImageLeftNode.cs

@@ -1,12 +1,7 @@
-using System.Collections.Concurrent;
-using PixiEditor.ChangeableDocument.Changeables.Animations;
-using PixiEditor.ChangeableDocument.Changeables.Graph.Context;
+using PixiEditor.ChangeableDocument.Changeables.Graph.Context;
 using PixiEditor.ChangeableDocument.Changeables.Graph.Interfaces;
 using PixiEditor.ChangeableDocument.Changeables.Graph.Interfaces;
 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.Shaders;
-using PixiEditor.DrawingApi.Core.Shaders.Generation;
 using PixiEditor.DrawingApi.Core.Shaders.Generation.Expressions;
 using PixiEditor.DrawingApi.Core.Shaders.Generation.Expressions;
 using PixiEditor.DrawingApi.Core.Surfaces;
 using PixiEditor.DrawingApi.Core.Surfaces;
 using PixiEditor.Numerics;
 using PixiEditor.Numerics;
@@ -15,9 +10,9 @@ namespace PixiEditor.ChangeableDocument.Changeables.Graph.Nodes;
 
 
 [NodeInfo("ModifyImageLeft")]
 [NodeInfo("ModifyImageLeft")]
 [PairNode(typeof(ModifyImageRightNode), "ModifyImageZone", true)]
 [PairNode(typeof(ModifyImageRightNode), "ModifyImageZone", true)]
-public class ModifyImageLeftNode : Node, IPairNode
+public class ModifyImageLeftNode : Node, IPairNode, IPreviewRenderable
 {
 {
-    public RenderInputProperty Image { get; }
+    public InputProperty<Texture?> Image { get; }
 
 
     public FuncOutputProperty<Float2> Coordinate { get; }
     public FuncOutputProperty<Float2> Coordinate { get; }
 
 
@@ -25,11 +20,9 @@ public class ModifyImageLeftNode : Node, IPairNode
 
 
     public Guid OtherNode { get; set; }
     public Guid OtherNode { get; set; }
     
     
-    public Texture InputTexture { get; private set; }
-
     public ModifyImageLeftNode()
     public ModifyImageLeftNode()
     {
     {
-        Image = CreateRenderInput("Surface", "IMAGE");
+        Image = CreateInput<Texture?>("Surface", "IMAGE", null);
         Coordinate = CreateFuncOutput("Coordinate", "UV", ctx => ctx.OriginalPosition);
         Coordinate = CreateFuncOutput("Coordinate", "UV", ctx => ctx.OriginalPosition);
         Color = CreateFuncOutput("Color", "COLOR", GetColor);
         Color = CreateFuncOutput("Color", "COLOR", GetColor);
     }
     }
@@ -38,14 +31,33 @@ public class ModifyImageLeftNode : Node, IPairNode
     {
     {
         context.ThrowOnMissingContext();
         context.ThrowOnMissingContext();
 
 
-        return context.SampleSurface(InputTexture.DrawingSurface, context.SamplePosition);
+        return context.SampleSurface(Image.Value.DrawingSurface, context.SamplePosition);
     }
     }
 
 
     protected override void OnExecute(RenderContext context)
     protected override void OnExecute(RenderContext context)
     {
     {
-        InputTexture = RequestTexture(0, context.DocumentSize);
-        Image.Value.Paint(context, InputTexture.DrawingSurface);
     }
     }
 
 
     public override Node CreateCopy() => new ModifyImageLeftNode();
     public override Node CreateCopy() => new ModifyImageLeftNode();
+    public RectD? GetPreviewBounds(int frame, string elementToRenderName = "")
+    {
+        if(Image.Value == null)
+        {
+            return null;
+        } 
+        
+        return new RectD(0, 0, Image.Value.Size.X, Image.Value.Size.Y);
+    }
+
+    public bool RenderPreview(DrawingSurface renderOn, ChunkResolution resolution, int frame, string elementToRenderName)
+    {
+        if(Image.Value is null)
+        {
+            return false;
+        }
+
+        RenderContext renderContext = new(renderOn, frame, ChunkResolution.Full, VecI.Zero);
+        renderOn.Canvas.DrawSurface(Image.Value.DrawingSurface, 0, 0); 
+        return true;
+    }
 }
 }

+ 4 - 9
src/PixiEditor.ChangeableDocument/Changeables/Graph/Nodes/ModifyImageRightNode.cs

@@ -1,11 +1,7 @@
-using PixiEditor.ChangeableDocument.Changeables.Animations;
-using PixiEditor.ChangeableDocument.Changeables.Graph.Context;
+using PixiEditor.ChangeableDocument.Changeables.Graph.Context;
 using PixiEditor.ChangeableDocument.Changeables.Graph.Interfaces;
 using PixiEditor.ChangeableDocument.Changeables.Graph.Interfaces;
-using PixiEditor.ChangeableDocument.Changeables.Interfaces;
 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.Shaders;
 using PixiEditor.DrawingApi.Core.Shaders.Generation;
 using PixiEditor.DrawingApi.Core.Shaders.Generation;
 using PixiEditor.DrawingApi.Core.Shaders.Generation.Expressions;
 using PixiEditor.DrawingApi.Core.Shaders.Generation.Expressions;
 using PixiEditor.DrawingApi.Core.Surfaces;
 using PixiEditor.DrawingApi.Core.Surfaces;
@@ -52,14 +48,11 @@ public class ModifyImageRightNode : RenderNode, IPairNode, ICustomShaderNode
             return;
             return;
         }
         }
 
 
-        if (startNode.InputTexture is not { Size: var size })
+        if (startNode.Image.Value is not { Size: var size })
         {
         {
             return;
             return;
         }
         }
 
 
-        var width = size.X;
-        var height = size.Y;
-
         Texture surface = RequestTexture(0, size);
         Texture surface = RequestTexture(0, size);
 
 
         ShaderBuilder builder = new(size);
         ShaderBuilder builder = new(size);
@@ -117,11 +110,13 @@ public class ModifyImageRightNode : RenderNode, IPairNode, ICustomShaderNode
 
 
     public override RectD? GetPreviewBounds(int frame, string elementToRenderName = "")
     public override RectD? GetPreviewBounds(int frame, string elementToRenderName = "")
     {
     {
+        //TODO: Implement
         return null;
         return null;
     }
     }
 
 
     public override bool RenderPreview(DrawingSurface renderOn, ChunkResolution resolution, int frame, string elementToRenderName)
     public override bool RenderPreview(DrawingSurface renderOn, ChunkResolution resolution, int frame, string elementToRenderName)
     {
     {
+        //TODO: Implement
         return false;
         return false;
     }
     }
 
 

+ 37 - 0
src/PixiEditor.ChangeableDocument/Changeables/Graph/Nodes/ToTextureNode.cs

@@ -0,0 +1,37 @@
+using PixiEditor.ChangeableDocument.Rendering;
+using PixiEditor.DrawingApi.Core;
+using PixiEditor.Numerics;
+
+namespace PixiEditor.ChangeableDocument.Changeables.Graph.Nodes;
+
+[NodeInfo("ToTexture")]
+public class ToTextureNode : Node
+{
+    public RenderInputProperty RenderInput { get; }
+    public InputProperty<VecI> Size { get; }
+    public OutputProperty<Texture> Texture { get; }
+
+    public ToTextureNode()
+    {
+        RenderInput = CreateRenderInput("RenderInput", "RENDER_INPUT");
+        Size = CreateInput("Size", "SIZE", VecI.One).WithRules(x => 
+            x.Min(VecI.One));
+        Texture = CreateOutput<Texture>("Texture", "TEXTURE", null);
+    }
+    
+    protected override void OnExecute(RenderContext context)
+    {
+        if(RenderInput.Value == null)
+        {
+            return;
+        }
+
+        Texture.Value = RequestTexture(0, Size.Value);
+        RenderInput.Value.Paint(context, Texture.Value.DrawingSurface);
+    }
+
+    public override Node CreateCopy()
+    {
+        return new ToTextureNode();
+    }
+}

+ 1 - 1
src/PixiEditor.DrawingApi.Core/Shaders/Generation/ShaderBuilder.cs

@@ -70,7 +70,7 @@ public class ShaderBuilder
         }
         }
 
 
         string name = $"texture_{GetUniqueNameNumber()}";
         string name = $"texture_{GetUniqueNameNumber()}";
-        using var snapshot = surface.Snapshot();
+        using var snapshot = surface.Snapshot(surface.DeviceClipBounds);
         Uniforms[name] = new Uniform(name, snapshot.ToShader());
         Uniforms[name] = new Uniform(name, snapshot.ToShader());
         var newSampler = new SurfaceSampler(name);
         var newSampler = new SurfaceSampler(name);
         _samplers[surface] = newSampler;
         _samplers[surface] = newSampler;

+ 7 - 0
src/PixiEditor/ViewModels/Document/Nodes/ToTextureNodeViewModel.cs

@@ -0,0 +1,7 @@
+using PixiEditor.ChangeableDocument.Changeables.Graph.Nodes;
+using PixiEditor.ViewModels.Nodes;
+
+namespace PixiEditor.ViewModels.Document.Nodes;
+
+[NodeViewModel("TO_TEXTURE_NODE", "Image", null)]
+internal class ToTextureNodeViewModel : NodeViewModel<ToTextureNode>;