Add D2D1 ColorfulInfinity test

このコミットが含まれているのは:
Sergio Pedri committed 2022-10-15 21:57:06 +02:00
1 親 650e815616
コミット 0a31733384
4ファイル変更
+98 -8

検索条件に一致するファイルはありません

+1 -2
ファイルの表示
@@ -5,7 +5,6 @@ using System.IO;
using System.Numerics;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using ComputeSharp.D2D1;
using ComputeSharp.D2D1.Interop;
using ComputeSharp.D2D1.Tests.Extensions;
using ComputeSharp.D2D1.Tests.Helpers;
@@ -15,7 +14,7 @@ using Win32.Graphics.Direct2D;
#pragma warning disable IDE0065
namespace ComputeSharp.BokehBlur.Processors;
namespace ComputeSharp.D2D1.Tests.Effects;
using D2D1_BORDER_EDGE_MODE = BorderEdgeMode;
using D2D1_BORDER_PROP = BorderProp;
+5 -6
ファイルの表示
@@ -1,6 +1,5 @@
using System.IO;
using System.Reflection;
using ComputeSharp.BokehBlur.Processors;
using ComputeSharp.D2D1.Interop;
using ComputeSharp.D2D1.Tests.Effects;
using ComputeSharp.D2D1.Tests.Helpers;
@@ -23,19 +22,19 @@ public class EffectsTests
}
[TestMethod]
public unsafe void Invert()
public void Invert()
{
D2D1TestRunner.RunAndCompareShader(new InvertEffect(), null, "Landscape.png", "Landscape_Inverted.png");
}
[TestMethod]
public unsafe void InvertWithThreshold()
public void InvertWithThreshold()
{
D2D1TestRunner.RunAndCompareShader(new InvertWithThresholdEffect(1), null, "Landscape.png", "Landscape_Inverted.png");
}
[TestMethod]
public unsafe void Pixelate()
public void Pixelate()
{
D2D1TestRunner.RunAndCompareShader(
new PixelateEffect(new PixelateEffect.Constants(1280, 840, 16)),
@@ -45,13 +44,13 @@ public class EffectsTests
}
[TestMethod]
public unsafe void ZonePlate()
public void ZonePlate()
{
D2D1TestRunner.RunAndCompareShader(new ZonePlateEffect(1280, 720, 800), 1280, 720, "ZonePlate.png");
}
[TestMethod]
public unsafe void CheckerboardClip()
public void CheckerboardClip()
{
D2D1TestRunner.RunAndCompareShader(new CheckerboardClipEffect(1280, 840, 32), null, "Landscape.png", "Landscape_CheckerboardClip.png");
}
+77
ファイルの表示
@@ -0,0 +1,77 @@
namespace ComputeSharp.D2D1.Tests.Shaders;
/// <summary>
/// A shader creating an abstract and colorful animation.
/// Ported from <see href="https://www.shadertoy.com/view/WtjyzR"/>.
/// <para>Created by Benoit Marini.</para>
/// <para>License Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License.</para>
/// </summary>
[D2DInputCount(0)]
[D2DRequiresScenePosition]
[D2DShaderProfile(D2D1ShaderProfile.PixelShader50)]
[AutoConstructor]
internal readonly partial struct ColorfulInfinity : ID2D1PixelShader
{
/// <summary>
/// The current time since the start of the application.
/// </summary>
public readonly float time;
/// <summary>
/// The dispatch size for the current output.
/// </summary>
public readonly int2 dispatchSize;
/// <summary>
/// The total number of layers for the final animation.
/// </summary>
private const float NumberOfLayers = 16.0f;
/// <summary>
/// The number of iterations to calculate a texel value.
/// </summary>
private const int NumberOfIterations = 23;
/// <summary>
/// Makes some magic happen.
/// </summary>
private float4 Tex(float3 p)
{
float t = this.time + 78.0f;
float4 o = new(p.X, p.Y, p.Z, 3.0f * Hlsl.Sin(t * 0.1f));
float4 dec =
new float4(1.0f, 0.9f, 0.1f, 0.15f) +
new float4(0.06f * Hlsl.Cos(t * 0.1f), 0, 0, 0.14f * Hlsl.Cos(t * 0.23f));
for (int i = 0; i++ < NumberOfIterations;)
{
o.XZYW = Hlsl.Abs((o / Hlsl.Dot(o, o)) - dec);
}
return o;
}
/// <inheritdoc/>
public float4 Execute()
{
int2 xy = (int2)D2D.GetScenePosition().XY;
float2 uv = (xy - ((float2)this.dispatchSize * 0.5f)) / this.dispatchSize.Y;
float3 col = 0;
float t = this.time * 0.3f;
for (float i = 0.0f; i <= 1.0f; i += 1.0f / NumberOfLayers)
{
float d = Hlsl.Frac(i + t);
float s = Hlsl.Lerp(5.0f, 0.5f, d);
float f = d * Hlsl.SmoothStep(1.0f, 0.9f, d);
col += Tex(new float3(uv.X * s, uv.Y * s, i * 4.0f)).XYZ * f;
}
col /= NumberOfLayers;
col *= new float3(2, 1.0f, 2.0f);
col = Hlsl.Pow(col, 0.5f);
return new(col.X, col.Y, col.Z, 1.0f);
}
}
+15
ファイルの表示
@@ -1,3 +1,5 @@
using System;
using ComputeSharp.D2D1.Tests.Helpers;
using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace ComputeSharp.D2D1.Tests;
@@ -6,4 +8,17 @@ namespace ComputeSharp.D2D1.Tests;
[TestCategory("Shaders")]
public class ShadersTests
{
[TestMethod]
public void ColorfulInfinity()
{
RunTest<Shaders.ColorfulInfinity>();
}
private static void RunTest<T>()
where T : unmanaged, ID2D1PixelShader
{
T shader = (T)Activator.CreateInstance(typeof(T), 0f, new int2(1280, 720))!;
D2D1TestRunner.RunAndCompareShader(in shader, 1280, 720, $"{typeof(T).Name}.png");
}
}