|
@@ -16,7 +16,7 @@ namespace PixiEditor.ChangeableDocument.Changeables.Graph.Nodes;
|
|
|
|
|
|
[NodeInfo("ModifyImageRight")]
|
|
[NodeInfo("ModifyImageRight")]
|
|
[PairNode(typeof(ModifyImageLeftNode), "ModifyImageZone")]
|
|
[PairNode(typeof(ModifyImageLeftNode), "ModifyImageZone")]
|
|
-public class ModifyImageRightNode : Node, IPairNode, ICustomShaderNode
|
|
|
|
|
|
+public class ModifyImageRightNode : RenderNode, IPairNode, ICustomShaderNode
|
|
{
|
|
{
|
|
public Guid OtherNode { get; set; }
|
|
public Guid OtherNode { get; set; }
|
|
|
|
|
|
@@ -25,20 +25,17 @@ public class ModifyImageRightNode : Node, IPairNode, ICustomShaderNode
|
|
public FuncInputProperty<Float2> Coordinate { get; }
|
|
public FuncInputProperty<Float2> Coordinate { get; }
|
|
public FuncInputProperty<Half4> Color { get; }
|
|
public FuncInputProperty<Half4> Color { get; }
|
|
|
|
|
|
- public OutputProperty<Texture> Output { get; }
|
|
|
|
-
|
|
|
|
|
|
|
|
private string _lastSksl;
|
|
private string _lastSksl;
|
|
-
|
|
|
|
|
|
+
|
|
|
|
|
|
public ModifyImageRightNode()
|
|
public ModifyImageRightNode()
|
|
{
|
|
{
|
|
Coordinate = CreateFuncInput(nameof(Coordinate), "UV", new Float2("coords"));
|
|
Coordinate = CreateFuncInput(nameof(Coordinate), "UV", new Float2("coords"));
|
|
Color = CreateFuncInput(nameof(Color), "COLOR", new Half4(""));
|
|
Color = CreateFuncInput(nameof(Color), "COLOR", new Half4(""));
|
|
- Output = CreateOutput<Texture>(nameof(Output), "OUTPUT", null);
|
|
|
|
}
|
|
}
|
|
|
|
|
|
- protected override void OnExecute(RenderContext renderContext)
|
|
|
|
|
|
+ protected override void OnPaint(RenderContext renderContext, DrawingSurface targetSurface)
|
|
{
|
|
{
|
|
if (OtherNode == null)
|
|
if (OtherNode == null)
|
|
{
|
|
{
|
|
@@ -49,13 +46,13 @@ public class ModifyImageRightNode : Node, IPairNode, ICustomShaderNode
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- var startNode = FindStartNode();
|
|
|
|
|
|
+ var startNode = FindStartNode();
|
|
if (startNode == null)
|
|
if (startNode == null)
|
|
{
|
|
{
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
-
|
|
|
|
- if (startNode.Image.Value is not { Size: var size })
|
|
|
|
|
|
+
|
|
|
|
+ if (startNode.InputTexture is not { Size: var size })
|
|
{
|
|
{
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
@@ -65,108 +62,67 @@ public class ModifyImageRightNode : Node, IPairNode, ICustomShaderNode
|
|
|
|
|
|
Texture surface = RequestTexture(0, size);
|
|
Texture surface = RequestTexture(0, size);
|
|
|
|
|
|
- if (!surface.IsHardwareAccelerated)
|
|
|
|
- {
|
|
|
|
- startNode.PreparePixmap(renderContext);
|
|
|
|
-
|
|
|
|
- using Pixmap targetPixmap = surface.PeekReadOnlyPixels();
|
|
|
|
-
|
|
|
|
- ModifyImageInParallel(renderContext, targetPixmap, width, height);
|
|
|
|
|
|
+ ShaderBuilder builder = new(size);
|
|
|
|
+ FuncContext context = new(renderContext, builder);
|
|
|
|
|
|
- startNode.DisposePixmap(renderContext);
|
|
|
|
- }
|
|
|
|
- else
|
|
|
|
|
|
+ if (Coordinate.Connection != null)
|
|
{
|
|
{
|
|
- ShaderBuilder builder = new(size);
|
|
|
|
- FuncContext context = new(renderContext, builder);
|
|
|
|
-
|
|
|
|
- if (Coordinate.Connection != null)
|
|
|
|
|
|
+ var coordinate = Coordinate.Value(context);
|
|
|
|
+ if (string.IsNullOrEmpty(coordinate.VariableName))
|
|
{
|
|
{
|
|
- var coordinate = Coordinate.Value(context);
|
|
|
|
- if (string.IsNullOrEmpty(coordinate.VariableName))
|
|
|
|
- {
|
|
|
|
- builder.SetConstant(context.SamplePosition, coordinate);
|
|
|
|
- }
|
|
|
|
- else
|
|
|
|
- {
|
|
|
|
- builder.Set(context.SamplePosition, coordinate);
|
|
|
|
- }
|
|
|
|
|
|
+ builder.SetConstant(context.SamplePosition, coordinate);
|
|
}
|
|
}
|
|
else
|
|
else
|
|
{
|
|
{
|
|
- var constCoords = Coordinate.NonOverridenValue(FuncContext.NoContext);
|
|
|
|
- constCoords.VariableName = "constCords";
|
|
|
|
- builder.AddUniform(constCoords.VariableName, constCoords.ConstantValue);
|
|
|
|
- builder.Set(context.SamplePosition, constCoords);
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- if (Color.Connection != null)
|
|
|
|
- {
|
|
|
|
- builder.ReturnVar(Color.Value(context));
|
|
|
|
|
|
+ builder.Set(context.SamplePosition, coordinate);
|
|
}
|
|
}
|
|
- else
|
|
|
|
- {
|
|
|
|
- Half4 color = Color.NonOverridenValue(FuncContext.NoContext);
|
|
|
|
- color.VariableName = "color";
|
|
|
|
- builder.AddUniform(color.VariableName, color.ConstantValue);
|
|
|
|
- builder.ReturnVar(color);
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- string sksl = builder.ToSkSl();
|
|
|
|
- if (sksl != _lastSksl)
|
|
|
|
- {
|
|
|
|
- _lastSksl = sksl;
|
|
|
|
- drawingPaint?.Shader?.Dispose();
|
|
|
|
- drawingPaint.Shader = builder.BuildShader();
|
|
|
|
- }
|
|
|
|
- else
|
|
|
|
- {
|
|
|
|
- drawingPaint.Shader = drawingPaint.Shader.WithUpdatedUniforms(builder.Uniforms);
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- surface.DrawingSurface.Canvas.DrawPaint(drawingPaint);
|
|
|
|
- builder.Dispose();
|
|
|
|
}
|
|
}
|
|
-
|
|
|
|
- Output.Value = surface;
|
|
|
|
- }
|
|
|
|
|
|
+ else
|
|
|
|
+ {
|
|
|
|
+ var constCoords = Coordinate.NonOverridenValue(FuncContext.NoContext);
|
|
|
|
+ constCoords.VariableName = "constCords";
|
|
|
|
+ builder.AddUniform(constCoords.VariableName, constCoords.ConstantValue);
|
|
|
|
+ builder.Set(context.SamplePosition, constCoords);
|
|
|
|
+ }
|
|
|
|
|
|
- private unsafe void ModifyImageInParallel(RenderContext renderContext, Pixmap targetPixmap, int width,
|
|
|
|
- int height)
|
|
|
|
- {
|
|
|
|
- int threads = Environment.ProcessorCount;
|
|
|
|
- int chunkHeight = height / threads;
|
|
|
|
|
|
+ if (Color.Connection != null)
|
|
|
|
+ {
|
|
|
|
+ builder.ReturnVar(Color.Value(context));
|
|
|
|
+ }
|
|
|
|
+ else
|
|
|
|
+ {
|
|
|
|
+ Half4 color = Color.NonOverridenValue(FuncContext.NoContext);
|
|
|
|
+ color.VariableName = "color";
|
|
|
|
+ builder.AddUniform(color.VariableName, color.ConstantValue);
|
|
|
|
+ builder.ReturnVar(color);
|
|
|
|
+ }
|
|
|
|
|
|
- /*Parallel.For(0, threads, i =>
|
|
|
|
|
|
+ string sksl = builder.ToSkSl();
|
|
|
|
+ if (sksl != _lastSksl)
|
|
|
|
+ {
|
|
|
|
+ _lastSksl = sksl;
|
|
|
|
+ drawingPaint?.Shader?.Dispose();
|
|
|
|
+ drawingPaint.Shader = builder.BuildShader();
|
|
|
|
+ }
|
|
|
|
+ else
|
|
{
|
|
{
|
|
- FuncContext context = new(renderingContext);
|
|
|
|
|
|
+ drawingPaint.Shader = drawingPaint.Shader.WithUpdatedUniforms(builder.Uniforms);
|
|
|
|
+ }
|
|
|
|
|
|
- int startY = i * chunkHeight;
|
|
|
|
- int endY = (i + 1) * chunkHeight;
|
|
|
|
- if (i == threads - 1)
|
|
|
|
- {
|
|
|
|
- endY = height;
|
|
|
|
- }
|
|
|
|
|
|
+ surface.DrawingSurface.Canvas.DrawPaint(drawingPaint);
|
|
|
|
|
|
- Half* drawArray = (Half*)targetPixmap.GetPixels();
|
|
|
|
|
|
+ targetSurface.Canvas.DrawSurface(surface.DrawingSurface, 0, 0);
|
|
|
|
+ builder.Dispose();
|
|
|
|
+ }
|
|
|
|
|
|
- for (int y = startY; y < endY; y++)
|
|
|
|
- {
|
|
|
|
- for (int x = 0; x < width; x++)
|
|
|
|
- {
|
|
|
|
- context.UpdateContext(new VecD((double)x / width, (double)y / height), new VecI(width, height));
|
|
|
|
- var coordinate = Coordinate.Value(context);
|
|
|
|
- context.UpdateContext(coordinate, new VecI(width, height));
|
|
|
|
-
|
|
|
|
- var color = Color.Value(context);
|
|
|
|
- ulong colorBits = color.ToULong();
|
|
|
|
-
|
|
|
|
- int pixelOffset = (y * width + x) * 4;
|
|
|
|
- Half* drawPixel = drawArray + pixelOffset;
|
|
|
|
- *(ulong*)drawPixel = colorBits;
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- });*/
|
|
|
|
|
|
+ public override RectD? GetPreviewBounds(int frame, string elementToRenderName = "")
|
|
|
|
+ {
|
|
|
|
+ return null;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public override bool RenderPreview(DrawingSurface renderOn, ChunkResolution resolution, int frame, string elementToRenderName)
|
|
|
|
+ {
|
|
|
|
+ return false;
|
|
}
|
|
}
|
|
|
|
|
|
public override void Dispose()
|
|
public override void Dispose()
|
|
@@ -189,7 +145,7 @@ public class ModifyImageRightNode : Node, IPairNode, ICustomShaderNode
|
|
|
|
|
|
return true;
|
|
return true;
|
|
});
|
|
});
|
|
-
|
|
|
|
|
|
+
|
|
return startNode;
|
|
return startNode;
|
|
}
|
|
}
|
|
|
|
|