Browse Source

Fixed clips and filters

flabbet 10 months ago
parent
commit
b7b69271d3

+ 41 - 21
src/PixiEditor.ChangeableDocument/Changeables/Graph/Nodes/FolderNode.cs

@@ -35,8 +35,11 @@ public class FolderNode : StructureNode, IReadOnlyFolderNode, IClipSource, IPrev
 
     public override Node CreateCopy() => new FolderNode { MemberName = MemberName };
 
-    public override VecD GetScenePosition(KeyFrameTime time) => documentSize / 2f; //GetTightBounds(time).GetValueOrDefault().Center;
-    public override VecD GetSceneSize(KeyFrameTime time) => documentSize; //GetTightBounds(time).GetValueOrDefault().Size;
+    public override VecD GetScenePosition(KeyFrameTime time) =>
+        documentSize / 2f; //GetTightBounds(time).GetValueOrDefault().Center;
+
+    public override VecD GetSceneSize(KeyFrameTime time) =>
+        documentSize; //GetTightBounds(time).GetValueOrDefault().Size;
 
     protected override void OnExecute(RenderContext context)
     {
@@ -56,9 +59,16 @@ public class FolderNode : StructureNode, IReadOnlyFolderNode, IClipSource, IPrev
         {
             using Paint paint = new();
             paint.Color = Colors.White.WithAlpha((byte)Math.Round(Opacity.Value * 255f));
+
+            if (sceneContext.TargetPropertyOutput == Output)
+            {
+                paint.ColorFilter = Filters.Value?.ColorFilter;
+                paint.ImageFilter = Filters.Value?.ImageFilter;
+            }
+
             int saved = sceneContext.RenderSurface.Canvas.SaveLayer(paint);
             Content.Value?.Paint(sceneContext, sceneContext.RenderSurface);
-            
+
             sceneContext.RenderSurface.Canvas.RestoreToCount(saved);
             return;
         }
@@ -72,48 +82,56 @@ public class FolderNode : StructureNode, IReadOnlyFolderNode, IClipSource, IPrev
                 blendPaint.BlendMode = RenderContext.GetDrawingBlendMode(BlendMode.Value);
             }
 
-            RenderFolder(sceneContext, bounds, true);
+            RenderFolderContent(sceneContext, bounds, true);
         }
         else if (sceneContext.TargetPropertyOutput == FilterlessOutput ||
                  sceneContext.TargetPropertyOutput == RawOutput)
         {
-            RenderFolder(sceneContext, bounds, false);
+            RenderFolderContent(sceneContext, bounds, false);
         }
     }
 
-    private void RenderFolder(SceneObjectRenderContext sceneContext, RectD bounds, bool useFilters)
+    private void RenderFolderContent(SceneObjectRenderContext sceneContext, RectD bounds, bool useFilters)
     {
         VecI size = (VecI)bounds.Size;
         var outputWorkingSurface = RequestTexture(0, size, true);
-        
-        blendPaint.Color = Colors.White.WithAlpha((byte)Math.Round(Opacity.Value * 255f));
-        int saved = outputWorkingSurface.DrawingSurface.Canvas.SaveLayer(blendPaint);
-        
+
+        blendPaint.ImageFilter = null;
+        blendPaint.ColorFilter = null;
+
         Content.Value?.Paint(sceneContext, outputWorkingSurface.DrawingSurface);
-        
-        outputWorkingSurface.DrawingSurface.Canvas.RestoreToCount(saved);
 
         ApplyMaskIfPresent(outputWorkingSurface.DrawingSurface, sceneContext);
 
-        if (Background.Value != null)
+        if (Background.Value != null && sceneContext.TargetPropertyOutput != RawOutput)
         {
             Texture tempSurface = RequestTexture(1, outputWorkingSurface.Size);
-            if (Background.Connection.Node is IClipSource clipSource)
+            if (Background.Connection.Node is IClipSource clipSource && ClipToPreviousMember)
             {
                 DrawClipSource(tempSurface.DrawingSurface, clipSource, sceneContext);
             }
 
             ApplyRasterClip(outputWorkingSurface.DrawingSurface, tempSurface.DrawingSurface);
-            blendPaint.BlendMode = RenderContext.GetDrawingBlendMode(BlendMode.Value);
-            tempSurface.DrawingSurface.Canvas.DrawSurface(outputWorkingSurface.DrawingSurface, 0, 0, blendPaint);
-
-            sceneContext.RenderSurface.Canvas.DrawSurface(tempSurface.DrawingSurface, 0, 0, blendPaint);
-            outputWorkingSurface.DrawingSurface.Canvas.Clear();
-            return;
         }
 
+        AdjustPaint(useFilters);
+
         sceneContext.RenderSurface.Canvas.DrawSurface(outputWorkingSurface.DrawingSurface, 0, 0, blendPaint);
-        outputWorkingSurface.DrawingSurface.Canvas.Clear();
+    }
+
+    private void AdjustPaint(bool useFilters)
+    {
+        blendPaint.Color = Colors.White.WithAlpha((byte)Math.Round(Opacity.Value * 255f));
+        if (useFilters)
+        {
+            blendPaint.ColorFilter = Filters.Value?.ColorFilter;
+            blendPaint.ImageFilter = Filters.Value?.ImageFilter;
+        }
+        else
+        {
+            blendPaint.ColorFilter = null;
+            blendPaint.ImageFilter = null;
+        }
     }
 
     public override RectD? GetTightBounds(KeyFrameTime frameTime)
