Switched sample shaders to pixel shaders

このコミットが含まれているのは:
Sergio Pedri committed 2021-05-11 01:54:37 +02:00
1 親 5a4e05ba94
コミット 76d2f7d83e
11ファイル変更
+43 -94

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

+7 -7
ファイルの表示
@@ -6,12 +6,12 @@ using FX = TerraFX.Interop.Windows;
namespace ComputeSharp.SwapChain.Backend
{
internal sealed class SwapChainApplication<T> : Win32Application
where T : struct, IComputeShader
where T : struct, IPixelShader<Float4>
{
/// <summary>
/// The <see cref="Func{T1, T2, TResult}"/> instance used to create shaders to run.
/// The <see cref="Func{T1, TResult}"/> instance used to create shaders to run.
/// </summary>
private readonly Func<IReadWriteTexture2D<Float4>, TimeSpan, T> shaderFactory;
private readonly Func<TimeSpan, T> shaderFactory;
/// <summary>
/// The <see cref="ID3D12Device"/> pointer for the device currently in use.
@@ -76,8 +76,8 @@ namespace ComputeSharp.SwapChain.Backend
/// <summary>
/// Creates a new <see cref="SwapChainApplication"/> instance with the specified parameters.
/// </summary>
/// <param name="shaderFactory">The <see cref="Func{T1, T2, TResult}"/> instance used to create shaders to run.</param>
public SwapChainApplication(Func<IReadWriteTexture2D<Float4>, TimeSpan, T> shaderFactory)
/// <param name="shaderFactory">The <see cref="Func{T1, TResult}"/> instance used to create shaders to run.</param>
public SwapChainApplication(Func<TimeSpan, T> shaderFactory)
{
this.shaderFactory = shaderFactory;
}
@@ -231,12 +231,12 @@ namespace ComputeSharp.SwapChain.Backend
}
// Generate the new frame
Gpu.Default.For(this.texture!.Width, this.texture.Height, this.shaderFactory(this.texture, time));
Gpu.Default.ForEach(this.texture!, this.shaderFactory(time));
using ComPtr<ID3D12Resource> d3D12Resource = default;
// Get the underlying ID3D12Resource pointer for the texture
_ = InteropServices.TryGetID3D12Resource(this.texture, FX.__uuidof<ID3D12Resource>(), (void**)d3D12Resource.GetAddressOf());
_ = InteropServices.TryGetID3D12Resource(this.texture!, FX.__uuidof<ID3D12Resource>(), (void**)d3D12Resource.GetAddressOf());
// Get the target back buffer to update
ID3D12Resource* d3D12ResourceBackBuffer = this.currentBufferIndex switch
+9 -9
ファイルの表示
@@ -11,15 +11,15 @@ namespace ComputeSharp.SwapChain
/// </summary>
private static readonly Win32Application[] Samples = new Win32Application[]
{
new SwapChainApplication<ColorfulInfinity>(static (texture, time) => new(texture, (float)time.TotalSeconds)),
new SwapChainApplication<FractalTiling>(static (texture, time) => new(texture, (float)time.TotalSeconds)),
new SwapChainApplication<TwoTiledTruchet>(static (texture, time) => new(texture, (float)time.TotalSeconds)),
new SwapChainApplication<MengerJourney>(static (texture, time) => new(texture, (float)time.TotalSeconds)),
new SwapChainApplication<Octagrams>(static (texture, time) => new(texture, (float)time.TotalSeconds)),
new SwapChainApplication<ProteanClouds>(static (texture, time) => new(texture, (float)time.TotalSeconds)),
new SwapChainApplication<ExtrudedTruchetPattern>(static (texture, time) => new(texture, (float)time.TotalSeconds)),
new SwapChainApplication<PyramidPattern>(static (texture, time) => new(texture, (float)time.TotalSeconds)),
new SwapChainApplication<TriangleGridContouring>(static (texture, time) => new(texture, (float)time.TotalSeconds))
new SwapChainApplication<ColorfulInfinity>(static time => new((float)time.TotalSeconds)),
new SwapChainApplication<FractalTiling>(static time => new((float)time.TotalSeconds)),
new SwapChainApplication<TwoTiledTruchet>(static time => new((float)time.TotalSeconds)),
new SwapChainApplication<MengerJourney>(static time => new((float)time.TotalSeconds)),
new SwapChainApplication<Octagrams>(static time => new((float)time.TotalSeconds)),
new SwapChainApplication<ProteanClouds>(static time => new((float)time.TotalSeconds)),
new SwapChainApplication<ExtrudedTruchetPattern>(static time => new((float)time.TotalSeconds)),
new SwapChainApplication<PyramidPattern>(static time => new((float)time.TotalSeconds)),
new SwapChainApplication<TriangleGridContouring>(static time => new((float)time.TotalSeconds))
};
static void Main()
+3 -10
ファイルの表示
@@ -7,13 +7,8 @@
/// <para>License Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License.</para>
/// </summary>
[AutoConstructor]
internal readonly partial struct ColorfulInfinity : IComputeShader
internal readonly partial struct ColorfulInfinity : IPixelShader<Float4>
{
/// <summary>
/// The target texture.
/// </summary>
public readonly IReadWriteTexture2D<Float4> texture;
/// <summary>
/// The current time since the start of the application.
/// </summary>
@@ -49,7 +44,7 @@
}
/// <inheritdoc/>
public void Execute()
public Float4 Execute()
{
Float2 uv = (ThreadIds.XY - (Float2)DispatchSize.XY * 0.5f) / DispatchSize.Y;
Float3 col = 0;
@@ -68,9 +63,7 @@
col *= new Float3(2, 1.0f, 2.0f);
col = Hlsl.Pow(col, 0.5f);
Float4 color = new(col.X, col.Y, col.Z, 1.0f);
texture[ThreadIds.XY] = color;
return new(col.X, col.Y, col.Z, 1.0f);
}
}
}
+3 -8
ファイルの表示
@@ -6,13 +6,8 @@
/// <para>Created by Shane.</para>
/// </summary>
[AutoConstructor]
internal readonly partial struct ExtrudedTruchetPattern : IComputeShader
internal readonly partial struct ExtrudedTruchetPattern : IPixelShader<Float4>
{
/// <summary>
/// The target texture.
/// </summary>
public readonly IReadWriteTexture2D<Float4> texture;
/// <summary>
/// The current time since the start of the application.
/// </summary>
@@ -180,7 +175,7 @@
}
/// <inheritdoc/>
public void Execute()
public Float4 Execute()
{
Int2 coords = new(ThreadIds.X, DispatchSize.Y - ThreadIds.Y);
Float2 u = (coords - (Float2)DispatchSize.XY * 0.5f) / DispatchSize.Y;
@@ -292,7 +287,7 @@
c = Hlsl.Sqrt(Hlsl.Max(c, 0));
texture[ThreadIds.XY] = c;
return c;
}
}
}
+3 -8
ファイルの表示
@@ -7,20 +7,15 @@
/// <para>License Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License.</para>
/// </summary>
[AutoConstructor]
internal readonly partial struct FractalTiling : IComputeShader
internal readonly partial struct FractalTiling : IPixelShader<Float4>
{
/// <summary>
/// The target texture.
/// </summary>
public readonly IReadWriteTexture2D<Float4> texture;
/// <summary>
/// The current time since the start of the application.
/// </summary>
public readonly float time;
/// <inheritdoc/>
public void Execute()
public Float4 Execute()
{
Float2 position = ((Float2)(256 * ThreadIds.XY)) / DispatchSize.X + time;
Float4 color = 0;
@@ -45,7 +40,7 @@
color.XYZ = Hlsl.Pow(color.XYZ, new Float3(0.7f, 0.8f, 0.5f));
color.W = 1.0f;
texture[ThreadIds.XY] = color;
return color;
}
}
}
+3 -8
ファイルの表示
@@ -6,13 +6,8 @@
/// <para>Created by Syntopia.</para>
/// </summary>
[AutoConstructor]
internal readonly partial struct MengerJourney : IComputeShader
internal readonly partial struct MengerJourney : IPixelShader<Float4>
{
/// <summary>
/// The target texture.
/// </summary>
public readonly IReadWriteTexture2D<Float4> texture;
/// <summary>
/// The current time since the start of the application.
/// </summary>
@@ -153,7 +148,7 @@
}
/// <inheritdoc/>
public void Execute()
public Float4 Execute()
{
Float3 camPos = 0.5f * time * new Float3(1.0f, 0.0f, 0.0f);
Float3 target = camPos + new Float3(1.0f, 0.0f * Hlsl.Cos(time), 0.0f * Hlsl.Sin(0.4f * time));
@@ -169,7 +164,7 @@
Float3 rayDir = Hlsl.Normalize(camDir + (coord.X * camRight + coord.Y * camUp) * FieldOfView);
texture[ThreadIds.XY] = RayMarch(camPos, rayDir, ThreadIds.XY);
return RayMarch(camPos, rayDir, ThreadIds.XY);
}
}
}
+3 -8
ファイルの表示
@@ -6,13 +6,8 @@
/// <para>Created by whisky_shusuky.</para>
/// </summary>
[AutoConstructor]
internal readonly partial struct Octagrams : IComputeShader
internal readonly partial struct Octagrams : IPixelShader<Float4>
{
/// <summary>
/// The target texture.
/// </summary>
public readonly IReadWriteTexture2D<Float4> texture;
/// <summary>
/// The current time since the start of the application.
/// </summary>
@@ -88,7 +83,7 @@
}
/// <inheritdoc/>
public void Execute()
public Float4 Execute()
{
Float2 p = ((Float2)ThreadIds.XY * 2.0f - DispatchSize.XY) / Hlsl.Min(DispatchSize.X, DispatchSize.Y);
Float3 ro = new(0.0f, -0.2f, time * 4.0f);
@@ -122,7 +117,7 @@
Float3 col = ac * 0.02f + new Float3(0.0f, 0.2f * Hlsl.Abs(Hlsl.Sin(time)), 0.5f + Hlsl.Sin(time) * 0.2f);
Float4 color = new(col, 1.0f - t * (0.02f + 0.02f * Hlsl.Sin(time)));
texture[ThreadIds.XY] = color;
return color;
}
}
}
+3 -8
ファイルの表示
@@ -7,13 +7,8 @@
/// <para>License Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License.</para>
/// </summary>
[AutoConstructor]
internal readonly partial struct ProteanClouds : IComputeShader
internal readonly partial struct ProteanClouds : IPixelShader<Float4>
{
/// <summary>
/// The target texture.
/// </summary>
public readonly IReadWriteTexture2D<Float4> texture;
/// <summary>
/// The current time Hlsl.Since the start of the application.
/// </summary>
@@ -131,7 +126,7 @@
}
/// <inheritdoc/>
public void Execute()
public Float4 Execute()
{
Float2 q = (Float2)ThreadIds.XY / DispatchSize.XY;
Float2 p = (ThreadIds.XY - 0.5f * (Float2)DispatchSize.XY) / DispatchSize.Y;
@@ -167,7 +162,7 @@
col = Hlsl.Pow(col, new Float3(0.55f, 0.65f, 0.6f)) * new Float3(1.0f, 0.97f, 0.9f);
col *= Hlsl.Pow(16.0f * q.X * q.Y * (1.0f - q.X) * (1.0f - q.Y), 0.12f) * 0.7f + 0.3f;
texture[ThreadIds.XY] = new Float4(col, 1.0f);
return new(col, 1.0f);
}
}
}
+3 -10
ファイルの表示
@@ -7,13 +7,8 @@
/// <para>Created by Shane.</para>
/// </summary>
[AutoConstructor]
internal readonly partial struct PyramidPattern : IComputeShader
internal readonly partial struct PyramidPattern : IPixelShader<Float4>
{
/// <summary>
/// The target texture.
/// </summary>
public readonly IReadWriteTexture2D<Float4> texture;
/// <summary>
/// The current time Hlsl.Since the start of the application.
/// </summary>
@@ -135,7 +130,7 @@
}
/// <inheritdoc/>
public void Execute()
public Float4 Execute()
{
Int2 coordinate = new(ThreadIds.X, DispatchSize.Y - ThreadIds.Y);
float iRes = Hlsl.Min(DispatchSize.Y, 800.0f);
@@ -175,9 +170,7 @@
col *= hatch * 0.5f + 0.7f;
Float4 color = new(Hlsl.Sqrt(Hlsl.Max(col, 0.0f)), 1);
texture[ThreadIds.XY] = color;
return new(Hlsl.Sqrt(Hlsl.Max(col, 0.0f)), 1);
}
}
}
+3 -10
ファイルの表示
@@ -6,13 +6,8 @@
/// <para>Created by Shane.</para>
/// </summary>
[AutoConstructor]
internal readonly partial struct TriangleGridContouring : IComputeShader
internal readonly partial struct TriangleGridContouring : IPixelShader<Float4>
{
/// <summary>
/// The target texture.
/// </summary>
public readonly IReadWriteTexture2D<Float4> texture;
/// <summary>
/// The current time Hlsl.Since the start of the application.
/// </summary>
@@ -268,7 +263,7 @@
}
/// <inheritdoc/>
public void Execute()
public Float4 Execute()
{
Int2 coordinate = new(ThreadIds.X, DispatchSize.Y - ThreadIds.Y);
Float2 uv = (coordinate - (Float2)DispatchSize.XY * 0.5f) / Hlsl.Min(650.0f, DispatchSize.Y);
@@ -278,9 +273,7 @@
uv = coordinate / (Float2)DispatchSize.XY;
col *= Hlsl.Pow(16.0f * uv.X * uv.Y * (1.0f - uv.X) * (1.0f - uv.Y), 0.0625f) + 0.1f;
Float4 color = new(Hlsl.Sqrt(Hlsl.Max(col, 0.0f)), 1);
texture[ThreadIds.XY] = color;
return new(Hlsl.Sqrt(Hlsl.Max(col, 0.0f)), 1);
}
}
}
+3 -8
ファイルの表示
@@ -6,13 +6,8 @@
/// <para>Created by Shane.</para>
/// </summary>
[AutoConstructor]
internal readonly partial struct TwoTiledTruchet : IComputeShader
internal readonly partial struct TwoTiledTruchet : IPixelShader<Float4>
{
/// <summary>
/// The target texture.
/// </summary>
public readonly IReadWriteTexture2D<Float4> texture;
/// <summary>
/// The current time since the start of the application.
/// </summary>
@@ -114,7 +109,7 @@
}
/// <inheritdoc/>
public void Execute()
public Float4 Execute()
{
Float2 uv = (ThreadIds.XY - (Float2)DispatchSize.XY * 0.5f) / DispatchSize.Y;
float gSc = 7.0f;
@@ -143,7 +138,7 @@
Float3 rgb = Hlsl.Sqrt(Hlsl.Max(col, 0.0f));
Float4 color = new(rgb.X, rgb.Y, rgb.Z, 1.0f);
texture[ThreadIds.XY] = color;
return color;
}
}
}