Shaders for Shadows
Shader code for rendering shadows of translucent occluders, soft shadows and single scattering with moment shadow maps.
|
Go to the source code of this file.
Macros | |
#define | TEXEL_TYPE float2 |
#define | TEXEL_TYPE float3 |
#define | TEXEL_TYPE float4 |
Functions | |
float3 | RectifiedToCartesian (float Distance, float Inclination, float Azimuth) |
void | CartesianToRectified (out float OutDistance, out float OutInclination, out float OutAzimuth, float3 CartesianCoordinates) |
void | GetSparseRepresentation4Moments (out float2 OutDepth, out float OutWeight1, float4 OptimizedMoments) |
float | EstimateIntegralFrom4Moments (float IntervalEnd, float4 OptimizedMoments, float MomentBias, float OverestimationWeight) |
float3 | GetRoots (float4 Coefficient) |
float | EstimateIntegralFrom6Moments (float IntervalEnd, float2 OptimizedMoments0, float4 OptimizedMoments1, float MomentBias, float OverestimationWeight) |
float | ComputeTexelTransmittance (uint ShadowMapWidth, float ExtinctionCoefficient, float2 DistanceMinMax, float2 InclinationMinMax) |
void | PrepareShadowMapRowResampling (out float3 OutTextureSpaceRayStart, out float3 OutTextureSpaceRayOffset, out float2 OutInclinationToDepthTransform, out float OutOffsetLength, out float OutInitialOffsetLength, out float OutTexelTransmittance, uint2 OutputShadowMapResolution, uint iShadowMapRow, float ExtinctionCoefficient, float4x4 RectificationToShadowMapProjectionSpace, float2 DistanceMinMax, float2 InclinationMinMax, float2 AzimuthMinMax) |
float | ConvertShadowMapDepthNonLinearRectification (float ShadowMapDepth, float2 ShadowMapToRectificationDepthTransform, float2 InclinationToDepthTransform, float TotalOffsetLength) |
void | Convert4MomentCanonicalToOptimized (out float4 OutQuantizedMoments0, float4 CanonicalMoments0) |
void | ComputeMomentVector4MomentsOptimized (out float4 OutQuantizedMoments0, float Depth) |
void | Convert6MomentCanonicalToOptimized (out float2 OutQuantizedMoments0, out float4 OutQuantizedMoments1, float2 CanonicalMoments0, float4 CanonicalMoments1) |
void | ComputeMomentVector6MomentsOptimized (out float2 OutQuantizedMoments0, out float4 OutQuantizedMoments1, float Depth) |
void | ApplyTransmittanceWeightedPrefixSum (inout RWTexture2D< TEXEL_TYPE > OutFilteredShadowMap, Texture2D< TEXEL_TYPE > FilterableShadowMap, uint iThreadX, uint iThreadY, float TexelTransmittance) |
This header defines utility functions that help to avoid code duplication among different techniques for integrating single scattering in participating media.
Definition in file ParticipatingMediaUtility.fx.
void ApplyTransmittanceWeightedPrefixSum | ( | inout RWTexture2D< TEXEL_TYPE > | OutFilteredShadowMap, |
Texture2D< TEXEL_TYPE > | FilterableShadowMap, | ||
uint | iThreadX, | ||
uint | iThreadY, | ||
float | TexelTransmittance | ||
) |
This function generates a transmittance-weighted prefix sum for an already rectified filterable shadow map. It only writes to every eights texel in its row and thus implements a single thread of a thread group of width 8.
OutFilteredShadowMap | The texture to which the output is written. |
FilterableShadowMap | The rectified, filterable shadow map from which the input is read. It must have resolution identical to OutFilteredShadowMap. |
iThreadX | The thread will write to columns of the form 8*x+iThreadX where x iterates over all integers yielding a coordinate within the texture. |
iThreadY | The index of the row from which the function will read and to which it will write. |
TexelTransmittance | The source texel in column x is weighted by TexelTransmittance^x. Output values are divided by the total weight of the prefix sum. See ComputeTexelTransmittance(). |
Definition at line 417 of file ParticipatingMediaUtility.fx.
void CartesianToRectified | ( | out float | OutDistance, |
out float | OutInclination, | ||
out float | OutAzimuth, | ||
float3 | CartesianCoordinates | ||
) |
This function converts the given position in Cartesian coordinates of rectification space into rectified coordinates. It is a right inverse of RectifiedToCartesian().
OutDistance | The non-negative distance from the origin after projecting to the z=0 plane. |
OutInclination | The angle to the z-axis in radians from zero to pi. |
OutAzimuth | The planar angle to the x-axis in radians from zero to two pi. |
CartesianCoordinates | The Cartesian coordinates that are to be converted. |
Definition at line 25 of file ParticipatingMediaUtility.fx.
void ComputeMomentVector4MomentsOptimized | ( | out float4 | OutQuantizedMoments0, |
float | Depth | ||
) |
Converts a given depth value to a vector encoding four moments of a Dirac-delta distribution at this depth. An affine transform is applied to the moments to prepare them for storage in a texture with minimal loss of information due to quantization.
Definition at line 362 of file ParticipatingMediaUtility.fx.
void ComputeMomentVector6MomentsOptimized | ( | out float2 | OutQuantizedMoments0, |
out float4 | OutQuantizedMoments1, | ||
float | Depth | ||
) |
Converts a given depth value to a vector encoding six moments of a Dirac-delta distribution at this depth. The moments are output as two vectors and an affine transform is applied to them to prepare them for storage in a texture with minimal loss of information due to quantization.
Definition at line 393 of file ParticipatingMediaUtility.fx.
float ComputeTexelTransmittance | ( | uint | ShadowMapWidth, |
float | ExtinctionCoefficient, | ||
float2 | DistanceMinMax, | ||
float2 | InclinationMinMax | ||
) |
This function computes the amount of light that is transmitted through one texel of a rectified shadow map horizontally at depth zero.
ShadowMapWidth | The width of the shadow map in texels. |
ExtinctionCoefficient | The extinction coefficient of the participating media. |
DistanceMinMax,InclinationMinMax | See GetRectifiedSpaceFrustumBounds(). |
Definition at line 277 of file ParticipatingMediaUtility.fx.
void Convert4MomentCanonicalToOptimized | ( | out float4 | OutQuantizedMoments0, |
float4 | CanonicalMoments0 | ||
) |
Applies the optimized quantization transform to the given four power moments.
Definition at line 352 of file ParticipatingMediaUtility.fx.
void Convert6MomentCanonicalToOptimized | ( | out float2 | OutQuantizedMoments0, |
out float4 | OutQuantizedMoments1, | ||
float2 | CanonicalMoments0, | ||
float4 | CanonicalMoments1 | ||
) |
Applies the optimized quantization transform to the given six power moments.
Definition at line 369 of file ParticipatingMediaUtility.fx.
float ConvertShadowMapDepthNonLinearRectification | ( | float | ShadowMapDepth, |
float2 | ShadowMapToRectificationDepthTransform, | ||
float2 | InclinationToDepthTransform, | ||
float | TotalOffsetLength | ||
) |
This function converts a depth taken from a shadow map and maps it to a depth value as used for non-linear rectification.
ShadowMapDepth | The depth value obtained from the shadow map mapped into the interval [-1,1]. |
ShadowMapToRectificationDepthTransform,InclinationToDepthTransform | See PrepareShadowMapRowResampling(). |
TotalOffsetLength | The number of times the offset has been applied to the ray start times the length of the offset as generated by PrepareShadowMapRowResampling(). |
Definition at line 344 of file ParticipatingMediaUtility.fx.
float EstimateIntegralFrom4Moments | ( | float | IntervalEnd, |
float4 | OptimizedMoments, | ||
float | MomentBias, | ||
float | OverestimationWeight | ||
) |
Estimates the integral of a probability distribution from minus infinity to a fixed point and returns it.
IntervalEnd | The end of the integration interval. |
OptimizedMoments | Power moments one to four of the distribution stored in a a manner that is optimized for little quantization errors. |
MomentBias | The strength of the bias that serves to compensate quantization errors (e.g. 6*10^-5). |
OverestimationWeight | If this value is zero, the function underestimates the integral. If it is one, it overestimates. Inbetween linear interpolation is employed. |
Definition at line 77 of file ParticipatingMediaUtility.fx.
float EstimateIntegralFrom6Moments | ( | float | IntervalEnd, |
float2 | OptimizedMoments0, | ||
float4 | OptimizedMoments1, | ||
float | MomentBias, | ||
float | OverestimationWeight | ||
) |
Like EstimateIntegralFrom4Moments() but uses six moments which have been stored in a manner that is optimized for small quantization error.
Definition at line 175 of file ParticipatingMediaUtility.fx.
float3 GetRoots | ( | float4 | Coefficient | ) |
Given the coefficients of a real, cubic polynomial Coefficient[0] +x*Coefficient[1]+x*x*Coefficient[2]+x*x*x*Coefficient[3] this function computes all of its roots and returns them.
Definition at line 138 of file ParticipatingMediaUtility.fx.
void GetSparseRepresentation4Moments | ( | out float2 | OutDepth, |
out float | OutWeight1, | ||
float4 | OptimizedMoments | ||
) |
This function constructs a linear combination of two Dirac-delta distributions which matches three given moments.
OutDepth | The locations of the Dirac-delta distributions. They are sorted. |
OutWeight1 | The weight of the second Dirac-delta. The weights add up to one. |
OptimizedMoments | Four moments stored in a manner that is optimized for quantization. The fourth moment is not used. |
Definition at line 40 of file ParticipatingMediaUtility.fx.
void PrepareShadowMapRowResampling | ( | out float3 | OutTextureSpaceRayStart, |
out float3 | OutTextureSpaceRayOffset, | ||
out float2 | OutInclinationToDepthTransform, | ||
out float | OutOffsetLength, | ||
out float | OutInitialOffsetLength, | ||
out float | OutTexelTransmittance, | ||
uint2 | OutputShadowMapResolution, | ||
uint | iShadowMapRow, | ||
float | ExtinctionCoefficient, | ||
float4x4 | RectificationToShadowMapProjectionSpace, | ||
float2 | DistanceMinMax, | ||
float2 | InclinationMinMax, | ||
float2 | AzimuthMinMax | ||
) |
This is a helper function for functions generating transmittance weighted shadow maps with resampling of a shadow map for non-linear rectification. It precomputes various useful quantities that can be prepared before entering a loop over a row of a shadow map.
OutTextureSpaceRayStart,OutTextureSpaceRayOffset | Coordinates defining the ray which is to be traced in the source shadow map. OutTextureSpaceRayStart correspons to the left-most texel. They use projective coordinates, you should divide by z to get the texture coordinate in xy. |
OutInclinationToDepthTransform | A linear transform mapping inclination in radians to a value that can be used as depth value for the rectified shadow map. |
OutTexelTransmittance | See ComputeTexelTransmittance(). |
OutputShadowMapResolution | The resolution of the shadow map in which prefix sums will be stored. |
iShadowMapRow | The index of the row in the output shadow map (i.e. the non-negative integer y-coordinate). |
ExtinctionCoefficient | The extinction coefficient of the participating media. |
RectificationToShadowMapProjectionSpace | See ApplyTransmittanceWeightedPrefixSumNonLinearRectificationMSM4(). |
DistanceMinMax,InclinationMinMax,AzimuthMinMax | See GetRectifiedSpaceFrustumBounds(). |
Definition at line 306 of file ParticipatingMediaUtility.fx.
float3 RectifiedToCartesian | ( | float | Distance, |
float | Inclination, | ||
float | Azimuth | ||
) |
Converts the given rectified coordinates to Cartesian coordinates in rectification space and returns the result.
Definition at line 8 of file ParticipatingMediaUtility.fx.