@@ -217,6 +235,8 @@ public class FolderNode : StructureNode, IReadOnlyFolderNode, IClipSource, IPrev
             return base.RenderPreview(renderOn, resolution, frame, elementToRenderName);
         }
 
+        // TODO: Make preview better, with filters, clips and stuff
+
         if (Content.Connection != null)
         {
             var executionQueue = GraphUtils.CalculateExecutionQueue(Content.Connection.Node);

+ 1 - 7
src/PixiEditor.ChangeableDocument/Changeables/Graph/Nodes/LayerNode.cs

@@ -59,18 +59,12 @@ public abstract class LayerNode : StructureNode, IReadOnlyLayerNode, IClipSource
         {
             Texture tempSurface = TryInitWorkingSurface(size, context.ChunkResolution, 4);
             tempSurface.DrawingSurface.Canvas.Clear();
-            if (Background.Connection.Node is IClipSource clipSource)
+            if (Background.Connection.Node is IClipSource clipSource && ClipToPreviousMember)
             {
-                // TODO: This probably should work with StructureMembers not Layers only
                 DrawClipSource(tempSurface.DrawingSurface, clipSource, context);
             }
 
             ApplyRasterClip(outputWorkingSurface.DrawingSurface, tempSurface.DrawingSurface);
-            blendPaint.BlendMode = RenderContext.GetDrawingBlendMode(BlendMode.Value);
-            tempSurface.DrawingSurface.Canvas.DrawSurface(outputWorkingSurface.DrawingSurface, 0, 0, blendPaint);
-
-            DrawWithResolution(tempSurface.DrawingSurface, renderOnto, context.ChunkResolution, size);
-            return;
         }
 
         DrawWithResolution(outputWorkingSurface.DrawingSurface, renderOnto, context.ChunkResolution, size);

+ 10 - 4
src/PixiEditor.ChangeableDocument/Changeables/Graph/Nodes/StructureNode.cs

@@ -49,7 +49,7 @@ public abstract class StructureNode : RenderNode, IReadOnlyStructureNode, IRende
         set => DisplayName = value;
     }
 
-    private Paint maskPaint = new Paint() { BlendMode = DrawingApi.Core.Surfaces.BlendMode.DstIn };
+    protected Paint maskPaint = new Paint() { BlendMode = DrawingApi.Core.Surfaces.BlendMode.DstIn };
     protected Paint blendPaint = new Paint() { BlendMode = DrawingApi.Core.Surfaces.BlendMode.SrcOver };
 
     protected Paint maskPreviewPaint = new Paint()
@@ -62,6 +62,7 @@ public abstract class StructureNode : RenderNode, IReadOnlyStructureNode, IRende
     protected StructureNode()
     {
         Painter filterlessPainter = new Painter(OnFilterlessPaint);
+        Painter rawPainter = new Painter(OnRawPaint);
         Background = CreateRenderInput("Background", "BACKGROUND");
         Opacity = CreateInput<float>("Opacity", "OPACITY", 1);
         IsVisible = CreateInput<bool>("IsVisible", "IS_VISIBLE", true);
@@ -73,14 +74,14 @@ public abstract class StructureNode : RenderNode, IReadOnlyStructureNode, IRende
         FilterlessOutput = CreateRenderOutput(nameof(FilterlessOutput), "WITHOUT_FILTERS",
             () => filterlessPainter, () => Background.Value);
 
-        RawOutput = CreateRenderOutput(nameof(RawOutput), "RAW_LAYER_OUTPUT", () => filterlessPainter);
+        RawOutput = CreateRenderOutput(nameof(RawOutput), "RAW_LAYER_OUTPUT", () => rawPainter);
 
         MemberName = DefaultMemberName;
     }
 
     protected override void OnPaint(RenderContext context, DrawingSurface renderTarget)
     {
-        if (Output.Connections.Count > 0 || Background.Value != null)
+        if (Output.Connections.Count > 0)
         {
             RenderForOutput(context, renderTarget, Output);
         }
@@ -91,6 +92,11 @@ public abstract class StructureNode : RenderNode, IReadOnlyStructureNode, IRende
         RenderForOutput(context, renderTarget, FilterlessOutput);
     }
     
+    private void OnRawPaint(RenderContext context, DrawingSurface renderTarget)
+    {
+        RenderForOutput(context, renderTarget, RawOutput);
+    }
+    
     public abstract VecD GetScenePosition(KeyFrameTime frameTime);
     public abstract VecD GetSceneSize(KeyFrameTime frameTime);
 
@@ -193,7 +199,7 @@ public abstract class StructureNode : RenderNode, IReadOnlyStructureNode, IRende
                 clearPaint);
         }
 
-        renderSurface.DrawingSurface.Canvas.Flush();
+        renderSurface.DrawingSurface.Flush();
     }
 
     protected void ApplyRasterClip(DrawingSurface toClip, DrawingSurface clipSource)