Graphics Reference
In-Depth Information
using (var vertCS = new ComputeShader(device, vertBC))
{
// The first source resource is the original image
context.ComputeShader.SetShaderResource(0,
srcTextureSRV);
// The first destination resource is target
context.ComputeShader.SetUnorderedAccessView(0,
targetUAV);
// Run the horizontal blur first (order doesn't matter)
context.ComputeShader.Set(horizCS);
context.Dispatch((int)Math.Ceiling(desc.Width /
1024.0
),
(int)Math.Ceiling(desc.Height /
1.0
), 1);
//
We must set the compute shader stage SRV and UAV to
//
null
between calls to the compute shader
context.ComputeShader.SetShaderResource(0, null);
context.ComputeShader.SetUnorderedAccessView(0, null);
// The second source resource is the first target
context.ComputeShader.SetShaderResource(0, targetSRV);
// The second destination resource is target2
context.ComputeShader.SetUnorderedAccessView(0,
target2UAV);
// Run the vertical blur
context.ComputeShader.Set(vertCS);
context.Dispatch((int)Math.Ceiling(desc.Width /
1.0
),
(int)Math.Ceiling(desc.Height /
1024.0
), 1);
// Set the compute shader stage SRV and UAV to null
context.ComputeShader.SetShaderResource(0, null);
context.ComputeShader.SetUnorderedAccessView(0, null);
}
An image processing renderer class (
ImageProcessingCS.cs
)
for running multiple filters and a utility class for implementing the
texture ping-pong (
TexturePingPong.cs
) is available within the
downloadable code for this chapter (
Ch07_01ImageProcessing
)
available on Packt's website.