Shaders for Shadows
Shader code for rendering shadows of translucent occluders, soft shadows and single scattering with moment shadow maps.
 All Classes Files Functions Variables Pages
Functions
ParticipatingMedia.fx File Reference
#include "RandomNumbers.fx"
#include "ParticipatingMediaUtility.fx"

Go to the source code of this file.

Functions

void ComputeRectificationToWorldSpaceDirectional (out float4x4 OutRectificationToWorldSpace, float3 WorldSpaceCameraPosition, float4x4 ShadowMapViewToWorldSpace)
 
void GetRectifiedSpaceFrustumBounds (out float2 OutDistanceMinMax, out float2 OutInclinationMinMax, out float2 OutAzimuthMinMax, float4x4 CameraProjectionToWorldSpace, float4x4 CameraWorldToProjectionSpace, float4x4 RectificationToWorldSpace, float4x4 WorldToRectificationSpace)
 
void ComputeExtinctionCoefficient (out float OutExtinctionCoefficient, float HalfOpacityDistance)
 
void ComputeViewRayLengthFromWorldSpace (out float OutViewRayLength, float3 WorldSpacePosition, float3 WorldSpaceCameraPosition)
 
void ApplyAbsorptionToOutgoingRadiance (out float3 OutReceivedRadiance, float3 OutgoingRadiance, float ViewRayLength, float ExtinctionCoefficient)
 
void ComputeViewRayFromProjectionSpace (out float OutViewRayLength, out float3 OutWorldSpaceRayStart, out float3 OutWorldSpaceRayEnd, float2 TexCoord, float PerspectiveDepth, float4x4 ProjectionToViewSpace, float4x4 ViewToWorldSpace)
 
void ComputeSingleScatteringFactors (out float3 OutPhaseTimesAlbedoTimesIrradiance, float3 PhaseTimesAlbedo, float3 DirectionalLightIrradiance)
 
void ComputeSingleScatteringRadiance (out float3 OutScatteringRadiance, float ScatteringIntegral, float3 PhaseTimesAlbedoTimesIrradiance)
 
void ComputeScatteringColor (out float4 OutScatteringColor, float3 ScatteringRadiance)
 
void ComputeSingleScatteringNoOcclusionDirectional (out float OutScatteringIntegral, float ViewRayLength, float ExtinctionCoefficient)
 
void ComputeSingleScatteringRayMarchingDirectional (out float OutScatteringIntegral, float ViewRayLength, float3 WorldSpaceViewRayStart, float3 WorldSpaceViewRayEnd, SSamplerTexturePair2D_float ShadowMapSampler, float4x4 ShadowMapWorldToProjectionSpace, float ExtinctionCoefficient, int nSample)
 
void ComputePrefilteredSingleScatteringCoordinatesNonLinearRectification (out float2 OutRayEndTexCoord, out float OutRayDepth, float3 WorldSpaceViewRayEnd, float4x4 WorldToRectificationSpace, float2 DistanceMinMax, float2 InclinationMinMax, float2 AzimuthMinMax)
 
void ComputePrefilteredSingleScatteringConvolution8 (out float OutScatteringIntegral, float2 RayEndTexCoord, float RayDepth, float ScatteringIntegralWithoutOcclusion, SSamplerTexturePair2D ShadowMapSampler0, SSamplerTexturePair2D ShadowMapSampler1, SSamplerTexturePair2D ShadowMapSampler2, SSamplerTexturePair2D ShadowMapSampler3)
 
void ComputePrefilteredSingleScatteringConvolution16 (out float OutScatteringIntegral, float2 RayEndTexCoord, float RayDepth, float ScatteringIntegralWithoutOcclusion, SSamplerTexturePair2D ShadowMapSampler0, SSamplerTexturePair2D ShadowMapSampler1, SSamplerTexturePair2D ShadowMapSampler2, SSamplerTexturePair2D ShadowMapSampler3, SSamplerTexturePair2D ShadowMapSampler4, SSamplerTexturePair2D ShadowMapSampler5, SSamplerTexturePair2D ShadowMapSampler6, SSamplerTexturePair2D ShadowMapSampler7)
 
void ComputeAdaptiveOverestimationWeight (out float OutOverestimationWeight, float3 WorldSpaceViewRayStart, float3 WorldSpaceViewRayEnd, float3 WorldSpaceLightDirection, float2 OverestimationWeightMinMax)
 
