Graphics Reference
In-Depth Information
void CSMAIN( uint3 GroupID : SV_GroupID, uint3 DispatchThreadID :
SV_DispatchThreadID, uint3 GroupThreadID : SV_GroupThreadID, uint GroupIndex
: SV_GroupIndex )
{
// Offset the texture location to the first sample location
int3 texturelocation = DispatchThreadlD - int3( 3, 3, 0 );
// Each thread will load its own depth/occlusion values
float4 CenterColor = InputMap.Load( DispatchThreadlD );
// Range sigma value
const float rsigma = 0.051f;
float4 Color = 0.0f;
float4 Weight = 0.0f;
for ( int x = 0; x < 7; x++ )
{
for ( int y = 0; y < 7; y++ )
{ // Get the current sample
float4 SampleColor = InputMap.Load( texturelocation + int3( x, y, 0 ) );
II Find the delta, and use that to calculate the range weighting
float4 Delta = CenterColor - SampleColor;
float4 Range = exp( ( -1.0f * Delta * Delta )
/ ( 2.0f * rsigma * rsigma ) );
// Sum both the color result and the total weighting used
Color += SampleColor * Range * filter[x][y];
Weight += Range * filter[x] [y];
}
}
// Store the renormalized result to the output resource
OutputMap[DispatchThreadID.xy] = Color / Weight;
}
Listing 10.4. The brute force bilateral filter implementation.
We can see from Listing 10.4 that the color-weighting factor is based on the delta
value between the center pixel and the sample pixel, which is then used as the input pa-
rameter to a Gaussian function. The spatial weights are precalculated in the same way we
saw in the Gaussian filter implementation, but they could just as easily be converted to be
dynamically calculated, or even provided in a constant buffer by the application. All of the
samples are looped through to build the overall weighted combination, and the total com-
bination of the weights that are applied to the samples is summed in the Weight variable.
This is then used to renormalize the summed output combination of the samples, producing
a final result that is written to the output resource through the unordered access view.
Search WWH ::




Custom Search