Переглянути джерело

Fixed wrong scaling and masks

flabbet 9 місяців тому
батько
коміт
ea098704d7

+ 1 - 1
src/Drawie

@@ -1 +1 @@
-Subproject commit 97236ef7c361ad0768d3c1b14005a5fc56ce75cf
+Subproject commit a3a2b919c9049bf7cde1324d9bc8afa81c881e1b

+ 2 - 1
src/PixiEditor.ChangeableDocument/Changeables/Graph/Nodes/Filters.cs

@@ -37,5 +37,6 @@ public static class Filters
     /// </summary>
     public static readonly ColorFilter AverageGrayscaleFilter =
         ColorFilter.CreateColorMatrix(ColorMatrix.AverageGrayscale + ColorMatrix.OpaqueAlphaOffset);
-    
+
+    public static ColorFilter MaskFilter => ColorFilter.CreateColorMatrix(ColorMatrix.WeightedWavelengthAlphaGrayscale);
 }

+ 16 - 4
src/PixiEditor.ChangeableDocument/Changeables/Graph/Nodes/ImageLayerNode.cs

@@ -42,7 +42,7 @@ public class ImageLayerNode : LayerNode, IReadOnlyImageNode
     {
         return (RectD?)GetLayerImageAtFrame(frameTime.Frame).FindTightCommittedBounds();
     }
-    
+
     protected override VecI GetTargetSize(RenderContext ctx)
     {
         return (GetFrameWithImage(ctx.FrameTime).Data as ChunkyImage).LatestSize;
@@ -59,6 +59,18 @@ public class ImageLayerNode : LayerNode, IReadOnlyImageNode
         workingSurface.Canvas.RestoreToCount(scaled);
     }
 
+    protected internal override void DrawLayerOnTexture(SceneObjectRenderContext ctx, DrawingSurface workingSurface,
+        bool useFilters)
+    {
+        int scaled = workingSurface.Canvas.Save();
+        workingSurface.Canvas.Translate(GetScenePosition(ctx.FrameTime) * ctx.ChunkResolution.Multiplier());
+        workingSurface.Canvas.Scale((float)ctx.ChunkResolution.Multiplier());
+
+        DrawLayerOnto(ctx, workingSurface, useFilters);
+
+        workingSurface.Canvas.RestoreToCount(scaled);
+    }
+
     protected override void DrawWithoutFilters(SceneObjectRenderContext ctx, DrawingSurface workingSurface,
         Paint paint)
     {
@@ -94,11 +106,11 @@ public class ImageLayerNode : LayerNode, IReadOnlyImageNode
 
     public override RectD? GetPreviewBounds(int frame, string elementFor = "")
     {
-        if(IsDisposed)
+        if (IsDisposed)
         {
             return null;
         }
-        
+
         if (elementFor == nameof(EmbeddedMask))
         {
             return base.GetPreviewBounds(frame, elementFor);
@@ -131,7 +143,7 @@ public class ImageLayerNode : LayerNode, IReadOnlyImageNode
         {
             return false;
         }
-        
+
         if (elementToRenderName == nameof(EmbeddedMask))
         {
             return base.RenderPreview(renderOnto, resolution, frame, elementToRenderName);

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

@@ -59,7 +59,7 @@ 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 && ClipToPreviousMember)
+            if (Background.Connection is { Node: IClipSource clipSource } && ClipToPreviousMember)
             {
                 DrawClipSource(tempSurface.DrawingSurface, clipSource, context);
             }
@@ -74,7 +74,7 @@ public abstract class LayerNode : StructureNode, IReadOnlyLayerNode, IClipSource
         bool useFilters)
     {
         int scaled = workingSurface.Canvas.Save();
-        workingSurface.Canvas.Translate(GetScenePosition(ctx.FrameTime));
+        workingSurface.Canvas.Scale((float)ctx.ChunkResolution.Multiplier());
 
         DrawLayerOnto(ctx, workingSurface, useFilters);
 
@@ -100,7 +100,7 @@ public abstract class LayerNode : StructureNode, IReadOnlyLayerNode, IClipSource
         DrawLayerOnto(ctx, workingSurface, useFilters);
     }
 
-    private void DrawLayerOnto(SceneObjectRenderContext ctx, DrawingSurface workingSurface, bool useFilters)
+    protected void DrawLayerOnto(SceneObjectRenderContext ctx, DrawingSurface workingSurface, bool useFilters)
     {
         blendPaint.Color = blendPaint.Color.WithAlpha((byte)Math.Round(Opacity.Value * ctx.Opacity * 255));
 

+ 5 - 2
src/PixiEditor.ChangeableDocument/Changeables/Graph/Nodes/StructureNode.cs

@@ -49,12 +49,13 @@ public abstract class StructureNode : RenderNode, IReadOnlyStructureNode, IRende
         set => DisplayName = value;
     }
 
-    protected Paint maskPaint = new Paint() { BlendMode = Drawie.Backend.Core.Surfaces.BlendMode.DstIn };
+    protected Paint maskPaint = new Paint() { BlendMode = Drawie.Backend.Core.Surfaces.BlendMode.DstIn, ColorFilter = Nodes.Filters.MaskFilter };
     protected Paint blendPaint = new Paint() { BlendMode = Drawie.Backend.Core.Surfaces.BlendMode.SrcOver };
 
     protected Paint maskPreviewPaint = new Paint()
     {
-        BlendMode = Drawie.Backend.Core.Surfaces.BlendMode.SrcOver, ColorFilter = Nodes.Filters.AlphaGrayscaleFilter
+        BlendMode = Drawie.Backend.Core.Surfaces.BlendMode.SrcOver, 
+        ColorFilter = ColorFilter.CreateCompose(Nodes.Filters.AlphaGrayscaleFilter, Nodes.Filters.MaskFilter)
     };
 
     private int maskCacheHash = 0;
@@ -63,6 +64,7 @@ public abstract class StructureNode : RenderNode, IReadOnlyStructureNode, IRende
     {
         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);
@@ -136,6 +138,7 @@ public abstract class StructureNode : RenderNode, IReadOnlyStructureNode, IRende
             if (CustomMask.Value != null)
             {
                 int layer = surface.Canvas.SaveLayer(maskPaint);
+                surface.Canvas.Scale((float)context.ChunkResolution.Multiplier());
                 CustomMask.Value.Paint(context, surface);
                 
                 surface.Canvas.RestoreToCount(layer);