void ComputePrefilteredSingleScattering4Moments (out float OutScatteringIntegral, float2 RayEndTexCoord, float RayDepth, float ScatteringIntegralWithoutOcclusion, SSamplerTexturePair2D ShadowMapSampler0, float MomentBias, float OverestimationWeight=0.5f)
 
void ComputePrefilteredSingleScattering2_4Moments (out float OutScatteringIntegral, float2 RayEndTexCoord, float RayDepth, float ScatteringIntegralWithoutOcclusion, SSamplerTexturePair2D_float2 ShadowMapSampler0, SSamplerTexturePair2D ShadowMapSampler1, float MomentBias, float OverestimationWeight=0.5f)
 
void ComputePrefilteredSingleScattering3_3Moments (out float OutScatteringIntegral, float2 RayEndTexCoord, float RayDepth, float ScatteringIntegralWithoutOcclusion, SSamplerTexturePair2D_float3 ShadowMapSampler0, SSamplerTexturePair2D_float3 ShadowMapSampler1, float MomentBias, float OverestimationWeight=0.5f)
 
void GetPrefixSumThreadGroupCount (out uint3 nOutThreadGroup, uint3 ThreadGroupSize, uint nPrefixSumShadowMap, float4 TextureSize)
 
void GetShadowMapToRectificationDepthTransform (out float2 OutShadowMapToRectificationDepthTransform, float4x4 RectificationToShadowMapProjectionSpace)
 
void GetRectifiedDepth (out float OutRectifiedDepth, SSamplerTexturePair2D_float ShadowMapSampler0, float2 RectifiedTexCoord, float4x4 RectificationToShadowMapProjectionSpace, float2 ShadowMapToRectificationDepthTransform, float2 DistanceMinMax, float2 InclinationMinMax, float2 AzimuthMinMax)
 
void GetSparseRectifiedRepresentation (out float2 OutRectifiedDepth, out float OutDepthWeight1, SSamplerTexturePair2D ShadowMapSampler0, float2 RectifiedTexCoord, float4x4 RectificationToShadowMapProjectionSpace, float2 ShadowMapToRectificationDepthTransform, float2 DistanceMinMax, float2 InclinationMinMax, float2 AzimuthMinMax)
 
void GetMomentsFromDepth4 (out float4 OutQuantizedMoments0, float RectifiedDepth)
 
void GetMomentsFromSparseRectifiedRepresentation4 (out float4 OutQuantizedMoments0, float2 RectifiedDepth, float DepthWeight1)
 
void GetMomentsFromDepth3_3 (out float3 OutQuantizedMoments0, out float3 OutQuantizedMoments1, float RectifiedDepth)
 
void GetMomentsFromSparseRectifiedRepresentation3_3 (out float3 OutQuantizedMoments0, out float3 OutQuantizedMoments1, float2 RectifiedDepth, float DepthWeight1)
 
void GetMomentsFromDepth2_4 (out float2 OutQuantizedMoments0, out float4 OutQuantizedMoments1, float RectifiedDepth)
 
void GetMomentsFromSparseRectifiedRepresentation2_4 (out float2 OutQuantizedMoments0, out float4 OutQuantizedMoments1, float2 RectifiedDepth, float DepthWeight1)
 
void ApplyTransmittanceWeightedPrefixSumNonLinearRectificationCSM8 (inout RWTexture2D< float4 > OutFilteredShadowMap0, inout RWTexture2D< float4 > OutFilteredShadowMap1, inout RWTexture2D< float4 > OutFilteredShadowMap2, inout RWTexture2D< float4 > OutFilteredShadowMap3, SSamplerTexturePair2D ShadowMapSampler0, SSamplerTexturePair2D ShadowMapSampler1, SSamplerTexturePair2D ShadowMapSampler2, SSamplerTexturePair2D ShadowMapSampler3, uint3 ThreadID, float ExtinctionCoefficient, float2 DistanceMinMax, float2 InclinationMinMax)
 
void ApplyTransmittanceWeightedPrefixSumNonLinearRectificationCSM16 (inout RWTexture2D< float4 > OutFilteredShadowMap0, inout RWTexture2D< float4 > OutFilteredShadowMap1, inout RWTexture2D< float4 > OutFilteredShadowMap2, inout RWTexture2D< float4 > OutFilteredShadowMap3, inout RWTexture2D< float4 > OutFilteredShadowMap4, inout RWTexture2D< float4 > OutFilteredShadowMap5, inout RWTexture2D< float4 > OutFilteredShadowMap6, inout RWTexture2D< float4 > OutFilteredShadowMap7, SSamplerTexturePair2D ShadowMapSampler0, SSamplerTexturePair2D ShadowMapSampler1, SSamplerTexturePair2D ShadowMapSampler2, SSamplerTexturePair2D ShadowMapSampler3, SSamplerTexturePair2D ShadowMapSampler4, SSamplerTexturePair2D ShadowMapSampler5, SSamplerTexturePair2D ShadowMapSampler6, SSamplerTexturePair2D ShadowMapSampler7, uint3 ThreadID, float ExtinctionCoefficient, float2 DistanceMinMax, float2 InclinationMinMax)
 
