Graphics Reference
In-Depth Information
float ImageBasedHairAA ( float2 p0 , float2 p1 , float2 pixelLoc )
{ // p0, p1, pixelLoc are in d3d clip space ( 1to1)x( 1to1).
// p0 and p1 are the two nearest hair fiber edge positions
//
to the hair fragment being shaded.
// Scale positions so 1.f = half pixel width
p0 ￿ = g_WinSize . xy ;
p1 ￿ = g_WinSize . xy ;
pixelLoc ￿ = g_WinSize . xy ;
float p0dist = length ( p0 pixelLoc );
float p1dist = length ( p1 pixelLoc );
float hairWidth = length ( p0
p1 );
// will be 1. f if pixel outside hair , 0. f if pixel inside hair
float outside = any ( float2 ( step ( hairWidth , p0dist ),
step ( hairWidth , p1dist )) );
// i f outside , set sign to 1, else set sign to 1
float sign = outside > 0. f ?
1. f :1. f ;
// signed distance
//(positive if inside hair , negative if outside hair)
float relDist = sign ￿ saturate ( min ( p0dist , p1dist ));
// returns coverage based on the relative distance
// 0, if completely outside hair edge
// 1, if completely inside hair edge
return ( relDist +1. f ) ￿ 0.5 f ;
}
Listing 5.2. This is the function used to perform the image-based hair antialiasing
calculation. See Listing 5.1 to see where p0 and p1 are calculated.
ence of thin individual hair strands. Also, where each hair fragment has its
own lighting and shadowing applied separately, transparency is important for a
high-quality volumetric result.
Due to the large amount of geometry and high possibility of a large number
of transparent layers within a single pixel, dealing with correctly blending the
many transparent layers of hair becomes a challenge. The hair transparency
is handled through the use of Order Independent Transparency with per-pixel
linked lists [Thibieroz 11]. For every pixel on screen that has one or more layers
of hair, a linked list is generated containing each overlapping hair fragment.
The transparency for hair is handled by two separate passes. The first pass,
the A-Buffer Fill , generates the unsorted linked lists for each pixel on screen that
contains hair fragments. The second pass, Sort and Draw , traverses the per-pixel
linked lists, sorting and blending for the final hair pixel result [Yu et al. 12]. In the
rest of this section, we'll go through some of the specifics of the hair transparency
passes and how that works with per-pixel linked lists.
Search WWH ::




Custom Search