Fixed image processing sample
このコミットが含まれているのは:
1 親
f7d998ef30
コミット
400a2f4ab3
4ファイル変更
+183
-179
検索条件に一致するファイルはありません
@@ -1,4 +1,5 @@
|
||||
using SixLabors.ImageSharp;
|
||||
using System.Numerics;
|
||||
using SixLabors.ImageSharp;
|
||||
using SixLabors.ImageSharp.PixelFormats;
|
||||
using SixLabors.ImageSharp.Processing.Processors;
|
||||
|
||||
@@ -7,7 +8,7 @@ namespace ComputeSharp.BokehBlur.Processors
|
||||
/// <summary>
|
||||
/// Defines Gaussian blur by a (Sigma, Radius) pair.
|
||||
/// </summary>
|
||||
public sealed class HlslGaussianBlurProcessor : IImageProcessor
|
||||
public sealed partial class HlslGaussianBlurProcessor : IImageProcessor
|
||||
{
|
||||
/// <summary>
|
||||
/// The default value for <see cref="Sigma"/>.
|
||||
@@ -52,5 +53,79 @@ namespace ComputeSharp.BokehBlur.Processors
|
||||
{
|
||||
return new HlslGaussianBlurProcessor<TPixel>(this, configuration, source, sourceRectangle);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Kernel for the vertical convolution pass.
|
||||
/// </summary>
|
||||
[AutoConstructor]
|
||||
internal readonly partial struct VerticalConvolutionProcessor : IComputeShader
|
||||
{
|
||||
public readonly int width;
|
||||
public readonly int maxY;
|
||||
public readonly int maxX;
|
||||
public readonly int kernelLength;
|
||||
|
||||
public readonly ReadWriteBuffer<Vector4> source;
|
||||
public readonly ReadWriteBuffer<Vector4> target;
|
||||
public readonly ReadOnlyBuffer<float> kernel;
|
||||
|
||||
/// <inheritdoc/>
|
||||
public void Execute(ThreadIds ids)
|
||||
{
|
||||
Vector4 result = Vector4.Zero;
|
||||
int radiusY = kernelLength >> 1;
|
||||
int sourceOffsetColumnBase = ids.X;
|
||||
|
||||
for (int i = 0; i < kernelLength; i++)
|
||||
{
|
||||
int offsetY = Hlsl.Clamp(ids.Y + i - radiusY, 0, maxY);
|
||||
int offsetX = Hlsl.Clamp(sourceOffsetColumnBase, 0, maxX);
|
||||
Vector4 color = source[offsetY * width + offsetX];
|
||||
|
||||
result += kernel[i] * color;
|
||||
}
|
||||
|
||||
int offsetXY = ids.Y * width + ids.X;
|
||||
target[offsetXY] = result;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Kernel for the horizontal convolution pass.
|
||||
/// </summary>
|
||||
[AutoConstructor]
|
||||
internal readonly partial struct HorizontalConvolutionProcessor : IComputeShader
|
||||
{
|
||||
public readonly int width;
|
||||
public readonly int maxY;
|
||||
public readonly int maxX;
|
||||
public readonly int kernelLength;
|
||||
|
||||
public readonly ReadWriteBuffer<Vector4> source;
|
||||
public readonly ReadWriteBuffer<Vector4> target;
|
||||
public readonly ReadOnlyBuffer<float> kernel;
|
||||
|
||||
/// <inheritdoc/>
|
||||
public void Execute(ThreadIds ids)
|
||||
{
|
||||
Vector4 result = Vector4.Zero;
|
||||
int radiusX = kernelLength >> 1;
|
||||
int sourceOffsetColumnBase = ids.X;
|
||||
int offsetY = Hlsl.Clamp(ids.Y, 0, maxY);
|
||||
int offsetXY;
|
||||
|
||||
for (int i = 0; i < kernelLength; i++)
|
||||
{
|
||||
int offsetX = Hlsl.Clamp(sourceOffsetColumnBase + i - radiusX, 0, maxX);
|
||||
offsetXY = offsetY * width + offsetX;
|
||||
Vector4 color = source[offsetXY];
|
||||
|
||||
result += kernel[i] * color;
|
||||
}
|
||||
|
||||
offsetXY = ids.Y * width + ids.X;
|
||||
target[offsetXY] = result;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
新しいイシューから参照
ユーザーをブロックする