void ApplyTransmittanceWeightedPrefixSumNonLinearRectificationMSM4 (inout RWTexture2D< float4 > OutFilteredShadowMap0, SSamplerTexturePair2D ShadowMapSampler0, uint3 ThreadID, float ExtinctionCoefficient, float2 DistanceMinMax, float2 InclinationMinMax)
 
void ApplyTransmittanceWeightedPrefixSumNonLinearRectificationMSM2_4 (inout RWTexture2D< float2 > OutFilteredShadowMap0, inout RWTexture2D< float4 > OutFilteredShadowMap1, SSamplerTexturePair2D_float2 ShadowMapSampler0, SSamplerTexturePair2D ShadowMapSampler1, uint3 ThreadID, float ExtinctionCoefficient, float2 DistanceMinMax, float2 InclinationMinMax)
 
void ApplyTransmittanceWeightedPrefixSumNonLinearRectificationMSM3_3 (inout RWTexture2D< float3 > OutFilteredShadowMap0, inout RWTexture2D< float3 > OutFilteredShadowMap1, SSamplerTexturePair2D_float3 ShadowMapSampler0, SSamplerTexturePair2D_float3 ShadowMapSampler1, uint3 ThreadID, float ExtinctionCoefficient, float2 DistanceMinMax, float2 InclinationMinMax)
 
void GetPerspectiveDepth1 (out float OutPerspectiveDepth, Texture2DMS< float, 1 > DepthStencilTexture, int2 TexelIndex)
 
void GetPerspectiveDepth2 (out float OutPerspectiveDepth, Texture2DMS< float, 2 > DepthStencilTexture, int2 TexelIndex)
 
void GetPerspectiveDepth4 (out float OutPerspectiveDepth, Texture2DMS< float, 4 > DepthStencilTexture, int2 TexelIndex)
 
void GetPerspectiveDepth8 (out float OutPerspectiveDepth, Texture2DMS< float, 8 > DepthStencilTexture, int2 TexelIndex)
 

Detailed Description

This file defines functions to define and render render participating media. Most notably absorption and single scattering can be rendered.

Definition in file ParticipatingMedia.fx.

Function Documentation

void ApplyAbsorptionToOutgoingRadiance ( out float3  OutReceivedRadiance,
float3  OutgoingRadiance,
float  ViewRayLength,
float  ExtinctionCoefficient 
)

This function converts an outgoing radiance to an incoming radiance by taking the attenuation due to absorption and outscattering in homogeneous participating media into account.

Parameters
OutReceivedRadianceThe radiance at the end of the considered ray.
OutgoingRadianceThe radiance at the beginning of the ray.
ViewRayLengthThe length of the considered ray.
ExtinctionCoefficientThe extinction coefficient.

Definition at line 201 of file ParticipatingMedia.fx.

void ApplyTransmittanceWeightedPrefixSumNonLinearRectificationCSM16 ( inout RWTexture2D< float4 >  OutFilteredShadowMap0,
inout RWTexture2D< float4 >  OutFilteredShadowMap1,
inout RWTexture2D< float4 >  OutFilteredShadowMap2,
inout RWTexture2D< float4 >  OutFilteredShadowMap3,
inout RWTexture2D< float4 >  OutFilteredShadowMap4,
inout RWTexture2D< float4 >  OutFilteredShadowMap5,
inout RWTexture2D< float4 >  OutFilteredShadowMap6,
inout RWTexture2D< float4 >  OutFilteredShadowMap7,
SSamplerTexturePair2D  ShadowMapSampler0,
SSamplerTexturePair2D  ShadowMapSampler1,
SSamplerTexturePair2D  ShadowMapSampler2,
SSamplerTexturePair2D  ShadowMapSampler3,
SSamplerTexturePair2D  ShadowMapSampler4,
SSamplerTexturePair2D  ShadowMapSampler5,
SSamplerTexturePair2D  ShadowMapSampler6,
SSamplerTexturePair2D  ShadowMapSampler7,
uint3  ThreadID,
float  ExtinctionCoefficient,
float2  DistanceMinMax,
float2  InclinationMinMax 
)

