Graphics Reference
In-Depth Information
Note that the number of groups in the x and y axes is determined by dividing the width
of the image by the x axis threads/group count, and the height of the image by the y axis
threads/group count. In this example, we only use a single slice (along the z axis).
The following diagram shows the compute shader thread addressing for a thread
group (large filled square) and a single thread (small filled square):
Compute shader thread addressing showing a thread group (large filled square) and a single thread
(small filled square)
To sample from the source texture, we are using the pixel coordinate rather than a normalized
UV coordinate (that is, for our 640x480 image we use 0-639 along the x axis rather than
0.0-1.0). This is done using the array access operator of the input texture input[] .
Because we have a single thread created for each pixel, the dispatchThreadId attribute
matches the appropriate pixel's XY coordinate for the input and output image (see the
previous diagram). As we are using a Texture2D variable rather than a StructureBuffer
or RawStructuredBuffer variable for the input texture, we are still taking advantage of the
texture-fetch hardware, which converts the image pixel RGBA data to a float4 variable:
float4 sample = input[dispatchThreadId.xy];
Next, we determine the pixel's relative luminance (Y) by calculating the dot product of the
linear RGB components with the appropriate coefficients (these depend on the colors that
contribute the most to light intensity for the human eye and are based upon the ITU-R
Recommendation BT.709):
Y = R * 0.2125 + G * 0.7154 + B * 0.0721;
Y = dot(sample.rgb, float3(0.2125,0.7154,0.0721));
 
Search WWH ::




Custom Search