mirror of
https://github.com/Artemis-RGB/Artemis
synced 2026-11-12 11:56:30 +00:00
Noise brush - Fixed for new render system
This commit is contained in:
1 parent
3aa9a632ea
commit
a05af16391
15 files changed
+92
-64
No files matched your search
@@ -54,8 +54,7 @@
|
||||
<Private>False</Private>
|
||||
</Reference>
|
||||
<Reference Include="SkiaSharp, Version=1.68.0.0, Culture=neutral, PublicKeyToken=0738eb9f132ed756, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\SkiaSharp.1.68.1\lib\net45\SkiaSharp.dll</HintPath>
|
||||
<Private>False</Private>
|
||||
<HintPath>..\packages\SkiaSharp.1.68.1.1\lib\net45\SkiaSharp.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Stylet, Version=1.3.0.0, Culture=neutral, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\Stylet.1.3.0\lib\net45\Stylet.dll</HintPath>
|
||||
@@ -119,11 +118,11 @@
|
||||
<PostBuildEvent>echo Copying plugin to Artemis.UI output directory
|
||||
XCOPY "$(TargetDir.TrimEnd('\'))" "$(SolutionDir)\Artemis.UI\$(OutDir)Plugins\$(ProjectName)" /s /q /i /y</PostBuildEvent>
|
||||
</PropertyGroup>
|
||||
<Import Project="..\packages\SkiaSharp.1.68.1\build\net45\SkiaSharp.targets" Condition="Exists('..\packages\SkiaSharp.1.68.1\build\net45\SkiaSharp.targets')" />
|
||||
<Import Project="..\packages\SkiaSharp.1.68.1.1\build\net45\SkiaSharp.targets" Condition="Exists('..\packages\SkiaSharp.1.68.1.1\build\net45\SkiaSharp.targets')" />
|
||||
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
|
||||
<PropertyGroup>
|
||||
<ErrorText>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}.</ErrorText>
|
||||
</PropertyGroup>
|
||||
<Error Condition="!Exists('..\packages\SkiaSharp.1.68.1\build\net45\SkiaSharp.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\SkiaSharp.1.68.1\build\net45\SkiaSharp.targets'))" />
|
||||
<Error Condition="!Exists('..\packages\SkiaSharp.1.68.1.1\build\net45\SkiaSharp.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\SkiaSharp.1.68.1.1\build\net45\SkiaSharp.targets'))" />
|
||||
</Target>
|
||||
</Project>
|
||||
@@ -16,6 +16,7 @@ namespace Artemis.Plugins.LayerBrushes.Noise
|
||||
public NoiseBrush(Layer layer, LayerBrushDescriptor descriptor) : base(layer, descriptor)
|
||||
{
|
||||
MainColorProperty = RegisterLayerProperty<SKColor>("Brush.MainColor", "Main color", "The main color of the noise.");
|
||||
SecondaryColorProperty = RegisterLayerProperty<SKColor>("Brush.SecondaryColor", "Secondary color", "The secondary color of the noise.");
|
||||
ScaleProperty = RegisterLayerProperty<SKSize>("Brush.Scale", "Scale", "The scale of the noise.");
|
||||
AnimationSpeedProperty = RegisterLayerProperty<float>("Brush.AnimationSpeed", "Animation speed", "The speed at which the noise moves.");
|
||||
ScaleProperty.InputAffix = "%";
|
||||
@@ -25,6 +26,7 @@ namespace Artemis.Plugins.LayerBrushes.Noise
|
||||
}
|
||||
|
||||
public LayerProperty<SKColor> MainColorProperty { get; set; }
|
||||
public LayerProperty<SKColor> SecondaryColorProperty { get; set; }
|
||||
public LayerProperty<SKSize> ScaleProperty { get; set; }
|
||||
public LayerProperty<float> 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
|
||||
<packages>
|
||||
<package id="SkiaSharp" version="1.68.1" targetFramework="net472" />
|
||||
<package id="SkiaSharp" version="1.68.1.1" targetFramework="net472" />
|
||||
<package id="Stylet" version="1.3.0" targetFramework="net472" />
|
||||
<package id="System.Buffers" version="4.5.0" targetFramework="net472" />
|
||||
<package id="System.Memory" version="4.5.3" targetFramework="net472" />
|
||||
|
||||
Reference in new issue
Block a user