Like ApplyTransmittanceWeightedPrefixSumNonLinearRectificationMSM4() but operates on a convolution shadow map with 16 complex Fourier coefficients.

Definition at line 716 of file ParticipatingMedia.fx.

void ApplyTransmittanceWeightedPrefixSumNonLinearRectificationCSM8 ( inout RWTexture2D< float4 >  OutFilteredShadowMap0,
inout RWTexture2D< float4 >  OutFilteredShadowMap1,
inout RWTexture2D< float4 >  OutFilteredShadowMap2,
inout RWTexture2D< float4 >  OutFilteredShadowMap3,
SSamplerTexturePair2D  ShadowMapSampler0,
SSamplerTexturePair2D  ShadowMapSampler1,
SSamplerTexturePair2D  ShadowMapSampler2,
SSamplerTexturePair2D  ShadowMapSampler3,
uint3  ThreadID,
float  ExtinctionCoefficient,
float2  DistanceMinMax,
float2  InclinationMinMax 
)

Like ApplyTransmittanceWeightedPrefixSumNonLinearRectificationMSM4() but operates on a convolution shadow map with eight complex Fourier coefficients.

Definition at line 693 of file ParticipatingMedia.fx.

void ApplyTransmittanceWeightedPrefixSumNonLinearRectificationMSM2_4 ( inout RWTexture2D< float2 >  OutFilteredShadowMap0,
inout RWTexture2D< float4 >  OutFilteredShadowMap1,
SSamplerTexturePair2D_float2  ShadowMapSampler0,
SSamplerTexturePair2D  ShadowMapSampler1,
uint3  ThreadID,
float  ExtinctionCoefficient,
float2  DistanceMinMax,
float2  InclinationMinMax 
)

Like ApplyTransmittanceWeightedPrefixSumNonLinearRectificationMSM4() but operates on textures storing six power moments in two textures, one with two and one with four channels (useful for 16- or 32-bit quantization). The inputs are supposed to be rectified already, so no coordinate conversion is performed.

Definition at line 776 of file ParticipatingMedia.fx.

void ApplyTransmittanceWeightedPrefixSumNonLinearRectificationMSM3_3 ( inout RWTexture2D< float3 >  OutFilteredShadowMap0,
inout RWTexture2D< float3 >  OutFilteredShadowMap1,
SSamplerTexturePair2D_float3  ShadowMapSampler0,
SSamplerTexturePair2D_float3  ShadowMapSampler1,
uint3  ThreadID,
float  ExtinctionCoefficient,
float2  DistanceMinMax,
float2  InclinationMinMax 
)

Like ApplyTransmittanceWeightedPrefixSumNonLinearRectificationMSM2_4() but stores the six moments in two three-channel textures (useful for 10-bit quantization).

Definition at line 793 of file ParticipatingMedia.fx.

void ApplyTransmittanceWeightedPrefixSumNonLinearRectificationMSM4 ( inout RWTexture2D< float4 >  OutFilteredShadowMap0,
SSamplerTexturePair2D  ShadowMapSampler0,
uint3  ThreadID,
float  ExtinctionCoefficient,
float2  DistanceMinMax,
float2  InclinationMinMax 
)

Generates transmittance weighted prefix sums for the given four moment shadow map. The moment shadow map is supposed to be rectified, i.e. the texture coordinates and depths refer to the coordinate system produced by ComputePrefilteredSingleScatteringCoordinatesNonLinearRectification(). Transmittance weighting means that summands are weighted by their (approximate) contribution to the single scattering integral.

Parameters
OutFilteredShadowMap0The texture which is to be overwritten by weighted prefix sums of moments.
ShadowMapSampler0A texture and sampler providing access to a rectified four moment shadow map for which prefix sums should be generated.
ThreadIDThe y component of this vector indicates the row on which to operate.
ExtinctionCoefficientThe extinction coefficient of the participating media.
DistanceMinMax,InclinationMinMaxSee GetRectifiedSpaceFrustumBounds().

Definition at line 764 of file ParticipatingMedia.fx.

void ComputeAdaptiveOverestimationWeight ( out float  OutOverestimationWeight,
float3  WorldSpaceViewRayStart,
float3  WorldSpaceViewRayEnd,
float3  WorldSpaceLightDirection,
float2  OverestimationWeightMinMax 
)

This function computes an adaptive overestimation weight to avoid common artifacts at epipoles. It works for directional light sources only. When looking directly into the light minimal overestimation is used, when looking directly away from the light maximal overestimation is used (on a per pixel basis). In between a continuous and monotonous function of inclination is used.

