Browse Source

Merge node

flabbet 10 months ago
parent
commit
07438438b2

+ 1 - 14
src/PixiEditor.ChangeableDocument/Changeables/Graph/Nodes/FolderNode.cs

@@ -17,20 +17,7 @@ public class FolderNode : StructureNode, IReadOnlyFolderNode, IClipSource, IPrev
 
 
     public FolderNode()
     public FolderNode()
     {
     {
-        Content = CreateRenderInput("Content", "CONTENT" /*, ctx =>
-        {
-            RectD? bounds = new RectD(VecI.Zero, ctx.DocumentSize);
-
-            // Folder doesn't need to do anything if no operations are present
-            if (bounds == null || (!HasOperations() && BlendMode.Value == Enums.BlendMode.Normal))
-            {
-                return Output.GetFirstRenderTarget(ctx);
-            }
-
-            VecI size = (VecI)bounds.Value.Size;
-            var outputWorkingSurface = RequestTexture(0, size, false);
-            return outputWorkingSurface.DrawingSurface;
-        }*/);
+        Content = CreateRenderInput("Content", "CONTENT");
     }
     }
 
 
     public override Node CreateCopy() => new FolderNode { MemberName = MemberName };
     public override Node CreateCopy() => new FolderNode { MemberName = MemberName };

+ 14 - 42
src/PixiEditor.ChangeableDocument/Changeables/Graph/Nodes/MergeNode.cs

@@ -26,29 +26,8 @@ public class MergeNode : RenderNode
     public MergeNode() 
     public MergeNode() 
     {
     {
         BlendMode = CreateInput("BlendMode", "BlendMode", Enums.BlendMode.Normal);
         BlendMode = CreateInput("BlendMode", "BlendMode", Enums.BlendMode.Normal);
-        /*Top = CreateRenderInput("Top", "TOP", context =>
-        {
-            var output = Output.GetFirstRenderTarget(context);
-            if(output == null)
-            {
-                return null;
-            }
-
-            topLayer = output.Canvas.SaveLayer(blendPaint);
-            return output;
-        });
-        Bottom = CreateRenderInput("Bottom", "BOTTOM", context =>
-        {
-            var output = Output.GetFirstRenderTarget(context);
-            
-            if(output == null)
-            {
-                return null;
-            }
-            
-            bottomLayer = output.Canvas.SaveLayer(blendPaint);
-            return output;
-        });*/
+        Top = CreateRenderInput("Top", "TOP");
+        Bottom = CreateRenderInput("Bottom", "BOTTOM");
     }
     }
 
 
     public override Node CreateCopy()
     public override Node CreateCopy()
@@ -69,34 +48,26 @@ public class MergeNode : RenderNode
             return;
             return;
         }
         }
 
 
-        Merge(target);
+        Merge(target, context);
     }
     }
 
 
-    private void Merge(DrawingSurface target)
+    private void Merge(DrawingSurface target, RenderContext context)
     {
     {
+        //TODO: Obsereve if behavior is correct, it could be that some background rendered elements influence Top with different blend mode.
         if (Bottom.Value != null && Top.Value != null)
         if (Bottom.Value != null && Top.Value != null)
         {
         {
-            Texture texTop = RequestTexture(0, target.DeviceClipBounds.Size, false);
-            Texture texBottom = RequestTexture(1, target.DeviceClipBounds.Size, false);
-            
+            Bottom.Value.Paint(context, target);
+
             paint.BlendMode = RenderContext.GetDrawingBlendMode(BlendMode.Value);
             paint.BlendMode = RenderContext.GetDrawingBlendMode(BlendMode.Value);
-            texBottom.DrawingSurface.Canvas.DrawSurface(texTop.DrawingSurface, 0, 0, blendPaint);
+            int saved = target.Canvas.SaveLayer(paint);
             
             
-            target.Canvas.DrawSurface(texTop.DrawingSurface, 0, 0);
+            Top.Value.Paint(context, target);
+            target.Canvas.RestoreToCount(saved);
             return;
             return;
         }
         }
-        
-        if(Bottom.Value != null)
-        {
-            Texture tex = RequestTexture(1, target.DeviceClipBounds.Size, false);
-            target.Canvas.DrawSurface(tex.DrawingSurface, 0, 0);
-        }
 
 
-        if(Top.Value != null)
-        {
-            Texture tex = RequestTexture(0, target.DeviceClipBounds.Size, false);
-            target.Canvas.DrawSurface(tex.DrawingSurface, 0, 0);
-        }
+        Bottom.Value?.Paint(context, target);
+        Top.Value?.Paint(context, target);
     }
     }
 
 
     public override RectD? GetPreviewBounds(int frame, string elementToRenderName = "")
     public override RectD? GetPreviewBounds(int frame, string elementToRenderName = "")
@@ -116,7 +87,8 @@ public class MergeNode : RenderNode
             return false;
             return false;
         }
         }
 
 
-        Merge(renderOn);
+        using RenderContext context = new RenderContext(renderOn, frame, ChunkResolution.Full, VecI.Zero);
+        Merge(renderOn, context);
 
 
         return true;
         return true;
     }
     }

+ 1 - 1
src/PixiEditor/Views/Rendering/Scene.cs

@@ -155,7 +155,7 @@ internal class Scene : Zoombox.Zoombox, ICustomHitTest
 
 
     public override void Render(DrawingContext context)
     public override void Render(DrawingContext context)
     {
     {
-        if (Document == null) return;
+        if (Document == null || SceneRenderer == null) return;
 
 
         float angle = (float)MathUtil.RadiansToDegrees(AngleRadians);
         float angle = (float)MathUtil.RadiansToDegrees(AngleRadians);