Browse Source

Fixed Sampling in shaders, fixed timeline max value

flabbet 1 year ago
parent
commit
a04d51e52a

+ 11 - 2
src/PixiEditor.ChangeableDocument/Changeables/Graph/Context/FuncContext.cs

@@ -14,7 +14,15 @@ public class FuncContext
 {
     public static FuncContext NoContext { get; } = new();
 
-    public Float2 Position { get; private set; }
+    /// <summary>
+    ///     Original position of the pixel in the image. This is the input argument of the main function.
+    /// </summary>
+    public Float2 OriginalPosition { get; private set; }
+    
+    /// <summary>
+    ///     Modified position of the pixel. This should be used to sample the texture, unless you want to sample the texture at the original position only.
+    /// </summary>
+    public Float2 SamplePosition { get; private set; }
     public VecI Size { get; private set; }
     public bool HasContext { get; private set; }
     public RenderingContext RenderingContext { get; set; }
@@ -38,7 +46,8 @@ public class FuncContext
         RenderingContext = renderingContext;
         Builder = builder;
         HasContext = true;
-        Position = new Float2("coords"); // input argument 'half4 main(float2 coords)'
+        OriginalPosition = new Float2("coords"); // input argument 'half4 main(float2 coords)'
+        SamplePosition = Builder.ConstructFloat2(OriginalPosition.X, OriginalPosition.Y); 
     }
 
     public Half4 SampleTexture(Texture imageValue, Float2 pos)

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

@@ -28,7 +28,7 @@ public class ModifyImageLeftNode : Node
     public ModifyImageLeftNode()
     {
         Image = CreateInput<Texture>("Surface", "IMAGE", null);
-        Coordinate = CreateFuncOutput("Coordinate", "UV", ctx => ctx.Position);
+        Coordinate = CreateFuncOutput("Coordinate", "UV", ctx => ctx.OriginalPosition);
         Color = CreateFuncOutput("Color", "COLOR", GetColor);
     }
 
@@ -36,7 +36,7 @@ public class ModifyImageLeftNode : Node
     {
         context.ThrowOnMissingContext();
 
-        return context.SampleTexture(Image.Value, context.Position);
+        return context.SampleTexture(Image.Value, context.SamplePosition);
 
         /*var targetPixmap = pixmapCache[context.RenderingContext];
 

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

@@ -80,11 +80,11 @@ public class ModifyImageRightNode : Node, IPairNodeEnd
                 var coordinate = Coordinate.Value(context);
                 if (string.IsNullOrEmpty(coordinate.VariableName))
                 {
-                    builder.SetConstant(context.Position, coordinate);
+                    builder.SetConstant(context.SamplePosition, coordinate);
                 }
                 else
                 {
-                    builder.Set(context.Position, coordinate);
+                    builder.Set(context.SamplePosition, coordinate);
                 }
             }
             else
@@ -92,7 +92,7 @@ public class ModifyImageRightNode : Node, IPairNodeEnd
                 var constCoords = Coordinate.NonOverridenValue(FuncContext.NoContext);
                 constCoords.VariableName = "constCords";
                 builder.AddUniform(constCoords.VariableName, constCoords.ConstantValue);
-                builder.Set(context.Position, constCoords);
+                builder.Set(context.SamplePosition, constCoords);
             }
 
             if (Color.Connection != null)

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

@@ -101,7 +101,7 @@ public class ShaderBuilder
         {
             return;
         }
-
+        
         _bodyBuilder.AppendLine($"{contextPosition.VariableName} = {coordinateValue.VariableName};");
     }
 

+ 2 - 2
src/PixiEditor/Styles/Templates/Timeline.axaml

@@ -143,7 +143,7 @@
                                 IsSnapToTickEnabled="True"
                                 Name="PART_TimelineSlider"
                                 Minimum="1">
-                                <animations:TimelineSlider.Maximum>
+                                <!--<animations:TimelineSlider.Maximum>
                                     <MultiBinding>
                                         <MultiBinding.Converter>
                                             <converters:TimelineSliderWidthToMaximumConverter />
@@ -157,7 +157,7 @@
                                         <Binding RelativeSource="{RelativeSource TemplatedParent}"
                                                  Path="ActiveFrame" />
                                     </MultiBinding>
-                                </animations:TimelineSlider.Maximum>
+                                </animations:TimelineSlider.Maximum>-->
                                 <Interaction.Behaviors>
                                     <behaviours:SliderUpdateBehavior
                                         Binding="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=ActiveFrame, Mode=OneWay}"

+ 5 - 0
src/PixiEditor/Views/Animations/TimelineSlider.cs

@@ -50,6 +50,11 @@ public class TimelineSlider : Slider
         AffectsRender<TimelineSlider>(ScaleProperty, OffsetProperty, MinLeftOffsetProperty);
     }
 
+    public TimelineSlider()
+    {
+        Maximum = int.MaxValue;
+    }
+
     protected override void OnApplyTemplate(TemplateAppliedEventArgs e)
     {
         _increaseButtonSubscription?.Dispose();