Parameters
OutOverestimationWeightZero if single scattering is to be underestimated. One if single scattering is to be overestimated. In between radiance is interpolated linearly.
WorldSpaceViewRayStart,WorldSpaceViewRayEndThe endpoints of the view ray in world space coordinates.
WorldSpaceLightDirectionThe normalized world space light direction of the directional light.
OverestimationWeightMinMaxThe minimal possible overestimation weight in x, the maximal weight in y.

Definition at line 474 of file ParticipatingMedia.fx.

void ComputeExtinctionCoefficient ( out float  OutExtinctionCoefficient,
float  HalfOpacityDistance 
)

This function computes the extinction coefficient of participating media from the given half opacity distance.

Definition at line 182 of file ParticipatingMedia.fx.

void ComputePrefilteredSingleScattering2_4Moments ( out float  OutScatteringIntegral,
float2  RayEndTexCoord,
float  RayDepth,
float  ScatteringIntegralWithoutOcclusion,
SSamplerTexturePair2D_float2  ShadowMapSampler0,
SSamplerTexturePair2D  ShadowMapSampler1,
float  MomentBias,
float  OverestimationWeight = 0.5f 
)

Like ComputePrefilteredSingleScattering4Moments() but uses six moments.

Definition at line 509 of file ParticipatingMedia.fx.

void ComputePrefilteredSingleScattering3_3Moments ( out float  OutScatteringIntegral,
float2  RayEndTexCoord,
float  RayDepth,
float  ScatteringIntegralWithoutOcclusion,
SSamplerTexturePair2D_float3  ShadowMapSampler0,
SSamplerTexturePair2D_float3  ShadowMapSampler1,
float  MomentBias,
float  OverestimationWeight = 0.5f 
)

Like ComputePrefilteredSingleScattering4Moments() but uses six moments.

Definition at line 518 of file ParticipatingMedia.fx.

void ComputePrefilteredSingleScattering4Moments ( out float  OutScatteringIntegral,
float2  RayEndTexCoord,
float  RayDepth,
float  ScatteringIntegralWithoutOcclusion,
SSamplerTexturePair2D  ShadowMapSampler0,
float  MomentBias,
float  OverestimationWeight = 0.5f 
)

This function evaluates the scattering integral resolving occlusions by means of a rectified moment shadow map holding weighted prefix sums of rows.

Parameters
OutScatteringIntegralSee ComputeSingleScatteringRadiance().
RayEndTexCoord,RayDepthSee ComputePrefilteredSingleScatteringCoordinatesNonLinearRectification().
ScatteringIntegralWithoutOcclusionThe output value in absence of occlusion.
ShadowMapSampler0A sampler for the rectified and prefiltered moment shadow map of the scene.
MomentBiasThe bias used to overcome quantization artifacts in the moment shadow map.
OverestimationWeightIf this value is zero, the output underestimates the actual amount of single scattering. If it is one, it overestimates. Inbetween linear interpolation is employed.

Definition at line 501 of file ParticipatingMedia.fx.

void ComputePrefilteredSingleScatteringConvolution16 ( out float  OutScatteringIntegral,
float2  RayEndTexCoord,
float  RayDepth,
float  ScatteringIntegralWithoutOcclusion,
SSamplerTexturePair2D  ShadowMapSampler0,
SSamplerTexturePair2D  ShadowMapSampler1,
SSamplerTexturePair2D  ShadowMapSampler2,
SSamplerTexturePair2D  ShadowMapSampler3,
SSamplerTexturePair2D  ShadowMapSampler4,
SSamplerTexturePair2D  ShadowMapSampler5,
SSamplerTexturePair2D  ShadowMapSampler6,
SSamplerTexturePair2D  ShadowMapSampler7 
)

Like ComputePrefilteredSingleScatteringConvolution16() but for eight Fourier coefficients.

Definition at line 406 of file ParticipatingMedia.fx.

void ComputePrefilteredSingleScatteringConvolution8 ( out float  OutScatteringIntegral,
float2  RayEndTexCoord,
float  RayDepth,
float  ScatteringIntegralWithoutOcclusion,
SSamplerTexturePair2D  ShadowMapSampler0,
SSamplerTexturePair2D  ShadowMapSampler1,
SSamplerTexturePair2D  ShadowMapSampler2,
SSamplerTexturePair2D  ShadowMapSampler3 
)

