
174 II Lighting and Shading
4.5.3 Ray-Tracing Pass
The implementation in Listing 4.5 is the Hi-Z ray-tracing code in Microsoft HLSL.
The code snippet is heavily commented and should be easy to follow once the
algorithm presented in Section 4.4.3 is clear.
float3 hiZTrace( float3 p , float3 v )
{
const float rootLevel = mipCount − 1.0f ; // Convert to 0
// based indexing
float level = HIZ_START_LEVEL ; // HIZ START LEVEL was
// set to 2 in the demo
float iterations =0.0f ;
// Get the cell cross direction and a small offset to enter
// the next cell when doing cell crossing.
float2 crossStep , crossOffset ;
crossStep . x =( v . x >=0 ) ? 1.f : −1.f ;
crossStep ...