Graphics Reference
In-Depth Information
// Read roughness from a render target and convert to a BRDF
// specular power .
float specularPower = roughnessToSpecularPower ( roughness );
// Depending on what BRDF used , convert to cone angle . Cone
// angle is maximum extent of the specular lobe aperture .
float coneTheta
= specularPowerToConeAngle (
specularPower );
// Cone
trace using an isosceles triangle to approximate a cone
// in screen space
for ( int i =0; i < 7; ++ i )
{
// Intersection length is the adjacent side , get the opposite
// side using trigonometry
float oppositeLength = isoscelesTriangleOpposite (
adjacentLength , coneTheta );
// Calculate in radius of the isosceles triangle now
float incircleSize = isoscelesTriangleInradius (
adjacentLength , oppositeLength );
// Get the sample position in screen space
float2 samplePos
= screenPos . xy + adjacentUnit ￿
( adjacentLength
incircleSize );
// Convert the in radius into screen size (960x540) and then
// check what power N we have to raise 2 to reach it .
// That power N becomes our mip level to sample from.
float mipChannel = log2 ( incircleSize ￿
max ( screenSize . x , screenSize . y ));
// Read color and accumulate it using trilinear filtering
// (blending in xy and mip direction) and weight it .
// Uses pre convolved image and pre−i integrated transparency
// buffer and Hi
Z buffer . It checks if cone sphere is below,
// in between , or above the Hi Z minimum and maxamimum and
// weights it together with transparency.
// Visibility is accumulated in the alpha channel .
totalColor += coneSampleWeightedColor ( samplePos , mipChannel
);
if ( totalColor . a > 1.0 f )
break ;
// Calculate next smaller triangle that approximates the cone
// in screen space .
adjacentLength = isoscelesTriangleNextAdjacent (
adjacentLength , incircleSize );
}
Listing 4.7. Again the full implementation of some of the functions is not shown
because of code length. The demo code available online has the full implementation;
the demo also comes with alternative toggle-able code for accumulating the colors such
as basic averaging, distance-based weighting, and hierarchical pre-integrated visibility
buffer weighting.
Search WWH ::




Custom Search