This function evaluates the scattering integral resolving occlusions by means of a rectified moment shadow map holding weighted prefix sums of rows.

Parameters
OutScatteringIntegralSee ComputeSingleScatteringRadiance().
RayEndTexCoord,RayDepthSee ComputePrefilteredSingleScatteringCoordinatesNonLinearRectification().
ScatteringIntegralWithoutOcclusionThe output value in absence of shadow.
ShadowMapSampler0,ShadowMapSampler1,ShadowMapSampler2,ShadowMapSampler3Samplers for the rectified and prefiltered shadow maps holding of the scene.

Definition at line 362 of file ParticipatingMedia.fx.

void ComputePrefilteredSingleScatteringCoordinatesNonLinearRectification ( out float2  OutRayEndTexCoord,
out float  OutRayDepth,
float3  WorldSpaceViewRayEnd,
float4x4  WorldToRectificationSpace,
float2  DistanceMinMax,
float2  InclinationMinMax,
float2  AzimuthMinMax 
)

This function computes coordinates which are needed for evaluation of prefiltered single scattering with any prefiltered, non-linearly rectified shadow map.

Parameters
OutRayEndTexCoordThe texture coordinate at which the prefiltered shadow map has to be sampled to get information about the provided ray.
OutRayDepthA size that depends linearly on the inclination of the relevant ray. It functions as shadow map depth value in the rectified coordinate system. -1 corresponds to InclinationMinMax.x, 1 corresponds to InclinationMinMax.y.
WorldSpaceViewRayEndThe endpoint of the view ray in world space coordinates.
WorldToRectificationSpaceInverse of the transform provided by ComputeRectificationToWorldSpaceDirectional().
DistanceMinMax,InclinationMinMax,AzimuthMinMaxSee GetRectifiedSpaceFrustumBounds().
See Also
ApplyTransmittanceWeightedPrefixSumNonLinearRectification()

Definition at line 336 of file ParticipatingMedia.fx.

void ComputeRectificationToWorldSpaceDirectional ( out float4x4  OutRectificationToWorldSpace,
float3  WorldSpaceCameraPosition,
float4x4  ShadowMapViewToWorldSpace 
)

This function prepares a matrix that is useful when working with non-linear rectification transforms for directional lights and prefiltered single scattering.

Parameters
OutRectificationToWorldSpaceThe rectification to world space transform. Rectification space is essentially light view space with the world space camera position at its origin. Additionally, the z and y axis are mirrored to ensure that inclinations grow as the depth grows. From rectification space coordinates rectified coordinates can be computed immediately.
WorldSpaceCameraPositionThe position of the camera for which single scattering is to be rendered in world space.
ShadowMapViewToWorldSpaceThe view to world space transform used for the camera that renders the shadow map of the relevant directional light. It is assumed to be a rotation.

Definition at line 21 of file ParticipatingMedia.fx.

void ComputeScatteringColor ( out float4  OutScatteringColor,
float3  ScatteringRadiance 
)

Given the radiance value due to single scattering this function computes the color to be output by the shader for additive blending. Essentially, it just sets the alpha to one.

See Also
ComputeSingleScatteringRadiance()

Definition at line 251 of file ParticipatingMedia.fx.

void ComputeSingleScatteringFactors ( out float3  OutPhaseTimesAlbedoTimesIrradiance,
float3  PhaseTimesAlbedo,
float3  DirectionalLightIrradiance 
)

This function computes the constant factors in front of the single scattering integral divided by the extinction coefficient. This is simply the product of its arguments.

Definition at line 234 of file ParticipatingMedia.fx.

void ComputeSingleScatteringNoOcclusionDirectional ( out float  OutScatteringIntegral,
float  ViewRayLength,
float  ExtinctionCoefficient 
)

This function evaluates the single scattering integral under the assumption that the light is never occluded.

Parameters
OutScatteringIntegralSee ComputeSingleScatteringRadiance().
ViewRayLengthThe length of the view ray for which single scattering should be accumulated.
ExtinctionCoefficientThe extinction coefficient of the participating media.

Definition at line 264 of file ParticipatingMedia.fx.

void ComputeSingleScatteringRadiance ( out float3  OutScatteringRadiance,
float  ScatteringIntegral,
float3  PhaseTimesAlbedoTimesIrradiance 
)

Given the value of the single scattering integral times the extinction coefficient this function computes the radiance received due to single scattering. The value of the scattering integral has to be a value between zero (no scattering) and one (maximal scattering).

See Also
ComputeSingleScatteringFactors()

Definition at line 243 of file ParticipatingMedia.fx.

