Graphics Reference
In-Depth Information
10.3.2 Implementation Design
The basic implementation setup for the bilateral filter is very similar to that of the Gaussian
filter. It will execute in the compute shader, with the input image bound with a shader re-
source view, and the resulting image will be bound with an unordered access view so the
shader program can write the appropriate data to it. We will consider how a simple brute
force implementation looks, and then later develop a more efficient approach.
Brute Force Approach
The straightforward technique is quite similar to the Gaussian method, with the exception
that the color-based weight value must be calculated and applied to each sample used in the
summation. In addition, we assume that the input color image will use all four channels and
will use float4 calculations throughout the shader to allow each channel to be processed
independently. For this naive implementation, each pixel will process a single output pixel,
and the thread groups will be arranged in the 32×32 sized groups once again. The imple-
mentation is shown in Listing 10.4.
// Declare the input and output resources
Texture2D<float4> InputMap : register( t0 );
RWTexture2D<float4> OutputMap : register( u0 );
// Group size
ttdefine size_x 32
#define size_y 32
// Declare the filter kernel coefficients
static const float filter[7][7] = {
0.000904706, 0.003157733, 0.00668492, 0.008583607, 0.00668492,
0.003157733, 0.000904706,
0.003157733, 0.01102157, 0.023332663, 0.029959733, 0.023332663,
0.01102157, 0.003157733,
0.00668492, 0.023332663, 0.049395249, 0.063424755, 0.049395249,
0.023332663, 0.00668492,
0.008583607, 0.029959733, 0.063424755, 0.081438997, 0.063424755,
0.029959733, 0.008583607,
0.00668492, 0.023332663, 0.049395249, 0.063424755, 0.049395249,
0.023332663, 0.00668492,
0.003157733, 0.01102157, 0.023332663, 0.029959733, 0.023332663,
0.01102157, 0.003157733,
0.000904706, 0.003157733, 0.00668492, 0.008583607, 0.00668492,
0.003157733, 0.000904706
};
II Declare one thread for each texel of the current block size.
[numthreads(size_x, size_y, 1)]
Search WWH ::




Custom Search