Graphics Reference
In-Depth Information
Another simple example is applying a sepia tone to an image (sepia is a reddish brown color):
float4 sample = input[dispatchThreadId.xy];
float3 target;
target.r = saturate(dot(sample.rgb, float3(0.393, 0.769, 0.189)));
target.g = saturate(dot(sample.rgb, float3(0.349, 0.686, 0.168)));
target.b = saturate(dot(sample.rgb, float3(0.272, 0.534, 0.131)));
output[dispatchThreadId.xy]= lerpKeepAlpha(sample, target, LerpT);
See also
F The Implementing box blur using separable convolution filters recipe to learn how you
can apply multiple filters in sequence
Implementing box blur using separable
convolution filters.
So far we have implemented some simple color manipulation techniques. Now we will create
an image blur effect using a filter kernel. This technique will make more effective use of the
compute shader thread groups by utilizing group shared memory and thread synchronization.
Convolution filters can be used to apply a wide range of image processing effects, and among
these effects, a number of them are separable, meaning that a 2D filter can be split into two
1D filters: the first representing the horizontal aspect of the filter, and the second representing
the filter to be applied to the image vertically. These two 1D filters can then be processed in
any order to produce the same result as the original 2D filter; however, the total number of
texture reads required is significantly reduced.
How to do it…
Our blur operation will consist of two filters: horizontal and vertical blur filters that will be
applied one after the other to produce the final blur. By adjusting the weights, we will be
able to use the same shader for a box blur filter and a Gaussian blur filter.
There are faster methods of implementing box blur and Gaussian
blur filters; however, we can use the shader code presented here to
implement a range of separable convolution filters. For blurs with
smaller radiuses, a pixel shader version can be faster as we can take
advantage of the bilinear hardware.
 
Search WWH ::




Custom Search