From aebdf002d6e8c8f4579e8cf75e480806be9ea373 Mon Sep 17 00:00:00 2001 From: patan77 Date: Tue, 19 Oct 2021 11:47:15 +0200 Subject: [PATCH] Added a simple "HelloWorld" shader based on shadertoy/new to the SwapChain sample shaders to make it easier to understand and get started with making custom shaders. --- samples/ComputeSharp.SwapChain/Program.cs | 1 + .../Shaders/HelloWorld.cs | 29 +++++++++++++++++++ 2 files changed, 30 insertions(+) create mode 100644 samples/ComputeSharp.SwapChain/Shaders/HelloWorld.cs diff --git a/samples/ComputeSharp.SwapChain/Program.cs b/samples/ComputeSharp.SwapChain/Program.cs index 7e7332f2..c44c7992 100644 --- a/samples/ComputeSharp.SwapChain/Program.cs +++ b/samples/ComputeSharp.SwapChain/Program.cs @@ -20,6 +20,7 @@ namespace ComputeSharp.SwapChain /// private static readonly Win32Application[] Samples = new Win32Application[] { + new SwapChainApplication(static time => new((float)time.TotalSeconds)), new SwapChainApplication(static time => new((float)time.TotalSeconds)), new SwapChainApplication(static time => new((float)time.TotalSeconds)), new SwapChainApplication(static time => new((float)time.TotalSeconds)), diff --git a/samples/ComputeSharp.SwapChain/Shaders/HelloWorld.cs b/samples/ComputeSharp.SwapChain/Shaders/HelloWorld.cs new file mode 100644 index 00000000..cf6c9a34 --- /dev/null +++ b/samples/ComputeSharp.SwapChain/Shaders/HelloWorld.cs @@ -0,0 +1,29 @@ +namespace ComputeSharp.SwapChain.Shaders +{ + /// + /// A simple shader to get started with based on shadertoy new shader template. + /// Ported from . + /// + /// + [AutoConstructor] + internal readonly partial struct HelloWorld : IPixelShader + { + /// + /// The current time since the start of the application. + /// + public readonly float time; + + /// + public Float4 Execute() + { + // Normalized ScreenSpace UV coordinates from 0.0f to 1.0f + Float2 uv = new Float2(ThreadIds.Normalized.X, ThreadIds.Normalized.Y); + + // Time varying pixel color + Float3 col = 0.5f + 0.5f * Hlsl.Cos(time + new Float3(uv, uv.X) + new Float3(0, 2, 4)); + + // Output to screen + return new(col, 1f); + } + } +}