浏览代码

Added color space to shader sample

Krzysztof Krysiński 8 月之前
父节点
当前提交
4a7bfbee48

+ 8 - 0
src/PixiEditor.ChangeableDocument/Changeables/Graph/ColorSpaces/ColorSpaceType.cs

@@ -0,0 +1,8 @@
+namespace PixiEditor.ChangeableDocument.Changeables.Graph.ColorSpaces;
+
+public enum ColorSpaceType
+{
+    Inherit,
+    Srgb,
+    LinearSrgb,
+}

+ 25 - 9
src/PixiEditor.ChangeableDocument/Changeables/Graph/Nodes/ShaderNode.cs

@@ -5,6 +5,7 @@ using Drawie.Backend.Core.Shaders.Generation;
 using Drawie.Backend.Core.Surfaces;
 using Drawie.Backend.Core.Surfaces.PaintImpl;
 using Drawie.Numerics;
+using PixiEditor.ChangeableDocument.Changeables.Graph.ColorSpaces;
 using PixiEditor.ChangeableDocument.Changeables.Graph.Interfaces;
 using PixiEditor.ChangeableDocument.Rendering;
 
@@ -14,6 +15,7 @@ namespace PixiEditor.ChangeableDocument.Changeables.Graph.Nodes;
 public class ShaderNode : RenderNode, IRenderInput, ICustomShaderNode
 {
     public RenderInputProperty Background { get; }
+    public InputProperty<ColorSpaceType> ColorSpace { get; }
     public InputProperty<string> ShaderCode { get; }
 
     private Shader? shader;
@@ -32,6 +34,7 @@ public class ShaderNode : RenderNode, IRenderInput, ICustomShaderNode
     public ShaderNode()
     {
         Background = CreateRenderInput("Background", "BACKGROUND");
+        ColorSpace = CreateInput("ColorSpace", "COLOR_SPACE", ColorSpaceType.Inherit);
         ShaderCode = CreateInput("ShaderCode", "SHADER_CODE", "")
             .WithRules(validator => validator.Custom(ValidateShaderCode))
             .NonOverridenChanged(RegenerateUniformInputs);
@@ -112,13 +115,32 @@ public class ShaderNode : RenderNode, IRenderInput, ICustomShaderNode
 
     protected override void OnPaint(RenderContext context, DrawingSurface surface)
     {
-        if (shader == null)
+        if (shader == null || paint == null)
         {
             surface.Canvas.DrawColor(Colors.Magenta, BlendMode.Src);
             return;
         }
 
-        surface.Canvas.DrawRect(0, 0, context.DocumentSize.X, context.DocumentSize.Y, paint);
+        DrawingSurface targetSurface = surface;
+
+        if(ColorSpace.Value != ColorSpaceType.Inherit)
+        {
+            if (ColorSpace.Value == ColorSpaceType.Srgb && !context.ProcessingColorSpace.IsSrgb)
+            {
+                targetSurface = RequestTexture(51, context.DocumentSize, Drawie.Backend.Core.Surfaces.ImageData.ColorSpace.CreateSrgb()).DrawingSurface;
+            }
+            else if (ColorSpace.Value == ColorSpaceType.LinearSrgb && context.ProcessingColorSpace.IsSrgb)
+            {
+                targetSurface = RequestTexture(51, context.DocumentSize, Drawie.Backend.Core.Surfaces.ImageData.ColorSpace.CreateSrgbLinear()).DrawingSurface;
+            }
+        }
+
+        targetSurface.Canvas.DrawRect(0, 0, context.DocumentSize.X, context.DocumentSize.Y, paint);
+
+        if (targetSurface != surface)
+        {
+            surface.Canvas.DrawSurface(targetSurface, 0, 0);
+        }
     }
 
     public override RectD? GetPreviewBounds(int frame, string elementToRenderName = "")
@@ -128,13 +150,7 @@ public class ShaderNode : RenderNode, IRenderInput, ICustomShaderNode
 
     public override bool RenderPreview(DrawingSurface renderOn, RenderContext context, string elementToRenderName)
     {
-        if (shader == null || paint == null)
-        {
-            renderOn.Canvas.DrawColor(Colors.Magenta, BlendMode.Src);
-            return true;
-        }
-
-        renderOn.Canvas.DrawRect(0, 0, lastDocumentSize.X, lastDocumentSize.Y, paint);
+        OnPaint(context, renderOn);
         return true;
     }
 

二进制
src/PixiEditor/Data/BetaExampleFiles/Disco Ball.pixi


+ 3 - 2
src/PixiEditor/Data/Localization/Languages/en.json

@@ -648,7 +648,6 @@
   "CREATE_IMAGE_NODE": "Create Image",
   "FOLDER_NODE": "Folder",
   "IMAGE_LAYER_NODE": "Image Layer",
-  "IMAGE_SPACE_NODE": "Image Space",
   "KERNEL_FILTER_NODE": "Kernel Filter",
   "MATH_NODE": "Math",
   "COLOR_MATRIX_TRANSFORM_FILTER_NODE": "Matrix Transform Filter",
@@ -865,5 +864,7 @@
   "FAILED_TO_OPEN_EDITABLE_STRING_TITLE": "Failed to open file",
   "FAILED_TO_OPEN_EDITABLE_STRING_MESSAGE": "Failed to edit this string in external editor. Reason: {0}",
   "STRING_EDIT_IN_DEFAULT_APP": "Edit in default app",
-  "STRING_OPEN_IN_FOLDER": "Open in folder"
+  "STRING_OPEN_IN_FOLDER": "Open in folder",
+  "DISCO_BALL_EXAMPLE": "Disco Ball",
+  "COLOR_SPACE": "Color Space"
 }

+ 2 - 0
src/PixiEditor/Views/Nodes/Properties/StringPropertyView.axaml

@@ -39,6 +39,8 @@
                PlacementTarget="{Binding ElementName=bigModeToggle}">
             <DockPanel LastChildFill="True">
                 <Border CornerRadius="5 5 0 0" DockPanel.Dock="Top"
+                        BorderThickness="1 1 1 0"
+                        BorderBrush="{DynamicResource ThemeBorderHighBrush}"
                         Background="{DynamicResource ThemeBackgroundBrush1}">
                     <StackPanel Orientation="Horizontal">
                         <Button Margin="5" Classes="pixi-icon"

+ 6 - 5
src/PixiEditor/Views/Windows/HelloTherePopup.axaml

@@ -16,8 +16,7 @@
                          xmlns:visuals="clr-namespace:PixiEditor.Views.Visuals"
                          xmlns:windows="clr-namespace:PixiEditor.Views.Windows"
                          mc:Ignorable="d"
-                         Title="Hello there!" Height="680" Width="982" MinHeight="500" MinWidth="600"
-                         >
+                         Title="Hello there!" Height="680" Width="982" MinHeight="500" MinWidth="600">
 
     <Window.Styles>
         <Style Selector="TextBlock">
@@ -78,7 +77,7 @@
                                 ui:Translator.Key="NEW_FILE" />
                         <Button Classes="pixi-icon" Content="{DynamicResource icon-paste-as-new-layer}"
                                 Command="{Binding NewFromClipboardCommand}"
-                                ui:Translator.TooltipKey="NEW_FROM_CLIPBOARD"/>
+                                ui:Translator.TooltipKey="NEW_FROM_CLIPBOARD" />
                     </StackPanel>
 
                     <StackPanel Grid.Row="2" HorizontalAlignment="Center" Margin="0,30,0,0">
@@ -86,7 +85,7 @@
                                    ui:Translator.Key="BETA_EXAMPLE_FILES" />
 
                         <StackPanel Orientation="Horizontal" HorizontalAlignment="Center">
-                            <windows:BetaExampleButton FileName="Pond.pixi" DisplayName="POND_EXAMPLE"
+                            <windows:BetaExampleButton FileName="Disco Ball.pixi" DisplayName="DISCO_BALL_EXAMPLE"
                                                        CloseCommand="{Binding CloseCommand, RelativeSource={RelativeSource AncestorType=windows:HelloTherePopup}}" />
                             <windows:BetaExampleButton FileName="Tree.pixi" DisplayName="TREE_EXAMPLE"
                                                        CloseCommand="{Binding CloseCommand, RelativeSource={RelativeSource AncestorType=windows:HelloTherePopup}}" />
@@ -351,12 +350,14 @@
 
                     <ScrollViewer HorizontalAlignment="Center" VerticalScrollBarVisibility="Auto">
                         <panels:AlignableWrapPanel>
+                            <windows:BetaExampleButton FileName="Disco Ball.pixi" DisplayName="DISCO_BALL_EXAMPLE"
+                                                       CloseCommand="{Binding CloseCommand, RelativeSource={RelativeSource AncestorType=windows:HelloTherePopup}}" />
                             <windows:BetaExampleButton FileName="Pond.pixi" DisplayName="POND_EXAMPLE"
                                                        CloseCommand="{Binding CloseCommand, RelativeSource={RelativeSource AncestorType=windows:HelloTherePopup}}" />
                             <windows:BetaExampleButton FileName="Tree.pixi" DisplayName="TREE_EXAMPLE"
                                                        CloseCommand="{Binding CloseCommand, RelativeSource={RelativeSource AncestorType=windows:HelloTherePopup}}" />
                             <windows:BetaExampleButton FileName="Island.pixi" DisplayName="ISLAND_EXAMPLE"
-                                                         CloseCommand="{Binding CloseCommand, RelativeSource={RelativeSource AncestorType=windows:HelloTherePopup}}" />
+                                                       CloseCommand="{Binding CloseCommand, RelativeSource={RelativeSource AncestorType=windows:HelloTherePopup}}" />
                             <windows:BetaExampleButton FileName="Stars.pixi" DisplayName="STARS_EXAMPLE"
                                                        CloseCommand="{Binding CloseCommand, RelativeSource={RelativeSource AncestorType=windows:HelloTherePopup}}" />
                             <windows:BetaExampleButton FileName="Outline.pixi" DisplayName="OUTLINE_EXAMPLE"