Add pixelate effect to unit tests
This also includes a nested [AutoConstructor] buffer
このコミットが含まれているのは:
1 親
a8525592fd
コミット
d21cc4066c
3ファイル変更
+53
-1
検索条件に一致するファイルはありません
バイナリファイルは表示されません。
|
変更後 幅: | 高さ: | サイズ: 24 KiB |
@@ -32,6 +32,9 @@
|
||||
<None Update="Assets\Landscape_Inverted.png">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Update="Assets\Landscape_Pixelate.png">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</None>
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
@@ -12,11 +12,17 @@ namespace ComputeSharp.D2D1Interop.Tests;
|
||||
public class EndToEndTests
|
||||
{
|
||||
[TestMethod]
|
||||
public unsafe void InvertEffectWithCustomThreshold()
|
||||
public unsafe void InvertWithCustomThreshold()
|
||||
{
|
||||
RunAndCompareShader(new InvertShader(1), "Landscape.png", "Landscape_Inverted.png");
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public unsafe void Pixelate()
|
||||
{
|
||||
RunAndCompareShader(new PixelateShader(new PixelateShader.Constants(1280, 720, 16)), "Landscape.png", "Landscape_Pixelate.png");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Executes a pixel shader and compares the expected results.
|
||||
/// </summary>
|
||||
@@ -67,4 +73,47 @@ public partial struct InvertShader : ID2D1PixelShader
|
||||
|
||||
return new(rgb, 1);
|
||||
}
|
||||
}
|
||||
|
||||
[D2DInputCount(1)]
|
||||
[D2DInputComplex(0)]
|
||||
[D2DRequiresScenePosition]
|
||||
[D2DEmbeddedBytecode(D2D1ShaderProfile.PixelShader40)]
|
||||
[AutoConstructor]
|
||||
public partial struct PixelateShader : ID2D1PixelShader
|
||||
{
|
||||
[AutoConstructor]
|
||||
public partial struct Constants
|
||||
{
|
||||
public readonly int inputWidth;
|
||||
public readonly int inputHeight;
|
||||
public readonly int cellSize;
|
||||
}
|
||||
|
||||
private readonly Constants constants;
|
||||
|
||||
public float4 Execute()
|
||||
{
|
||||
float2 scenePos = D2D1.GetScenePosition().XY;
|
||||
uint x = (uint)Hlsl.Floor(scenePos.X);
|
||||
uint y = (uint)Hlsl.Floor(scenePos.Y);
|
||||
|
||||
int cellX = (int)Hlsl.Floor(x / this.constants.cellSize);
|
||||
int cellY = (int)Hlsl.Floor(y / this.constants.cellSize);
|
||||
|
||||
int x0 = cellX * this.constants.cellSize;
|
||||
int y0 = cellY * this.constants.cellSize;
|
||||
|
||||
int x1 = Hlsl.Min(this.constants.inputWidth, x0 + this.constants.cellSize) - 1;
|
||||
int y1 = Hlsl.Min(this.constants.inputHeight, y0 + this.constants.cellSize) - 1;
|
||||
|
||||
float4 sample0 = D2D1.SampleInputAtPosition(0, new int2(x0, y0));
|
||||
float4 sample1 = D2D1.SampleInputAtPosition(0, new int2(x1, y0));
|
||||
float4 sample2 = D2D1.SampleInputAtPosition(0, new int2(x0, y1));
|
||||
float4 sample3 = D2D1.SampleInputAtPosition(0, new int2(x1, y1));
|
||||
|
||||
float4 color = (sample0 + sample1 + sample2 + sample3) / 4;
|
||||
|
||||
return color;
|
||||
}
|
||||
}
|
||||
新しいイシューから参照
ユーザーをブロックする