From 18b38658e9f46fd1e635b5f0684c834ce5563109 Mon Sep 17 00:00:00 2001 From: Robert Date: Thu, 13 Feb 2020 20:31:54 +0100 Subject: [PATCH] Noise brush - Fixed for new render system --- src/Artemis.Core/Artemis.Core.csproj | 6 +-- src/Artemis.Core/packages.config | 3 +- .../Artemis.Plugins.Devices.Wooting.csproj | 1 + .../app.config | 35 ++++++++++++ .../Artemis.Plugins.LayerBrushes.Color.csproj | 7 ++- .../packages.config | 3 +- .../Artemis.Plugins.LayerBrushes.Noise.csproj | 7 ++- .../NoiseBrush.cs | 53 ++++++++++--------- .../packages.config | 3 +- .../Artemis.Plugins.Modules.General.csproj | 9 ++-- .../packages.config | 3 +- .../Artemis.UI.Shared.csproj | 6 +-- src/Artemis.UI.Shared/packages.config | 3 +- src/Artemis.UI/Artemis.UI.csproj | 10 ++-- src/Artemis.UI/packages.config | 7 ++- 15 files changed, 92 insertions(+), 64 deletions(-) create mode 100644 src/Artemis.Plugins.Devices.Wooting/app.config diff --git a/src/Artemis.Core/Artemis.Core.csproj b/src/Artemis.Core/Artemis.Core.csproj index 8ba0ca831..245972cc7 100644 --- a/src/Artemis.Core/Artemis.Core.csproj +++ b/src/Artemis.Core/Artemis.Core.csproj @@ -94,7 +94,7 @@ ..\packages\Serilog.Sinks.File.4.0.0\lib\net45\Serilog.Sinks.File.dll - ..\packages\SkiaSharp.1.68.1\lib\net45\SkiaSharp.dll + ..\packages\SkiaSharp.1.68.1.1\lib\net45\SkiaSharp.dll ..\packages\Stylet.1.3.0\lib\net45\Stylet.dll @@ -232,7 +232,7 @@ - + - + \ No newline at end of file diff --git a/src/Artemis.Core/packages.config b/src/Artemis.Core/packages.config index 8a736a304..65d99c5ab 100644 --- a/src/Artemis.Core/packages.config +++ b/src/Artemis.Core/packages.config @@ -1,5 +1,4 @@  - @@ -15,7 +14,7 @@ - + diff --git a/src/Artemis.Plugins.Devices.Wooting/Artemis.Plugins.Devices.Wooting.csproj b/src/Artemis.Plugins.Devices.Wooting/Artemis.Plugins.Devices.Wooting.csproj index bddd6ad42..497643022 100644 --- a/src/Artemis.Plugins.Devices.Wooting/Artemis.Plugins.Devices.Wooting.csproj +++ b/src/Artemis.Plugins.Devices.Wooting/Artemis.Plugins.Devices.Wooting.csproj @@ -54,6 +54,7 @@ + PreserveNewest diff --git a/src/Artemis.Plugins.Devices.Wooting/app.config b/src/Artemis.Plugins.Devices.Wooting/app.config new file mode 100644 index 000000000..e79265588 --- /dev/null +++ b/src/Artemis.Plugins.Devices.Wooting/app.config @@ -0,0 +1,35 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/Artemis.Plugins.LayerBrushes.Color/Artemis.Plugins.LayerBrushes.Color.csproj b/src/Artemis.Plugins.LayerBrushes.Color/Artemis.Plugins.LayerBrushes.Color.csproj index 506742723..e89cad702 100644 --- a/src/Artemis.Plugins.LayerBrushes.Color/Artemis.Plugins.LayerBrushes.Color.csproj +++ b/src/Artemis.Plugins.LayerBrushes.Color/Artemis.Plugins.LayerBrushes.Color.csproj @@ -54,8 +54,7 @@ False - ..\packages\SkiaSharp.1.68.1\lib\net45\SkiaSharp.dll - False + ..\packages\SkiaSharp.1.68.1.1\lib\net45\SkiaSharp.dll ..\packages\Stylet.1.3.0\lib\net45\Stylet.dll @@ -118,11 +117,11 @@ echo Copying plugin to Artemis.UI output directory XCOPY "$(TargetDir.TrimEnd('\'))" "$(SolutionDir)\Artemis.UI\$(OutDir)Plugins\$(ProjectName)" /s /q /i /y - + This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}. - + \ No newline at end of file diff --git a/src/Artemis.Plugins.LayerBrushes.Color/packages.config b/src/Artemis.Plugins.LayerBrushes.Color/packages.config index 9597fbf92..07e19569f 100644 --- a/src/Artemis.Plugins.LayerBrushes.Color/packages.config +++ b/src/Artemis.Plugins.LayerBrushes.Color/packages.config @@ -1,8 +1,7 @@  - - + diff --git a/src/Artemis.Plugins.LayerBrushes.Noise/Artemis.Plugins.LayerBrushes.Noise.csproj b/src/Artemis.Plugins.LayerBrushes.Noise/Artemis.Plugins.LayerBrushes.Noise.csproj index 533b471b0..733029010 100644 --- a/src/Artemis.Plugins.LayerBrushes.Noise/Artemis.Plugins.LayerBrushes.Noise.csproj +++ b/src/Artemis.Plugins.LayerBrushes.Noise/Artemis.Plugins.LayerBrushes.Noise.csproj @@ -54,8 +54,7 @@ False - ..\packages\SkiaSharp.1.68.1\lib\net45\SkiaSharp.dll - False + ..\packages\SkiaSharp.1.68.1.1\lib\net45\SkiaSharp.dll ..\packages\Stylet.1.3.0\lib\net45\Stylet.dll @@ -119,11 +118,11 @@ echo Copying plugin to Artemis.UI output directory XCOPY "$(TargetDir.TrimEnd('\'))" "$(SolutionDir)\Artemis.UI\$(OutDir)Plugins\$(ProjectName)" /s /q /i /y - + This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}. - + \ No newline at end of file diff --git a/src/Artemis.Plugins.LayerBrushes.Noise/NoiseBrush.cs b/src/Artemis.Plugins.LayerBrushes.Noise/NoiseBrush.cs index 45341dd63..01f9c3e98 100644 --- a/src/Artemis.Plugins.LayerBrushes.Noise/NoiseBrush.cs +++ b/src/Artemis.Plugins.LayerBrushes.Noise/NoiseBrush.cs @@ -16,6 +16,7 @@ namespace Artemis.Plugins.LayerBrushes.Noise public NoiseBrush(Layer layer, LayerBrushDescriptor descriptor) : base(layer, descriptor) { MainColorProperty = RegisterLayerProperty("Brush.MainColor", "Main color", "The main color of the noise."); + SecondaryColorProperty = RegisterLayerProperty("Brush.SecondaryColor", "Secondary color", "The secondary color of the noise."); ScaleProperty = RegisterLayerProperty("Brush.Scale", "Scale", "The scale of the noise."); AnimationSpeedProperty = RegisterLayerProperty("Brush.AnimationSpeed", "Animation speed", "The speed at which the noise moves."); ScaleProperty.InputAffix = "%"; @@ -25,6 +26,7 @@ namespace Artemis.Plugins.LayerBrushes.Noise } public LayerProperty MainColorProperty { get; set; } + public LayerProperty SecondaryColorProperty { get; set; } public LayerProperty ScaleProperty { get; set; } public LayerProperty AnimationSpeedProperty { get; set; } @@ -41,45 +43,44 @@ namespace Artemis.Plugins.LayerBrushes.Noise public override void Render(SKCanvas canvas, SKPath path, SKPaint paint) { - return; var mainColor = MainColorProperty.CurrentValue; - var scale = ScaleProperty.CurrentValue; + var horizontalScale = ScaleProperty.CurrentValue.Width / 400f; + var verticalScale = ScaleProperty.CurrentValue.Height / 400f; // Scale down the render path to avoid computing a value for every pixel - var width = (int) (Math.Max(path.Bounds.Width, path.Bounds.Height) / scale.Width); - var height = (int) (Math.Max(path.Bounds.Width, path.Bounds.Height) / scale.Height); + var width = (int) (path.Bounds.Width * horizontalScale); + var height = (int) (path.Bounds.Height * verticalScale); + var opacity = (float) Math.Round(mainColor.Alpha / 255.0, 2, MidpointRounding.AwayFromZero); using (var bitmap = new SKBitmap(new SKImageInfo(width, height))) { - bitmap.Erase(new SKColor(0, 0, 0, 0)); - // Only compute pixels inside LEDs, due to scaling there may be some rounding issues but it's neglect-able - foreach (var artemisLed in Layer.Leds) + bitmap.Erase(SKColor.Empty); + for (var x = 0; x < width; x++) { - var xStart = artemisLed.AbsoluteRenderRectangle.Left / scale.Width; - var xEnd = artemisLed.AbsoluteRenderRectangle.Right / scale.Width; - var yStart = artemisLed.AbsoluteRenderRectangle.Top / scale.Height; - var yEnd = artemisLed.AbsoluteRenderRectangle.Bottom / scale.Height; - - for (var x = xStart; x < xEnd; x++) + for (var y = 0; y < height; y++) { - for (var y = yStart; y < yEnd; y++) - { - var v = _noise.Evaluate(scale.Width * x / width, scale.Height * y / height, _z); - var alpha = (byte) ((v + 1) * 127 * opacity); - // There's some fun stuff we can do here, like creating hard lines - // if (alpha > 128) - // alpha = 255; - // else - // alpha = 0; - bitmap.SetPixel((int) x, (int) y, new SKColor(mainColor.Red, mainColor.Green, mainColor.Blue, alpha)); - } + var v = _noise.Evaluate(1f / horizontalScale * x, 1f / verticalScale * y, _z); + var alpha = (byte) ((v + 1) * 127 * opacity); + // There's some fun stuff we can do here, like creating hard lines +// if (alpha > 128) +// alpha = 255; +// else +// alpha = 0; + bitmap.SetPixel(x, y, new SKColor(mainColor.Red, mainColor.Green, mainColor.Blue, alpha)); } } - using (var sh = SKShader.CreateBitmap(bitmap, SKShaderTileMode.Mirror, SKShaderTileMode.Mirror, SKMatrix.MakeScale(scale.Width, scale.Height))) + + var makeTranslation = SKMatrix.MakeTranslation(path.Bounds.Left, path.Bounds.Top); + SKMatrix.Concat(ref makeTranslation, makeTranslation, SKMatrix.MakeScale(1f / horizontalScale, 1f / verticalScale)); + using (var sh = SKShader.CreateBitmap(bitmap, SKShaderTileMode.Mirror, SKShaderTileMode.Mirror, makeTranslation)) { + paint.FilterQuality = SKFilterQuality.Low; + + paint.Shader = SKShader.CreateColor(SecondaryColorProperty.CurrentValue); + canvas.DrawPath(path, paint); paint.Shader = sh; - canvas.DrawPath(Layer.LayerShape.Path, paint); + canvas.DrawPath(path, paint); } } } diff --git a/src/Artemis.Plugins.LayerBrushes.Noise/packages.config b/src/Artemis.Plugins.LayerBrushes.Noise/packages.config index 991931ace..78451dca9 100644 --- a/src/Artemis.Plugins.LayerBrushes.Noise/packages.config +++ b/src/Artemis.Plugins.LayerBrushes.Noise/packages.config @@ -1,7 +1,6 @@  - - + diff --git a/src/Artemis.Plugins.Modules.General/Artemis.Plugins.Modules.General.csproj b/src/Artemis.Plugins.Modules.General/Artemis.Plugins.Modules.General.csproj index 4f9fc237f..96f2e0176 100644 --- a/src/Artemis.Plugins.Modules.General/Artemis.Plugins.Modules.General.csproj +++ b/src/Artemis.Plugins.Modules.General/Artemis.Plugins.Modules.General.csproj @@ -12,7 +12,7 @@ v4.7.2 512 true - false + false @@ -48,8 +48,7 @@ ..\..\..\RGB.NET\bin\net45\RGB.NET.Core.dll - ..\packages\SkiaSharp.1.68.1\lib\net45\SkiaSharp.dll - False + ..\packages\SkiaSharp.1.68.1.1\lib\net45\SkiaSharp.dll ..\packages\Stylet.1.3.0\lib\net45\Stylet.dll @@ -113,11 +112,11 @@ echo Copying plugin to Artemis.UI output directory XCOPY "$(TargetDir.TrimEnd('\'))" "$(SolutionDir)\Artemis.UI\$(OutDir)Plugins\$(ProjectName)" /s /q /i /y - + This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}. - + \ No newline at end of file diff --git a/src/Artemis.Plugins.Modules.General/packages.config b/src/Artemis.Plugins.Modules.General/packages.config index 732a6ba59..867f5dc4a 100644 --- a/src/Artemis.Plugins.Modules.General/packages.config +++ b/src/Artemis.Plugins.Modules.General/packages.config @@ -1,8 +1,7 @@  - - + diff --git a/src/Artemis.UI.Shared/Artemis.UI.Shared.csproj b/src/Artemis.UI.Shared/Artemis.UI.Shared.csproj index 7699b36c0..91c1bf71b 100644 --- a/src/Artemis.UI.Shared/Artemis.UI.Shared.csproj +++ b/src/Artemis.UI.Shared/Artemis.UI.Shared.csproj @@ -48,7 +48,7 @@ ..\packages\MaterialDesignThemes.2.6.0\lib\net45\MaterialDesignThemes.Wpf.dll - ..\packages\SkiaSharp.1.68.1\lib\net45\SkiaSharp.dll + ..\packages\SkiaSharp.1.68.1.1\lib\net45\SkiaSharp.dll @@ -125,11 +125,11 @@ - + This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}. - + \ No newline at end of file diff --git a/src/Artemis.UI.Shared/packages.config b/src/Artemis.UI.Shared/packages.config index 759d4f17e..dcd74b19b 100644 --- a/src/Artemis.UI.Shared/packages.config +++ b/src/Artemis.UI.Shared/packages.config @@ -1,10 +1,9 @@  - - + diff --git a/src/Artemis.UI/Artemis.UI.csproj b/src/Artemis.UI/Artemis.UI.csproj index 88852323e..181b07202 100644 --- a/src/Artemis.UI/Artemis.UI.csproj +++ b/src/Artemis.UI/Artemis.UI.csproj @@ -92,13 +92,13 @@ ..\packages\Serilog.2.8.0\lib\net46\Serilog.dll - ..\packages\SkiaSharp.1.68.1\lib\net45\SkiaSharp.dll + ..\packages\SkiaSharp.1.68.1.1\lib\net45\SkiaSharp.dll - ..\packages\SkiaSharp.Views.Desktop.Common.1.68.1\lib\net45\SkiaSharp.Views.Desktop.Common.dll + ..\packages\SkiaSharp.Views.Desktop.Common.1.68.1.1\lib\net45\SkiaSharp.Views.Desktop.Common.dll - ..\packages\SkiaSharp.Views.WPF.1.68.1\lib\net45\SkiaSharp.Views.WPF.dll + ..\packages\SkiaSharp.Views.WPF.1.68.1.1\lib\net45\SkiaSharp.Views.WPF.dll ..\packages\Stylet.1.3.0\lib\net45\Stylet.dll @@ -579,10 +579,9 @@ - + - @@ -591,4 +590,5 @@ + \ No newline at end of file diff --git a/src/Artemis.UI/packages.config b/src/Artemis.UI/packages.config index fe7beab5f..7a86da627 100644 --- a/src/Artemis.UI/packages.config +++ b/src/Artemis.UI/packages.config @@ -1,5 +1,4 @@  - @@ -14,9 +13,9 @@ - - - + + +