Graphics Reference
In-Depth Information
// Declare the filter kernel coefficients
static const float filter[7] = {
0.030078323, 0.104983664, 0.222250419, 0.285375187, 0.222250419,
0.104983664, 0.030078323
};
// Declare the group shared memory to hold the loaded data
groupshared float4 horizontalpoints[size_x];
// For the horizontal pass, use only a single row of threads
[numthreads(size_x, 1, 1)]
void CSMAINX( uint3 DispatchThreadID : SV_DispatchThreadID )
{
// Load the current data from input texture
float4 CenterColor = InputMap.Load( DispatchThreadID );
// Stor the data'vinto the GSM for the current thread
horizontalpoints[DispatchThreadID.x] = CenterColorj
// Synchronize all threads
GroupMemoryBarrierWithGroupSync( );
// Offset the texture location to the first sample location
int3 texturelocation = DispatchThreadID - int3( 3, 0, 0 );
// Range sigma value
const float rsigma = 0.051f;
float4 Color = 0.0f;
float4 Weight = 0.0f;
for ( int x = 0; x < 7; x++ )
{
// Get the current sample
float4 SampleColor = horizontalpoints[texturelocation.x + x];
// 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];
Weight += Range * filter[x];
}
// Store the renormalized result to the output resource
OutputMap[DispatchThreadID.xy] = Color / Weight;
Listing 10.5. A separable implementation of the bilateral filter.
Search WWH ::




Custom Search