Shaders for Shadows
Shader code for rendering shadows of translucent occluders, soft shadows and single scattering with moment shadow maps.
|
This is an automatically generated documentation for the HLSL code that ships with the demo on moment shadow mapping and its many applications. We provide shader code only but several methods which would typically run on the CPU-side have been implemented in HLSL for reference.
We do not provide complete shaders because our application generates those on the fly for the countless possible combinations of techniques. However, the functions in the shaders provide all the relevant building blocks.
A few hints on where to start reading follow.
Since the implementation of this technique is as simple as rendering to a moment shadow map with alpha blending there is little code that is explicitly related to it. However, various methods come in a variant where they generate a vector of four moments and split it up onto two two-component vectors to use multiple render targets. Examples are ComputeMomentVector4MomentsOptimized_float2_float2() and ConvertSplit4MomentOptimizedToCanonical().
The moment-based blocker search is implemented in Compute4MomentAverageBlockerDepth().
Penumbra estimation for directional lights is implemented in EstimatePenumbraSize() with help from ComputeDirectionalLightSoftShadowParameters(). GetShadowFilterRectangle() turns the result into a filter region.
Hamburger four moment shadow mapping for evaluating the final shadow intensity is implemented in Compute4MomentUnboundedShadowIntensity(). The input moments typically go through Convert4MomentOptimizedToCanonical() to revert the affine quantization transform.
The compute shaders for generation of summed-area tables are implemented in ApplyPrefixSumHorizontal_uint4() and ApplyPrefixSumVertical_uint4(). Queries to the summed-area table with and without interpolation are implemented in ComputeRectangleAverage_uint4() and ComputeIntegerRectangleAverage_uint4(), respectively. ComputeFixedPrecision() takes care of computing the adequate factor for quantization.
The computation of rectified coordinates from world-space coordinates is implemented in ComputePrefilteredSingleScatteringCoordinatesNonLinearRectification(). This method uses outputs from GetRectifiedSpaceFrustumBounds() and ComputeRectificationToWorldSpaceDirectional().
Evaluation of the sparse representation of moments for filtering during resampling is implemented in GetSparseRepresentation4Moments(). This representation is turned into moments by GetMomentsFromSparseRectifiedRepresentation3_3(). Six moment shadow mapping is implemented in EstimateIntegralFrom6Moments().
Evaluation of the actual single scattering technique is implemented in ComputePrefilteredSingleScattering3_3Moments() with help from ComputeSingleScatteringRadiance(), ComputeSingleScatteringNoOcclusionDirectional(), ComputeSingleScatteringFactors() and ComputeAdaptiveOverestimationWeight().
The compute shader for generation of prefiltered moment shadow maps with six moments and without filtering is implemented in ApplyTransmittanceWeightedPrefixSumNonLinearRectificationMSM3_3().
You should find this documentation alongside an executable demo. For more information on how to explore this demo, please refer to the included ReadMe.pdf.