Graphics Reference
In-Depth Information
We'll begin with creating the horizontal blur compute shader.
1.
The start of our shader code will introduce the input and output resources as before
and in addition, we will use the #define macros to control the thread group size
and filter tap.
Texture2D<float4> input : register(t0);
RWTexture2D<float4> output : register(u0);
#define FILTERTAP 5 // Must be ODD
// Note: at a thread group size of 1024, the maximum
// FILTERTAP possible is 33
#define FILTERRADIUS ((FILTERTAP-1)/2)
#define THREADSX 1024
#define THREADSY 1
// The total group size (DX11 max 1024)
#define GROUPSIZE (THREADSX * THREADSY)
2.
Next, we will create our thread group shared memory. The shared memory needs to
be large enough to store the samples for a complete thread group. Border threads at
the start and end of the x axis for the thread group need to load an extra texel.
// Shared memory for storing thread group data for filters
// with enough room for
// GROUPSIZE + (THREADSY * FILTERRADIUS * 2)
// Max size of groupshared is 32KB
groupshared float4 FilterGroupMemX[GROUPSIZE + (THREADSY *
FILTERRADIUS*2)];
3. Our last global variable is the blur filter kernel. For now we will configure the kernel
as a simple box filter (where each texel under the kernel is given equal weight). It is
important to note that the kernel must be of the same size as the filter-tap specified
in FILTERTAP and that the middle element represents the kernel origin and
therefore, the current texel.
static const float BlurKernel[FILTERTAP] =
(float[FILTERTAP])(1.0/(FILTERTAP));
As we are only creating a 1D filter (for example, the horizontal and vertical filters are
separated), we are using a filter-tap x 1 convolution kernel . Here we have used a
shortcut to create the even weightings of a box filter by initializing the array with
1.0 / filter-tap. .
As a general rule, the sum of all elements in the kernel must
equal 1.0.
 
Search WWH ::




Custom Search