void ComputeSingleScatteringRayMarchingDirectional ( out float  OutScatteringIntegral,
float  ViewRayLength,
float3  WorldSpaceViewRayStart,
float3  WorldSpaceViewRayEnd,
SSamplerTexturePair2D_float  ShadowMapSampler,
float4x4  ShadowMapWorldToProjectionSpace,
float  ExtinctionCoefficient,
int  nSample 
)

This function evaluates the scattering integral resolving occlusions by sampling the given shadow map densely with some jittering to replace banding by white noise.

Parameters
OutScatteringIntegralSee ComputeSingleScatteringRadiance().
ViewRayLengthThe length of the view ray for which single scattering should be accumulated.
WorldSpaceViewRayStart,WorldSpaceViewRayEndThe endpoints of the view ray in world space coordinates.
ShadowMapSamplerA sampler for a shadow map of the scene.
ShadowMapWorldToProjectionSpaceThe world to projection space transform of the provided shadow map.
ExtinctionCoefficientThe extinction coefficient of the participating media.
nSampleThe number samples that is placed along the ray to evaluate the integral.

Definition at line 283 of file ParticipatingMedia.fx.

void ComputeViewRayFromProjectionSpace ( out float  OutViewRayLength,
out float3  OutWorldSpaceRayStart,
out float3  OutWorldSpaceRayEnd,
float2  TexCoord,
float  PerspectiveDepth,
float4x4  ProjectionToViewSpace,
float4x4  ViewToWorldSpace 
)

This function computes the distance between a specified point in projection space and the origin of the view space coordinate system (which is supposed to be the camera location) in view space.

Parameters
OutViewRayLengthThe computed view space distance.
OutWorldSpaceRayStartThe world space position at which the ray starts (i.e. the camera position).
OutWorldSpaceRayEndThe world space position at which the ray ends (i.e. the specified point).
TexCoordThe texture coordinate that corresponds to the point of interest in the render target.
PerspectiveDepthThe depth stored in the depth stencil texture for the point of interest. It is perspectivic (z/w) not linear (z).
ProjectionToViewSpaceThe projection to view space transform of the camera.
ViewToWorldSpaceThe view to world space transform of the camera.

Definition at line 221 of file ParticipatingMedia.fx.

void ComputeViewRayLengthFromWorldSpace ( out float  OutViewRayLength,
float3  WorldSpacePosition,
float3  WorldSpaceCameraPosition 
)

This function computes the world space distance between the given camera position and fragment position.

Definition at line 189 of file ParticipatingMedia.fx.

void GetMomentsFromDepth2_4 ( out float2  OutQuantizedMoments0,
out float4  OutQuantizedMoments1,
float  RectifiedDepth 
)

Converts a depth to six optimized moments.

Definition at line 669 of file ParticipatingMedia.fx.

void GetMomentsFromDepth3_3 ( out float3  OutQuantizedMoments0,
out float3  OutQuantizedMoments1,
float  RectifiedDepth 
)

Converts a depth to six optimized moments.

Definition at line 638 of file ParticipatingMedia.fx.

void GetMomentsFromDepth4 ( out float4  OutQuantizedMoments0,
float  RectifiedDepth 
)

Converts a depth to four optimized moments.

Definition at line 618 of file ParticipatingMedia.fx.

void GetMomentsFromSparseRectifiedRepresentation2_4 ( out float2  OutQuantizedMoments0,
out float4  OutQuantizedMoments1,
float2  RectifiedDepth,
float  DepthWeight1 
)

Converts a distribution with two depth values to six optimized moments, output as one two-dimensional vector and one four-dimensional vector.

See Also
GetSparseRectifiedRepresentation()

Definition at line 676 of file ParticipatingMedia.fx.

void GetMomentsFromSparseRectifiedRepresentation3_3 ( out float3  OutQuantizedMoments0,
out float3  OutQuantizedMoments1,
float2  RectifiedDepth,
float  DepthWeight1 
)

Converts a distribution with two depth values to six optimized moments, output as two three-element vectors.

See Also
GetSparseRectifiedRepresentation()

Definition at line 649 of file ParticipatingMedia.fx.

void GetMomentsFromSparseRectifiedRepresentation4 ( out float4  OutQuantizedMoments0,
float2  RectifiedDepth,
float  DepthWeight1 
)

Converts a distribution with two depth values to four optimized moments.

See Also
GetSparseRectifiedRepresentation()

Definition at line 624 of file ParticipatingMedia.fx.

