From 03279bf426824dc5a4feb310c487cec507e35083 Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Sun, 9 Oct 2022 23:04:49 +0200 Subject: [PATCH] Add D2D1 HelloWorld test --- .../Shaders/HelloWorld.cs | 37 +++++++++++++++++++ tests/ComputeSharp.D2D1.Tests/ShadersTests.cs | 6 +++ 2 files changed, 43 insertions(+) create mode 100644 tests/ComputeSharp.D2D1.Tests/Shaders/HelloWorld.cs diff --git a/tests/ComputeSharp.D2D1.Tests/Shaders/HelloWorld.cs b/tests/ComputeSharp.D2D1.Tests/Shaders/HelloWorld.cs new file mode 100644 index 00000000..19332a5a --- /dev/null +++ b/tests/ComputeSharp.D2D1.Tests/Shaders/HelloWorld.cs @@ -0,0 +1,37 @@ +namespace ComputeSharp.D2D1.Tests.Shaders; + +/// +/// A simple shader to get started with based on shadertoy new shader template. +/// Ported from . +/// +[D2DInputCount(0)] +[D2DRequiresScenePosition] +[D2DShaderProfile(D2D1ShaderProfile.PixelShader50)] +[AutoConstructor] +internal readonly partial struct HelloWorld : ID2D1PixelShader +{ + /// + /// The current time since the start of the application. + /// + public readonly float time; + + /// + /// The dispatch size for the current output. + /// + public readonly int2 dispatchSize; + + /// + public float4 Execute() + { + Int2 xy = (int2)D2D.GetScenePosition().XY; + + // Normalized screen space UV coordinates from 0.0 to 1.0 + float2 uv = xy / (float2)this.dispatchSize; + + // Time varying pixel color + float3 col = 0.5f + (0.5f * Hlsl.Cos(this.time + new float3(uv, uv.X) + new float3(0, 2, 4))); + + // Output to screen + return new(col, 1f); + } +} \ No newline at end of file diff --git a/tests/ComputeSharp.D2D1.Tests/ShadersTests.cs b/tests/ComputeSharp.D2D1.Tests/ShadersTests.cs index e2c909f1..7a621718 100644 --- a/tests/ComputeSharp.D2D1.Tests/ShadersTests.cs +++ b/tests/ComputeSharp.D2D1.Tests/ShadersTests.cs @@ -14,6 +14,12 @@ public class ShadersTests RunTest(); } + [TestMethod] + public void HelloWorld() + { + RunTest(); + } + private static void RunTest() where T : unmanaged, ID2D1PixelShader {