void GetPerspectiveDepth1 ( out float  OutPerspectiveDepth,
Texture2DMS< float, 1 >  DepthStencilTexture,
int2  TexelIndex 
)

This function loads the samples of the given texture for the specified texel and takes their average. This is a somewhat reasonable custom resolve for a depth stencil texture in the context of single scattering because single scattering depends monotonously (although not linearly) on depth.

Definition at line 145 of file ParticipatingMedia.fx.

void GetPrefixSumThreadGroupCount ( out uint3  nOutThreadGroup,
uint3  ThreadGroupSize,
uint  nPrefixSumShadowMap,
float4  TextureSize 
)

This function computes the number of thread groups to be dispatched for generation of row-wise prefix sums.

Parameters
nOutThreadGroupThe number of thread groups along each dimension to be dispatched.
ThreadGroupSizeThe size of thread groups along each dimension for the prefix sum generation. Only the second entry is supposed to be not one.
nPrefixSumShadowMapThe number of textures for which prefix sums need to be created. It is multiplied onto the number of vertical thread groups.
TextureSizeThe width and height of the texture for which prefix sums should be generated in x and y.
Note
This function is provided for reference only and would typically be implemented on the CPU-side of the application.

Definition at line 538 of file ParticipatingMedia.fx.

void GetRectifiedDepth ( out float  OutRectifiedDepth,
SSamplerTexturePair2D_float  ShadowMapSampler0,
float2  RectifiedTexCoord,
float4x4  RectificationToShadowMapProjectionSpace,
float2  ShadowMapToRectificationDepthTransform,
float2  DistanceMinMax,
float2  InclinationMinMax,
float2  AzimuthMinMax 
)

This function takes a single sample from the given non-rectified shadow map at the location that corresponds to the given rectified texture coordinate. It then converts the sampled depth to an inclination and maps it to the appropriate range to get a depth in the rectified coordinate system and outputs it.

Definition at line 562 of file ParticipatingMedia.fx.

void GetRectifiedSpaceFrustumBounds ( out float2  OutDistanceMinMax,
out float2  OutInclinationMinMax,
out float2  OutAzimuthMinMax,
float4x4  CameraProjectionToWorldSpace,
float4x4  CameraWorldToProjectionSpace,
float4x4  RectificationToWorldSpace,
float4x4  WorldToRectificationSpace 
)

This function computes the coordinate ranges covered by the rectified coordinates of the specified view frustum.

Parameters
OutDistanceMinMaxx is always set to zero, y is set to the maximal distance between the camera position and a point within the frustum.
OutInclinationMinMaxMinimal and maximal inclination of points within the frustum in rectification space. This ranges from 0 to pi.
OutAzimuthMinMaxMinimal and maximal azimuth of points within the frustum in rectification space. x and y-x are both always between 0 and 2*pi. The interval of radian angles inbetween covers the frustum.
CameraProjectionToWorldSpaceThe projection to world space transform of the camera for which single scattering is to be rendered. This defines the frustum.
CameraWorldToProjectionSpaceInverse of CameraProjectionToWorldSpace.
RectificationToWorldSpaceSee ComputeRectificationToWorldSpaceDirectional().
WorldToRectificationSpaceInverse of RectificationToWorldSpace.
Note
This is a reference implementation only. The function should be implemented on the CPU side of your application and executed once per frame and light source.

Definition at line 50 of file ParticipatingMedia.fx.

void GetShadowMapToRectificationDepthTransform ( out float2  OutShadowMapToRectificationDepthTransform,
float4x4  RectificationToShadowMapProjectionSpace 
)

Constructs a tuple (Gradient,YIntercept) describing the linear transform that maps depths in shadow map space to z values in rectification space.

Definition at line 546 of file ParticipatingMedia.fx.

void GetSparseRectifiedRepresentation ( out float2  OutRectifiedDepth,
out float  OutDepthWeight1,
SSamplerTexturePair2D  ShadowMapSampler0,
float2  RectifiedTexCoord,
float4x4  RectificationToShadowMapProjectionSpace,
float2  ShadowMapToRectificationDepthTransform,
float2  DistanceMinMax,
float2  InclinationMinMax,
float2  AzimuthMinMax 
)

This function takes a single filtered sample from the given non-rectified, optimized four moment shadow map at the location that corresponds to the given rectified texture coordinate. It then represents the first three moments by a distribution using two depth values. The depth values are converted to inclinations and mapped to the appropriate range to get a depth in the rectified coordinate system. The two depth values and the weight for the second depth are output.

Definition at line 590 of file ParticipatingMedia.fx.