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
Shadow.fx
Go to the documentation of this file.
1 #include "ShadowUtility.fx"
3 #include "RandomNumbers.fx"
4 
13 void ComputeFragmentDepth(out float OutFragmentDepth,float4 ProjectionSpacePosition){
14  OutFragmentDepth=saturate(ProjectionSpacePosition.z/ProjectionSpacePosition.w)*2.0f-1.0f;
15 }
16 
20 void ComputeShadowMapDepth(out float OutShadowMapDepth,float FragmentDepth){
21  OutShadowMapDepth=FragmentDepth*0.5f+0.5f;
22 }
23 
26 void CombineVectorWithAlpha_float1(out float4 OutVectorWithAlpha,float Vector,float Alpha){
27  OutVectorWithAlpha=float4(Vector,0.0f,0.0f,Alpha);
28 }
31 void CombineVectorWithAlpha_float2(out float4 OutVectorWithAlpha,float2 Vector,float Alpha){
32  OutVectorWithAlpha=float4(Vector,0.0f,Alpha);
33 }
35 void CombineVectorWithAlpha_float3(out float4 OutVectorWithAlpha,float3 Vector,float Alpha){
36  OutVectorWithAlpha=float4(Vector,Alpha);
37 }
39 void CombineVectorWithAlpha_float4(out float4 OutVectorWithAlpha,float4 Vector){
40  OutVectorWithAlpha=Vector;
41 }
42 
43 
46 void ConvertShadowIntensityToColor(out float4 OutColor,float ShadowIntensity){
47  OutColor.rgb=1.0f-ShadowIntensity;
48  OutColor.a=1.0f;
49 }
50 
51 
54 void ComputeMomentVectorExponential(out float OutExponential,float FragmentDepth,float Factor=80.0f){
55  OutExponential=exp(Factor*FragmentDepth);
56 }
57 
60 void ComputeMomentVectorFourier8(out float4 OutFourier1_2,out float4 OutFourier3_4,out float4 OutFourier5_6,out float4 OutFourier7_8,float FragmentDepth){
61  const float PI=3.1415926535897932384626433832795f;
62  // Compute the first Fourier coefficient
63  float2 Fourier1;
64  sincos((FragmentDepth*0.5f+0.5f)*PI,Fourier1.y,Fourier1.x);
65  // Compute the other coefficients by complex exponentiation
66  float2 FourierSquare=Multiply(Fourier1,Fourier1);
67  float2 pFourierCoefficient[8];
68  pFourierCoefficient[0]=Fourier1;
69  [unroll] for(int i=1;i!=8;++i){
70  pFourierCoefficient[i]=Multiply(pFourierCoefficient[i-1],FourierSquare);
71  }
72  // Store the results
73  const float2 Factor=float2(0.5f,0.5f);
74  const float2 Summand=Factor;
75  OutFourier1_2.xy=pFourierCoefficient[0]*Factor+Summand;
76  OutFourier1_2.zw=pFourierCoefficient[1]*Factor+Summand;
77  OutFourier3_4.xy=pFourierCoefficient[2]*Factor+Summand;
78  OutFourier3_4.zw=pFourierCoefficient[3]*Factor+Summand;
79  OutFourier5_6.xy=pFourierCoefficient[4]*Factor+Summand;
80  OutFourier5_6.zw=pFourierCoefficient[5]*Factor+Summand;
81  OutFourier7_8.xy=pFourierCoefficient[6]*Factor+Summand;
82  OutFourier7_8.zw=pFourierCoefficient[7]*Factor+Summand;
83 }
84 
87 void ComputeMomentVectorFourier16(out float4 OutFourier1_2,out float4 OutFourier3_4,out float4 OutFourier5_6,out float4 OutFourier7_8,out float4 OutFourier9_10,out float4 OutFourier11_12,out float4 OutFourier13_14,out float4 OutFourier15_16,float FragmentDepth){
88  const float PI=3.1415926535897932384626433832795f;
89  // Compute the first Fourier coefficient
90  float2 Fourier1;
91  sincos((FragmentDepth*0.5f+0.5f)*PI,Fourier1.y,Fourier1.x);
92  // Compute the other coefficients by complex exponentiation
93  float2 FourierSquare=Multiply(Fourier1,Fourier1);
94  float2 pFourierCoefficient[16];
95  pFourierCoefficient[0]=Fourier1;
96  [unroll] for(int i=1;i!=16;++i){
97  pFourierCoefficient[i]=Multiply(pFourierCoefficient[i-1],FourierSquare);
98  }
99  // Store the results
100  const float2 Factor=float2(0.5f,0.5f);
101  const float2 Summand=Factor;
102  OutFourier1_2.xy=pFourierCoefficient[0]*Factor+Summand;
103  OutFourier1_2.zw=pFourierCoefficient[1]*Factor+Summand;
104  OutFourier3_4.xy=pFourierCoefficient[2]*Factor+Summand;
105  OutFourier3_4.zw=pFourierCoefficient[3]*Factor+Summand;
106  OutFourier5_6.xy=pFourierCoefficient[4]*Factor+Summand;
107  OutFourier5_6.zw=pFourierCoefficient[5]*Factor+Summand;
108  OutFourier7_8.xy=pFourierCoefficient[6]*Factor+Summand;
109  OutFourier7_8.zw=pFourierCoefficient[7]*Factor+Summand;
110  OutFourier9_10.xy=pFourierCoefficient[8]*Factor+Summand;
111  OutFourier9_10.zw=pFourierCoefficient[9]*Factor+Summand;
112  OutFourier11_12.xy=pFourierCoefficient[10]*Factor+Summand;
113  OutFourier11_12.zw=pFourierCoefficient[11]*Factor+Summand;
114  OutFourier13_14.xy=pFourierCoefficient[12]*Factor+Summand;
115  OutFourier13_14.zw=pFourierCoefficient[13]*Factor+Summand;
116  OutFourier15_16.xy=pFourierCoefficient[14]*Factor+Summand;
117  OutFourier15_16.zw=pFourierCoefficient[15]*Factor+Summand;
118 }
119 
122 void ComputeTrigonometricMomentVector(out float4 OutFourier1_2,float FragmentDepth){
123  const float PI=3.1415926535897932384626433832795f;
124  // Compute the first Fourier coefficient
125  float2 Fourier1;
126  sincos(FragmentDepth*PI+PI,Fourier1.y,Fourier1.x);
127  // Square it to obtain the second Fourier coefficient
128  float2 Fourier2=Multiply(Fourier1,Fourier1);
129  // Store the results
130  const float2 Factor=float2(0.5f,0.5f);
131  const float2 Summand=Factor;
132  OutFourier1_2.xy=Fourier1*Factor+Summand;
133  OutFourier1_2.zw=Fourier2*Factor+Summand;
134 }
135 
138 void ComputeExponentialVarianceVector(out float4 OutDepthExponentialVariance,float FragmentDepth,float2 ExponentialVarianceFactors){
139  float SignedDepth=FragmentDepth;
140  float Exponential=exp(ExponentialVarianceFactors.x*SignedDepth);
141  float InvExponential=exp(ExponentialVarianceFactors.y*SignedDepth);
142  OutDepthExponentialVariance=float4(Exponential,Exponential*Exponential,InvExponential,InvExponential*InvExponential);
143 }
144 
147 void ComputeExponentialVarianceVectorSplit(out float2 OutDepthExponentialVariance0,out float2 OutDepthExponentialVariance1,float FragmentDepth,float2 ExponentialVarianceFactors){
148  float SignedDepth=FragmentDepth;
149  float Exponential=exp(ExponentialVarianceFactors.x*SignedDepth);
150  float InvExponential=exp(ExponentialVarianceFactors.y*SignedDepth);
151  OutDepthExponentialVariance0=float2(Exponential,Exponential*Exponential);
152  OutDepthExponentialVariance1=float2(InvExponential,InvExponential*InvExponential);
153 }
154 
158 void ComputeMomentVector2Moments_float2(out float2 Out2Moments_float2,float FragmentDepth){
159  Out2Moments_float2=float2(FragmentDepth*0.5f+0.5f,FragmentDepth*FragmentDepth);
160 }
161 
162 
165 void ComputeMomentVector4Moments_float4(out float4 Out4Moments_float4,float FragmentDepth){
166  float Square=FragmentDepth*FragmentDepth;
167  Out4Moments_float4=float4(FragmentDepth,Square,Square*FragmentDepth,Square*Square);
168 }
169 
173 void ComputeMomentVector4MomentsOptimized_float4(out float4 Out4MomentsOptimized_float4,float FragmentDepth){
174  float Square=FragmentDepth*FragmentDepth;
175  float4 Moments=float4(FragmentDepth,Square,Square*FragmentDepth,Square*Square);
176  Out4MomentsOptimized_float4.xz=mul(Moments.xz,float2x2(1.5f,sqrt(3.0f)*0.5f,-2.0f,-sqrt(3.0f)*2.0f/9.0f))+0.5f;
177  Out4MomentsOptimized_float4.yw=mul(Moments.yw,float2x2(4.0f,0.5f,-4.0f,0.5f));
178 }
179 
180 
185 void ComputeMomentVector4Moments_float2_float2(out float2 Out4Moments0_float2,out float2 Out4Moments1_float2,float FragmentDepth){
186  float Square=FragmentDepth*FragmentDepth;
187  Out4Moments0_float2=float2(FragmentDepth,Square);
188  Out4Moments1_float2=float2(Square*FragmentDepth,Square*Square);
189 }
190 
196 void ComputeMomentVector4MomentsOptimized_float2_float2(out float2 Out4MomentsOptimized0_float2,out float2 Out4MomentsOptimized1_float2,float FragmentDepth){
197  float Square=FragmentDepth*FragmentDepth;
198  float4 Moments=float4(FragmentDepth,Square,Square*FragmentDepth,Square*Square);
199  float4 OptimizedMoments;
200  OptimizedMoments.xz=mul(Moments.xz,float2x2(1.5f,sqrt(3.0f)*0.5f,-2.0f,-sqrt(3.0f)*2.0f/9.0f))+0.5f;
201  OptimizedMoments.yw=mul(Moments.yw,float2x2(4.0f,0.5f,-4.0f,0.5f));
202  Out4MomentsOptimized0_float2=OptimizedMoments.xy;
203  Out4MomentsOptimized1_float2=OptimizedMoments.zw;
204 }
205 
206 
212 void ComputeDirectionalLightCamera(out float4x4 OutViewToWorldSpace,out float4x4 OutViewToProjectionSpace,float3 WorldSpaceBoundingBoxMin,float3 WorldSpaceBoundingBoxMax,float3 WorldSpaceLightDirection){
213  // Determine the orientation of a view-space coordinate system to use for the
214  // camera
215  float3 LeftVectorUnnormalized=cross(float3(0.0f,1.0f,0.0f),WorldSpaceLightDirection);
216  float3 LeftVector;
217  if(dot(LeftVectorUnnormalized,LeftVectorUnnormalized)>1.0e-8f){
218  LeftVector=normalize(LeftVectorUnnormalized);
219  }
220  else{
221  LeftVector=normalize(cross(float3(0.0f,0.0f,1.0f),WorldSpaceLightDirection));
222  }
223  float3 UpVector=normalize(cross(WorldSpaceLightDirection,LeftVector));
224  float3x3 ViewToWorldSpaceRotation=float3x3(
225  LeftVector.x,LeftVector.y,LeftVector.z,
226  UpVector.x,UpVector.y,UpVector.z,
227  WorldSpaceLightDirection.x,WorldSpaceLightDirection.y,WorldSpaceLightDirection.z);
228  // Construct all eight vertices of the bounding box
229  float3 Min=WorldSpaceBoundingBoxMin;
230  float3 Max=WorldSpaceBoundingBoxMax;
231  float3 pBoundingBoxVertex[8]={
232  float3(Min.x,Min.y,Min.z),
233  float3(Min.x,Min.y,Max.z),
234  float3(Min.x,Max.y,Min.z),
235  float3(Min.x,Max.y,Max.z),
236  float3(Max.x,Min.y,Min.z),
237  float3(Max.x,Min.y,Max.z),
238  float3(Max.x,Max.y,Min.z),
239  float3(Max.x,Max.y,Max.z)
240  };
241  // Compute the minimal and maximal coordinates of these vertices in the camera
242  // coordinate system
243  float3 MinExtent=mul(pBoundingBoxVertex[0],transpose(ViewToWorldSpaceRotation));
244  float3 MaxExtent=MinExtent;
245  [unroll] for(int i=1;i!=8;++i){
246  float3 ViewSpaceVertex=mul(pBoundingBoxVertex[i],transpose(ViewToWorldSpaceRotation));
247  MinExtent=min(MinExtent,ViewSpaceVertex);
248  MaxExtent=max(MaxExtent,ViewSpaceVertex);
249  }
250  // Compute the camera position
251  float3 ViewSpaceCameraPosition=MinExtent*float3(0.5f,0.5f,1.0f)+MaxExtent*float3(0.5f,0.5f,0.0f);
252  float3 WorldSpaceCameraPosition=mul(ViewSpaceCameraPosition,ViewToWorldSpaceRotation);
253  // Construct the complete view to world space transformation
254  OutViewToWorldSpace[0]=float4(ViewToWorldSpaceRotation[0],0.0f);
255  OutViewToWorldSpace[1]=float4(ViewToWorldSpaceRotation[1],0.0f);
256  OutViewToWorldSpace[2]=float4(ViewToWorldSpaceRotation[2],0.0f);
257  OutViewToWorldSpace[3]=float4(WorldSpaceCameraPosition,0.0f);
258  // Construct the view to projection space transformation
259  float3 ViewSize=MaxExtent-MinExtent;
260  OutViewToProjectionSpace=float4x4(
261  2.0f/ViewSize.x,0.0f,0.0f,0.0f,
262  0.0f,2.0f/ViewSize.y,0.0f,0.0f,
263  0.0f,0.0f,1.0f/ViewSize.z,0.0f,
264  0.0f,0.0f,0.0f,1.0f);
265 }
266 
267 
273 void ComputeSpotLightCamera(out float4x4 OutViewToWorldSpace,out float4x4 OutViewToProjectionSpace,float3 WorldSpaceLightPosition,float3 WorldSpaceConeAxisDirection,float OuterConeAngle,float NearClippingPlane,float FarClippingPlane){
274  // Construct a view to world space transformation, which looks into the right
275  // direction
276  float3 LeftVector=normalize(cross(float3(0.0f,1.0f,0.0f),WorldSpaceConeAxisDirection));
277  float3 UpVector=normalize(cross(WorldSpaceConeAxisDirection,LeftVector));
278  OutViewToWorldSpace=float4x4(
279  LeftVector.x,LeftVector.y,LeftVector.z,0.0f,
280  UpVector.x,UpVector.y,UpVector.z,0.0f,
281  WorldSpaceConeAxisDirection.x,WorldSpaceConeAxisDirection.y,WorldSpaceConeAxisDirection.z,0.0f,
282  WorldSpaceLightPosition.x,WorldSpaceLightPosition.y,WorldSpaceLightPosition.z,1.0f);
283  // Construct the projection transformation using the appropriate field of view
284  float Cotangent=1.0/tan(OuterConeAngle);
285  float NormalizationFactor=1.0f/(FarClippingPlane-NearClippingPlane);
286  OutViewToProjectionSpace=NormalizationFactor*float4x4(
287  Cotangent,0.0f,0.0f,0.0f,
288  0.0f,Cotangent,0.0f,0.0f,
289  0.0f,0.0f,FarClippingPlane*NormalizationFactor,1.0,
290  0.0f,0.0f,-NearClippingPlane*FarClippingPlane*NormalizationFactor,0.0f);
291 }
292 
293 
299 void ComputeShadowMapCoordinate(out float2 OutShadowMapTexCoord,out float OutShadowMapDepth,float4 ShadowMapProjectionSpacePosition,float4 ShadowMapSize){
300  OutShadowMapTexCoord=ShadowMapProjectionSpacePosition.xy/ShadowMapProjectionSpacePosition.w;
301  OutShadowMapTexCoord=OutShadowMapTexCoord*float2(0.5f,-0.5f)+float2(0.5f,0.5f);
302 #if D3D_VERSION==9
303  OutShadowMapTexCoord=OutShadowMapTexCoord+0.5f*ShadowMapSize.zw;
304 #endif
305  OutShadowMapDepth=(ShadowMapProjectionSpacePosition.z/ShadowMapProjectionSpacePosition.w)*2.0f-1.0f;
306 }
307 
308 
321 void ComputeWorldSpacePositionUnderCursor(out float3 OutWorldSpacePosition,Texture2DMS<float,1> SceneDepthTexture,float4 SceneDepthTextureSize,int2 iCursorPosition,float4x4 CameraProjectionToWorldSpace){
322  float SceneDepth=SceneDepthTexture.Load(iCursorPosition,0);
323  float4 ProjectionSpacePosition;
324  ProjectionSpacePosition.x=(float(iCursorPosition.x)+0.5f)*SceneDepthTextureSize.z*2.0f-1.0f;
325  ProjectionSpacePosition.y=(float(iCursorPosition.y)+0.5f)*SceneDepthTextureSize.w*(-2.0f)+1.0f;
326  ProjectionSpacePosition.z=SceneDepth;
327  ProjectionSpacePosition.w=1.0f;
328  float4 WorldSpacePosition=mul(ProjectionSpacePosition,CameraProjectionToWorldSpace);
329  OutWorldSpacePosition=WorldSpacePosition.xyz/WorldSpacePosition.w;
330 }
331 
332 
335 void HeavisideStepFunction(out float OutShadowIntensity,float BlockerDepth,float FragmentDepth){
336  OutShadowIntensity=(BlockerDepth<FragmentDepth)?1.0f:0.0f;
337 }
338 
339 
342 void SampleShadowMap(out float OutShadowMapDepth,SSamplerTexturePair2D_float ShadowMapSampler,float2 ShadowMapTexCoord){
343  OutShadowMapDepth=ShadowMapSampler.Texture.SampleLevel(ShadowMapSampler.Sampler,ShadowMapTexCoord,0.0f);
344 }
345 
348 void SampleExponentialVarianceShadowMap(out float4 OutExponentialVarianceVector,SSamplerTexturePair2D ExponentialVarianceShadowMapSampler0,float2 ShadowMapTexCoord){
349 #ifdef SHADER_PROFILE_VS
350  OutExponentialVarianceVector=ExponentialVarianceShadowMapSampler0.Texture.SampleLevel(ExponentialVarianceShadowMapSampler0.Sampler,ShadowMapTexCoord,0.0f);
351 #else
352  OutExponentialVarianceVector=ExponentialVarianceShadowMapSampler0.Texture.Sample(ExponentialVarianceShadowMapSampler0.Sampler,ShadowMapTexCoord);
353 #endif
354 }
355 
359 void SampleExponentialVarianceSplitShadowMap(out float4 OutExponentialVarianceVector,SSamplerTexturePair2D_float2 ExponentialVarianceShadowMapSampler0,SSamplerTexturePair2D_float2 ExponentialVarianceShadowMapSampler1,float2 ShadowMapTexCoord){
360 #ifdef SHADER_PROFILE_VS
361  OutExponentialVarianceVector.xy=ExponentialVarianceShadowMapSampler0.Texture.SampleLevel(ExponentialVarianceShadowMapSampler0.Sampler,ShadowMapTexCoord,0.0f);
362  OutExponentialVarianceVector.zw=ExponentialVarianceShadowMapSampler1.Texture.SampleLevel(ExponentialVarianceShadowMapSampler1.Sampler,ShadowMapTexCoord,0.0f);
363 #else
364  OutExponentialVarianceVector.xy=ExponentialVarianceShadowMapSampler0.Texture.Sample(ExponentialVarianceShadowMapSampler0.Sampler,ShadowMapTexCoord);
365  OutExponentialVarianceVector.zw=ExponentialVarianceShadowMapSampler1.Texture.Sample(ExponentialVarianceShadowMapSampler1.Sampler,ShadowMapTexCoord);
366 #endif
367 }
368 
371 void SampleExponentialShadowMap(out float OutExponentialShadowMap,SSamplerTexturePair2D_float ExponentialShadowMapSampler,float2 ShadowMapTexCoord){
372 #ifdef SHADER_PROFILE_VS
373  OutExponentialShadowMap=ExponentialShadowMapSampler.Texture.SampleLevel(ExponentialShadowMapSampler.Sampler,ShadowMapTexCoord,0.0f);
374 #else
375  OutExponentialShadowMap=ExponentialShadowMapSampler.Texture.Sample(ExponentialShadowMapSampler.Sampler,ShadowMapTexCoord);
376 #endif
377 }
378 
382 void SampleConvolutionShadowMap8(out float2 pOutFourierCoefficient[8],SSamplerTexturePair2D ConvolutionShadowMapSampler0,SSamplerTexturePair2D ConvolutionShadowMapSampler1,SSamplerTexturePair2D ConvolutionShadowMapSampler2,SSamplerTexturePair2D ConvolutionShadowMapSampler3,float2 ShadowMapTexCoord){
383  const float2 Factor=float2(2.0f,2.0f);
384  const float2 Summand=float2(-1.0f,-1.0f);
385 #ifdef SHADER_PROFILE_VS
386  float4 Fourier1_2=ConvolutionShadowMapSampler0.Texture.SampleLevel(ConvolutionShadowMapSampler0.Sampler,ShadowMapTexCoord,0.0f);
387  float4 Fourier3_4=ConvolutionShadowMapSampler1.Texture.SampleLevel(ConvolutionShadowMapSampler1.Sampler,ShadowMapTexCoord,0.0f);
388  float4 Fourier5_6=ConvolutionShadowMapSampler2.Texture.SampleLevel(ConvolutionShadowMapSampler2.Sampler,ShadowMapTexCoord,0.0f);
389  float4 Fourier7_8=ConvolutionShadowMapSampler3.Texture.SampleLevel(ConvolutionShadowMapSampler3.Sampler,ShadowMapTexCoord,0.0f);
390 #else
391  float4 Fourier1_2=ConvolutionShadowMapSampler0.Texture.Sample(ConvolutionShadowMapSampler0.Sampler,ShadowMapTexCoord);
392  float4 Fourier3_4=ConvolutionShadowMapSampler1.Texture.Sample(ConvolutionShadowMapSampler1.Sampler,ShadowMapTexCoord);
393  float4 Fourier5_6=ConvolutionShadowMapSampler2.Texture.Sample(ConvolutionShadowMapSampler2.Sampler,ShadowMapTexCoord);
394  float4 Fourier7_8=ConvolutionShadowMapSampler3.Texture.Sample(ConvolutionShadowMapSampler3.Sampler,ShadowMapTexCoord);
395 #endif
396  pOutFourierCoefficient[0]=Fourier1_2.xy*Factor+Summand;
397  pOutFourierCoefficient[1]=Fourier1_2.zw*Factor+Summand;
398  pOutFourierCoefficient[2]=Fourier3_4.xy*Factor+Summand;
399  pOutFourierCoefficient[3]=Fourier3_4.zw*Factor+Summand;
400  pOutFourierCoefficient[4]=Fourier5_6.xy*Factor+Summand;
401  pOutFourierCoefficient[5]=Fourier5_6.zw*Factor+Summand;
402  pOutFourierCoefficient[6]=Fourier7_8.xy*Factor+Summand;
403  pOutFourierCoefficient[7]=Fourier7_8.zw*Factor+Summand;
404 }
405 
406 
408 void SampleConvolutionShadowMap16(out float2 pOutFourierCoefficient[16],SSamplerTexturePair2D ConvolutionShadowMapSampler0,SSamplerTexturePair2D ConvolutionShadowMapSampler1,SSamplerTexturePair2D ConvolutionShadowMapSampler2,SSamplerTexturePair2D ConvolutionShadowMapSampler3,SSamplerTexturePair2D ConvolutionShadowMapSampler4,SSamplerTexturePair2D ConvolutionShadowMapSampler5,SSamplerTexturePair2D ConvolutionShadowMapSampler6,SSamplerTexturePair2D ConvolutionShadowMapSampler7,float2 ShadowMapTexCoord){
409  const float2 Factor=float2(2.0f,2.0f);
410  const float2 Summand=float2(-1.0f,-1.0f);
411 #ifdef SHADER_PROFILE_VS
412  float4 Fourier1_2=ConvolutionShadowMapSampler0.Texture.SampleLevel(ConvolutionShadowMapSampler0.Sampler,ShadowMapTexCoord,0.0f);
413  float4 Fourier3_4=ConvolutionShadowMapSampler1.Texture.SampleLevel(ConvolutionShadowMapSampler1.Sampler,ShadowMapTexCoord,0.0f);
414  float4 Fourier5_6=ConvolutionShadowMapSampler2.Texture.SampleLevel(ConvolutionShadowMapSampler2.Sampler,ShadowMapTexCoord,0.0f);
415  float4 Fourier7_8=ConvolutionShadowMapSampler3.Texture.SampleLevel(ConvolutionShadowMapSampler3.Sampler,ShadowMapTexCoord,0.0f);
416  float4 Fourier9_10=ConvolutionShadowMapSampler4.Texture.SampleLevel(ConvolutionShadowMapSampler4.Sampler,ShadowMapTexCoord,0.0f);
417  float4 Fourier11_12=ConvolutionShadowMapSampler5.Texture.SampleLevel(ConvolutionShadowMapSampler5.Sampler,ShadowMapTexCoord,0.0f);
418  float4 Fourier13_14=ConvolutionShadowMapSampler6.Texture.SampleLevel(ConvolutionShadowMapSampler6.Sampler,ShadowMapTexCoord,0.0f);
419  float4 Fourier15_16=ConvolutionShadowMapSampler7.Texture.SampleLevel(ConvolutionShadowMapSampler7.Sampler,ShadowMapTexCoord,0.0f);
420 #else
421  float4 Fourier1_2=ConvolutionShadowMapSampler0.Texture.Sample(ConvolutionShadowMapSampler0.Sampler,ShadowMapTexCoord);
422  float4 Fourier3_4=ConvolutionShadowMapSampler1.Texture.Sample(ConvolutionShadowMapSampler1.Sampler,ShadowMapTexCoord);
423  float4 Fourier5_6=ConvolutionShadowMapSampler2.Texture.Sample(ConvolutionShadowMapSampler2.Sampler,ShadowMapTexCoord);
424  float4 Fourier7_8=ConvolutionShadowMapSampler3.Texture.Sample(ConvolutionShadowMapSampler3.Sampler,ShadowMapTexCoord);
425  float4 Fourier9_10=ConvolutionShadowMapSampler4.Texture.Sample(ConvolutionShadowMapSampler4.Sampler,ShadowMapTexCoord);
426  float4 Fourier11_12=ConvolutionShadowMapSampler5.Texture.Sample(ConvolutionShadowMapSampler5.Sampler,ShadowMapTexCoord);
427  float4 Fourier13_14=ConvolutionShadowMapSampler6.Texture.Sample(ConvolutionShadowMapSampler6.Sampler,ShadowMapTexCoord);
428  float4 Fourier15_16=ConvolutionShadowMapSampler7.Texture.Sample(ConvolutionShadowMapSampler7.Sampler,ShadowMapTexCoord);
429 #endif
430  pOutFourierCoefficient[0]=Fourier1_2.xy*Factor+Summand;
431  pOutFourierCoefficient[1]=Fourier1_2.zw*Factor+Summand;
432  pOutFourierCoefficient[2]=Fourier3_4.xy*Factor+Summand;
433  pOutFourierCoefficient[3]=Fourier3_4.zw*Factor+Summand;
434  pOutFourierCoefficient[4]=Fourier5_6.xy*Factor+Summand;
435  pOutFourierCoefficient[5]=Fourier5_6.zw*Factor+Summand;
436  pOutFourierCoefficient[6]=Fourier7_8.xy*Factor+Summand;
437  pOutFourierCoefficient[7]=Fourier7_8.zw*Factor+Summand;
438  pOutFourierCoefficient[8]=Fourier9_10.xy*Factor+Summand;
439  pOutFourierCoefficient[9]=Fourier9_10.zw*Factor+Summand;
440  pOutFourierCoefficient[10]=Fourier11_12.xy*Factor+Summand;
441  pOutFourierCoefficient[11]=Fourier11_12.zw*Factor+Summand;
442  pOutFourierCoefficient[12]=Fourier13_14.xy*Factor+Summand;
443  pOutFourierCoefficient[13]=Fourier13_14.zw*Factor+Summand;
444  pOutFourierCoefficient[14]=Fourier15_16.xy*Factor+Summand;
445  pOutFourierCoefficient[15]=Fourier15_16.zw*Factor+Summand;
446 }
447 
448 
452 void Sample2TMSMShadowMap(out float2 pOutFourierCoefficient[2],SSamplerTexturePair2D _2TMSMShadowMapSampler,float2 ShadowMapTexCoord){
453  const float2 Factor=float2(2.0f,2.0f);
454  const float2 Summand=float2(-1.0f,-1.0f);
455 #ifdef SHADER_PROFILE_VS
456  float4 Fourier1_2=_2TMSMShadowMapSampler.Texture.SampleLevel(_2TMSMShadowMapSampler.Sampler,ShadowMapTexCoord,0.0f);
457 #else
458  float4 Fourier1_2=_2TMSMShadowMapSampler.Texture.Sample(_2TMSMShadowMapSampler.Sampler,ShadowMapTexCoord);
459 #endif
460  pOutFourierCoefficient[0]=Fourier1_2.xy*Factor+Summand;
461  pOutFourierCoefficient[1]=Fourier1_2.zw*Factor+Summand;
462 }
463 
464 
467 void Sample2MomentShadowMap(out float2 OutBiased2Moments,SSamplerTexturePair2D_float2 _2MomentShadowMapSampler,float2 ShadowMapTexCoord,float MomentBias=0.0f){
468 #ifdef SHADER_PROFILE_VS
469  OutBiased2Moments=_2MomentShadowMapSampler.Texture.SampleLevel(_2MomentShadowMapSampler.Sampler,ShadowMapTexCoord,0.0f);
470 #else
471  OutBiased2Moments=_2MomentShadowMapSampler.Texture.Sample(_2MomentShadowMapSampler.Sampler,ShadowMapTexCoord);
472 #endif
473  OutBiased2Moments.x=OutBiased2Moments.x*2.0f-1.0f;
474  // Guarantee a variance of at least MomentBias
475  OutBiased2Moments.y=max(OutBiased2Moments.y,OutBiased2Moments.x*OutBiased2Moments.x+MomentBias);
476 }
477 
479 void Convert2MomentToCanonical(out float2 OutBiased2Moments,float2 Moments0,float MomentBias=0.0f){
480  OutBiased2Moments.x=Moments0.x*2.0f-1.0f;
481  // Guarantee a variance of at least MomentBias
482  OutBiased2Moments.y=max(Moments0.y,OutBiased2Moments.x*OutBiased2Moments.x+MomentBias);
483 }
484 
485 
489 void Sample4MomentShadowMap(out float4 OutBiased4Moments,SSamplerTexturePair2D _4MomentShadowMapSampler,float2 ShadowMapTexCoord,float MomentBias=3.0e-7f){
490 #ifdef SHADER_PROFILE_VS
491  OutBiased4Moments=_4MomentShadowMapSampler.Texture.SampleLevel(_4MomentShadowMapSampler.Sampler,ShadowMapTexCoord,0.0f);
492 #else
493  OutBiased4Moments=_4MomentShadowMapSampler.Texture.Sample(_4MomentShadowMapSampler.Sampler,ShadowMapTexCoord);
494 #endif
495  OutBiased4Moments=lerp(OutBiased4Moments,float4(0.0f,0.375f,0.0f,0.375f),MomentBias);
496 }
497 
501 void Sample4MomentOptimizedShadowMap(out float4 OutBiased4Moments,SSamplerTexturePair2D _4MomentOptimizedShadowMapSampler,float2 ShadowMapTexCoord,float MomentBias=6.0e-5f){
502 #ifdef SHADER_PROFILE_VS
503  float4 OptimizedSample=_4MomentOptimizedShadowMapSampler.Texture.SampleLevel(_4MomentOptimizedShadowMapSampler.Sampler,ShadowMapTexCoord,0.0f);
504 #else
505  float4 OptimizedSample=_4MomentOptimizedShadowMapSampler.Texture.Sample(_4MomentOptimizedShadowMapSampler.Sampler,ShadowMapTexCoord);
506 #endif
507  OutBiased4Moments.xz=mul(OptimizedSample.xz-0.5f,float2x2(-1.0f/3.0f,-0.75f,sqrt(3.0f),0.75f*sqrt(3.0f)));
508  OutBiased4Moments.yw=mul(OptimizedSample.yw,float2x2(0.125f,-0.125f,1.0f,1.0f));
509  OutBiased4Moments=lerp(OutBiased4Moments,float4(0.0f,0.628f,0.0f,0.628f),MomentBias);
510 }
511 
512 
515 void Sample4MomentSplitShadowMap(out float4 OutBiased4Moments,SSamplerTexturePair2D_float2 _4MomentShadowMapSampler0,SSamplerTexturePair2D_float2 _4MomentShadowMapSampler1,float2 ShadowMapTexCoord,float MomentBias=3.0e-7f){
516 #ifdef SHADER_PROFILE_VS
517  OutBiased4Moments.xy=_4MomentShadowMapSampler0.Texture.SampleLevel(_4MomentShadowMapSampler0.Sampler,ShadowMapTexCoord,0.0f);
518  OutBiased4Moments.zw=_4MomentShadowMapSampler1.Texture.SampleLevel(_4MomentShadowMapSampler1.Sampler,ShadowMapTexCoord,0.0f);
519 #else
520  OutBiased4Moments.xy=_4MomentShadowMapSampler0.Texture.Sample(_4MomentShadowMapSampler0.Sampler,ShadowMapTexCoord);
521  OutBiased4Moments.zw=_4MomentShadowMapSampler1.Texture.Sample(_4MomentShadowMapSampler1.Sampler,ShadowMapTexCoord);
522 #endif
523  OutBiased4Moments=lerp(OutBiased4Moments,float4(0.0f,0.375f,0.0f,0.375f),MomentBias);
524 }
525 
529 void Sample4MomentOptimizedSplitShadowMap(out float4 OutBiased4Moments,SSamplerTexturePair2D_float2 _4MomentOptimizedShadowMapSampler0,SSamplerTexturePair2D_float2 _4MomentOptimizedShadowMapSampler1,float2 ShadowMapTexCoord,float MomentBias=6.0e-5f){
530  float4 OptimizedSample;
531 #ifdef SHADER_PROFILE_VS
532  OptimizedSample.xy=_4MomentOptimizedShadowMapSampler0.Texture.SampleLevel(_4MomentOptimizedShadowMapSampler0.Sampler,ShadowMapTexCoord,0.0f);
533  OptimizedSample.zw=_4MomentOptimizedShadowMapSampler1.Texture.SampleLevel(_4MomentOptimizedShadowMapSampler1.Sampler,ShadowMapTexCoord,0.0f);
534 #else
535  OptimizedSample.xy=_4MomentOptimizedShadowMapSampler0.Texture.Sample(_4MomentOptimizedShadowMapSampler0.Sampler,ShadowMapTexCoord);
536  OptimizedSample.zw=_4MomentOptimizedShadowMapSampler1.Texture.Sample(_4MomentOptimizedShadowMapSampler1.Sampler,ShadowMapTexCoord);
537 #endif
538  OutBiased4Moments.xz=mul(OptimizedSample.xz-0.5f,float2x2(-1.0f/3.0f,-0.75f,sqrt(3.0f),0.75f*sqrt(3.0f)));
539  OutBiased4Moments.yw=mul(OptimizedSample.yw,float2x2(0.125f,-0.125f,1.0f,1.0f));
540  OutBiased4Moments=lerp(OutBiased4Moments,float4(0.0f,0.628f,0.0f,0.628f),MomentBias);
541 }
542 
543 
545 void Convert4MomentToCanonical(out float4 OutBiased4Moments,float4 Moments0,float MomentBias=3.0e-7f){
546  OutBiased4Moments=Moments0;
547  OutBiased4Moments=lerp(OutBiased4Moments,float4(0.0f,0.375f,0.0f,0.375f),MomentBias);
548 }
550 void ConvertSplit4MomentToCanonical(out float4 OutBiased4Moments,float2 Moments0,float2 Moments1,float MomentBias=3.0e-7f){
551  OutBiased4Moments=float4(Moments0,Moments1);
552  OutBiased4Moments=lerp(OutBiased4Moments,float4(0.0f,0.375f,0.0f,0.375f),MomentBias);
553 }
556 void Convert4MomentOptimizedToCanonical(out float4 OutBiased4Moments,float4 OptimizedMoments0,float MomentBias=6.0e-5f){
557  OutBiased4Moments.xz=mul(OptimizedMoments0.xz-0.5f,float2x2(-1.0f/3.0f,-0.75f,sqrt(3.0f),0.75f*sqrt(3.0f)));
558  OutBiased4Moments.yw=mul(OptimizedMoments0.yw,float2x2(0.125f,-0.125f,1.0f,1.0f));
559  OutBiased4Moments=lerp(OutBiased4Moments,float4(0.0f,0.628f,0.0f,0.628f),MomentBias);
560 }
563 void ConvertSplit4MomentOptimizedToCanonical(out float4 OutBiased4Moments,float2 OptimizedMoments0,float2 OptimizedMoments1,float MomentBias=6.0e-5f){
564  float4 OptimizedMoments=float4(OptimizedMoments0,OptimizedMoments1);
565  OutBiased4Moments.xz=mul(OptimizedMoments.xz-0.5f,float2x2(-1.0f/3.0f,-0.75f,sqrt(3.0f),0.75f*sqrt(3.0f)));
566  OutBiased4Moments.yw=mul(OptimizedMoments.yw,float2x2(0.125f,-0.125f,1.0f,1.0f));
567  OutBiased4Moments=lerp(OutBiased4Moments,float4(0.0f,0.628f,0.0f,0.628f),MomentBias);
568 }
569 
570 
575 void ScaleShadowIntensity(out float OutShadowIntensity,float ShadowIntensity,float ShadowIntensityFactor,float2 ShadowMapTexCoord,float FragmentDepth){
576  OutShadowIntensity=saturate(ShadowIntensity*ShadowIntensityFactor);
577  bool OutOfRange=ShadowMapTexCoord.x<0.0f || ShadowMapTexCoord.x>1.0f ||
578  ShadowMapTexCoord.y<0.0f || ShadowMapTexCoord.y>1.0f ||
579  FragmentDepth<-1.0f || FragmentDepth>1.0f;
580  OutShadowIntensity=OutOfRange?0.0f:OutShadowIntensity;
581 }
582 
583 
587 void ComputeHardShadowIntensity(out float OutShadowIntensity,float SampledShadowMapDepth,float FragmentDepth,float DepthBias){
588  OutShadowIntensity=(SampledShadowMapDepth<mad(FragmentDepth-DepthBias,0.5f,0.5f))?1.0f:0.0f;
589 }
590 
591 
595 void ComputePCFShadowIntensity1x1(out float OutShadowIntensity,SSamplerTexturePair2D_float ShadowMapSampler,float2 ShadowMapTexCoord,float FragmentDepth,float4 ShadowMapSize,float DepthBias){
596 #if D3D_VERSION==9
597  ComputePCFShadowIntensity(OutShadowIntensity,ShadowMapSampler.Texture,ShadowMapSampler.Sampler,ShadowMapTexCoord,FragmentDepth,ShadowMapSize,1.0e-10f,0,DepthBias);
598 #elif D3D_VERSION==11
599  ComputePCFShadowIntensityBilinear(OutShadowIntensity,ShadowMapSampler.Texture,ShadowMapSampler.SamplerComparison,ShadowMapTexCoord,FragmentDepth,ShadowMapSize,1.0e-10f,0,DepthBias);
600 #endif
601 }
602 
606 void ComputePCFShadowIntensity5x5(out float OutShadowIntensity,SSamplerTexturePair2D_float ShadowMapSampler,float2 ShadowMapTexCoord,float FragmentDepth,float4 ShadowMapSize,float DepthBias){
607 #if D3D_VERSION==9
608  ComputePCFShadowIntensity(OutShadowIntensity,ShadowMapSampler.Texture,ShadowMapSampler.Sampler,ShadowMapTexCoord,FragmentDepth,ShadowMapSize,1.2f,2,DepthBias);
609 #elif D3D_VERSION==11
610  ComputePCFShadowIntensityBilinear(OutShadowIntensity,ShadowMapSampler.Texture,ShadowMapSampler.SamplerComparison,ShadowMapTexCoord,FragmentDepth,ShadowMapSize,1.2f,2,DepthBias);
611 #endif
612 }
613 
617 void ComputePCFShadowIntensity7x7(out float OutShadowIntensity,SSamplerTexturePair2D_float ShadowMapSampler,float2 ShadowMapTexCoord,float FragmentDepth,float4 ShadowMapSize,float DepthBias){
618 #if D3D_VERSION==9
619  ComputePCFShadowIntensity(OutShadowIntensity,ShadowMapSampler.Texture,ShadowMapSampler.Sampler,ShadowMapTexCoord,FragmentDepth,ShadowMapSize,1.8f,3,DepthBias);
620 #elif D3D_VERSION==11
621  ComputePCFShadowIntensityBilinear(OutShadowIntensity,ShadowMapSampler.Texture,ShadowMapSampler.SamplerComparison,ShadowMapTexCoord,FragmentDepth,ShadowMapSize,1.8f,3,DepthBias);
622 #endif
623 }
624 
628 void ComputePCFShadowIntensity9x9(out float OutShadowIntensity,SSamplerTexturePair2D_float ShadowMapSampler,float2 ShadowMapTexCoord,float FragmentDepth,float4 ShadowMapSize,float DepthBias){
629 #if D3D_VERSION==9
630  ComputePCFShadowIntensity(OutShadowIntensity,ShadowMapSampler.Texture,ShadowMapSampler.Sampler,ShadowMapTexCoord,FragmentDepth,ShadowMapSize,2.4f,4,DepthBias);
631 #elif D3D_VERSION==11
632  ComputePCFShadowIntensityBilinear(OutShadowIntensity,ShadowMapSampler.Texture,ShadowMapSampler.SamplerComparison,ShadowMapTexCoord,FragmentDepth,ShadowMapSize,2.4f,4,DepthBias);
633 #endif
634 }
635 
639 void ComputePCFShadowIntensity15x15(out float OutShadowIntensity,SSamplerTexturePair2D_float ShadowMapSampler,float2 ShadowMapTexCoord,float FragmentDepth,float4 ShadowMapSize,float DepthBias){
640 #if D3D_VERSION==9
641  ComputePCFShadowIntensity(OutShadowIntensity,ShadowMapSampler.Texture,ShadowMapSampler.Sampler,ShadowMapTexCoord,FragmentDepth,ShadowMapSize,4.3f,7,DepthBias);
642 #elif D3D_VERSION==11
643  ComputePCFShadowIntensityBilinear(OutShadowIntensity,ShadowMapSampler.Texture,ShadowMapSampler.SamplerComparison,ShadowMapTexCoord,FragmentDepth,ShadowMapSize,4.3f,7,DepthBias);
644 #endif
645 }
646 
647 
651 void ComputePCFShadowIntensityPoisson(out float OutShadowIntensity,SSamplerTexturePair2D_float ShadowMapSampler,float2 ShadowMapTexCoord,float FragmentDepth,float4 ShadowMapSize,float DepthBias,float KernelDiameter){
652  const float2 pSample[24]={float2(0.222626907535f,0.0376987419418f),float2(-0.288020237452f,0.0483084976027f),float2(0.148792471943f,0.371819322479f),float2(-0.236547109164f,-0.34200277074f),float2(-0.215270313225f,0.3687537531f),float2(0.0504826268158f,-0.510591250885f),float2(0.397889542792f,-0.339257480326f),float2(0.528289416978f,0.193135746913f),float2(-0.624405641543f,-0.00267040033168f),float2(0.042582582866f,0.717798243087f),float2(-0.265949625244f,-0.668857675789f),float2(-0.682615983924f,0.318685080441f),float2(-0.72656536118f,-0.28616597416f),float2(-0.555608194422f,-0.558757632487f),float2(0.813852960936f,-0.0490302757418f),float2(0.0153612941654f,-0.848023558844f),float2(-0.588613523901f,0.611835348797f),float2(0.808496940088f,0.336649119359f),float2(0.536490481955f,0.748683460864f),float2(-0.942823213098f,-0.0715127157808f),float2(-0.164551377044f,0.958722089919f),float2(0.305530222001f,-0.925670811422f),float2(0.815894543795f,-0.539824620967f),float2(0.587381917044f,-0.792860283726f)};
653  const float PI=3.1415926535897932384626433832795f;
654  // Determine a random rotation of the filter kernel using the shadow map texture
655  // coordinate as seed to achieve temporal coherence.
656  float Rotation=2.0f*PI*GetRandomNumber(ShadowMapTexCoord);
657  float2x2 RotationMatrix;
658  sincos(Rotation,RotationMatrix[0][1],RotationMatrix[0][0]);
659  RotationMatrix[1][0]=-RotationMatrix[0][1];
660  RotationMatrix[1][1]=RotationMatrix[0][0];
661  OutShadowIntensity=0.0f;
662  float BiasedDepth=mad(FragmentDepth-DepthBias,0.5f,0.5f);
663  [unroll] for(int i=0;i!=24;++i){
664  float2 OffsetTexCoord=ShadowMapTexCoord+mul(pSample[i],RotationMatrix)*ShadowMapSize.zw*KernelDiameter;
665 #if D3D_VERSION==9
666  float ShadowIntensity=(ShadowMapSampler.Texture.Sample(ShadowMapSampler.Sampler,OffsetTexCoord)<BiasedDepth)?1.0f:0.0f;
667 #elif D3D_VERSION==11
668  float ShadowIntensity=ShadowMapSampler.Texture.SampleCmp(ShadowMapSampler.SamplerComparison,OffsetTexCoord,BiasedDepth);
669 #endif
670  OutShadowIntensity+=ShadowIntensity/24.0f;
671  }
672 }
673 
674 
679 void ComputeExponentialShadowIntensity(out float OutShadowIntensity,float ExponentialShadowMapSample,float FragmentDepth,float DepthBias,float Factor=80.0f){
680  float BiasedDepth=FragmentDepth-DepthBias;
681  OutShadowIntensity=1.0f-exp(-Factor*BiasedDepth)*ExponentialShadowMapSample;
682  OutShadowIntensity=saturate(OutShadowIntensity);
683 }
684 
685 
690 void ComputeConvolutionShadowIntensity8(out float OutShadowIntensity,float2 pFourierCoefficient[8],float FragmentDepth,float DepthBias){
691  const float PI=3.1415926535897932384626433832795f;
692  float BiasedDepth=FragmentDepth-DepthBias;
693  // Evaluate the first complex basis function
694  float2 Fourier1;
695  sincos((BiasedDepth*0.5f+0.5f)*PI,Fourier1.y,Fourier1.x);
696  // Evaluate the other basis functions using complex exponentiation
697  float2 pBasisFunction[8];
698  pBasisFunction[0]=Fourier1;
699  float2 FourierSquare=Multiply(Fourier1,Fourier1);
700  [unroll] for(int i=1;i!=8;++i){
701  pBasisFunction[i]=Multiply(pBasisFunction[i-1],FourierSquare);
702  }
703  // Compute the shadow intensity which is a linear combination of the basis
704  // functions using the Fourier coefficients as weights
705  OutShadowIntensity=0.5f;
706  [unroll] for(int i=0;i!=8;++i){
707  float Constant=PI*(2.0f*i+1.0f);
708  float Summand=pBasisFunction[i].y*pFourierCoefficient[i].x-pBasisFunction[i].x*pFourierCoefficient[i].y;
709  OutShadowIntensity+=Summand*2.0f/Constant;
710  }
711  OutShadowIntensity=saturate(OutShadowIntensity);
712 }
713 
714 
716 void ComputeConvolutionShadowIntensity16(out float OutShadowIntensity,float2 pFourierCoefficient[16],float FragmentDepth,float DepthBias){
717  const float PI=3.1415926535897932384626433832795f;
718  float BiasedDepth=FragmentDepth-DepthBias;
719  // Evaluate the first complex basis function
720  float2 Fourier1;
721  sincos((BiasedDepth*0.5f+0.5f)*PI,Fourier1.y,Fourier1.x);
722  // Evaluate the other basis functions using complex exponentiation
723  float2 pBasisFunction[16];
724  pBasisFunction[0]=Fourier1;
725  float2 FourierSquare=Multiply(Fourier1,Fourier1);
726  [unroll] for(int i=1;i!=16;++i){
727  pBasisFunction[i]=Multiply(pBasisFunction[i-1],FourierSquare);
728  }
729  // Compute the shadow intensity which is a linear combination of the basis
730  // functions using the Fourier coefficients as weights
731  OutShadowIntensity=0.5f;
732  [unroll] for(int i=0;i!=16;++i){
733  float Constant=PI*(2.0f*i+1.0f);
734  float Summand=pBasisFunction[i].y*pFourierCoefficient[i].x-pBasisFunction[i].x*pFourierCoefficient[i].y;
735  OutShadowIntensity+=Summand*2.0f/Constant;
736  }
737  OutShadowIntensity=saturate(OutShadowIntensity);
738 }
739 
740 
745 void ComputeExponentialVarianceShadowIntensity(out float OutShadowIntensity,float4 ExponentialVarianceVector,float FragmentDepth,float DepthBias,float2 ExponentialVarianceFactors){
746  float BiasedDepth=FragmentDepth-DepthBias;
747  // Estimate the shadow intensity using ExponentialVarianceVector.xy
748  float b1=ExponentialVarianceVector.x;
749  float b2=ExponentialVarianceVector.y;
750  float Expectation=b1;
751  float Variance=b2-b1*b1;
752  float WarpedDepth=exp(ExponentialVarianceFactors.x*BiasedDepth);
753  float MinStandardDeviation=1.0e-4f*ExponentialVarianceFactors.x*WarpedDepth;
754  Variance=max(Variance,MinStandardDeviation*MinStandardDeviation);
755  float MeanDepthDifference=WarpedDepth-Expectation;
756  float ShadowIntensity1=(MeanDepthDifference<=0.0f)?0.0f:(1.0f-Variance/(Variance+MeanDepthDifference*MeanDepthDifference));
757 
758  // Estimate it using ExponentialVarianceVector.zw
759  b1=ExponentialVarianceVector.z;
760  b2=ExponentialVarianceVector.w;
761  Expectation=b1;
762  Variance=b2-b1*b1;
763  WarpedDepth=exp(ExponentialVarianceFactors.y*BiasedDepth);
764  MinStandardDeviation=1.0e-4f*ExponentialVarianceFactors.y*WarpedDepth;
765  Variance=max(Variance,MinStandardDeviation*MinStandardDeviation);
766  MeanDepthDifference=WarpedDepth-Expectation;
767  float ShadowIntensity2=(MeanDepthDifference>=0.0f)?0.0f:(1.0f-Variance/(Variance+MeanDepthDifference*MeanDepthDifference));
768  // Combine the results
769  OutShadowIntensity=saturate(max(ShadowIntensity1,ShadowIntensity2));
770 }
771 
772 
777 void Compute2MomentShadowIntensity(out float OutShadowIntensity,float2 Biased2Moments,float FragmentDepth,float DepthBias){
778  float Expectation=Biased2Moments.x;
779  float Variance=Biased2Moments.y-Biased2Moments.x*Biased2Moments.x;
780  float BiasedDepth=FragmentDepth-DepthBias;
781  float MeanDepthDifference=BiasedDepth-Expectation;
782  OutShadowIntensity=(MeanDepthDifference<=0.0f)?0.0f:(1.0f-Variance/(Variance+MeanDepthDifference*MeanDepthDifference));
783  OutShadowIntensity=saturate(OutShadowIntensity);
784 }
785 
786 
791 void Compute4MomentShadowIntensity(out float OutShadowIntensity,
792  float4 Biased4Moments,float FragmentDepth,float DepthBias)
793 {
794  // Use short-hands for the many formulae to come
795  float4 b=Biased4Moments;
796  float3 z;
797  z[0]=FragmentDepth-DepthBias;
798 
799  // Compute a Cholesky factorization of the Hankel matrix B storing only non-
800  // trivial entries or related products
801  float L21D11=mad(-b[0],b[1],b[2]);
802  float D11=mad(-b[0],b[0], b[1]);
803  float SquaredDepthVariance=mad(-b[1],b[1], b[3]);
804  float D22D11=dot(float2(SquaredDepthVariance,-L21D11),float2(D11,L21D11));
805  float InvD11=1.0f/D11;
806  float L21=L21D11*InvD11;
807 
808  // Obtain a scaled inverse image of bz=(1,z[0],z[0]*z[0])^T
809  float3 c=float3(1.0f,z[0],z[0]*z[0]);
810  // Forward substitution to solve L*c1=bz
811  c[1]-=b.x;
812  c[2]-=b.y+L21*c[1];
813  // Scaling to solve D*c2=c1
814  c[1]*=InvD11;
815  c[2]*=D11/D22D11;
816  // Backward substitution to solve L^T*c3=c2
817  c[1]-=L21*c[2];
818  c[0]-=dot(c.yz,b.xy);
819  // Solve the quadratic equation c[0]+c[1]*z+c[2]*z^2 to obtain solutions z[1]
820  // and z[2]
821  float InvC2=1.0f/c[2];
822  float p=c[1]*InvC2;
823  float q=c[0]*InvC2;
824  float D=((p*p)/4.0f)-q;
825  float r=sqrt(D);
826  z[1]=-(p/2.0f)-r;
827  z[2]=-(p/2.0f)+r;
828 
829  // Use a solution made of four deltas if the solution with three deltas is
830  // invalid
831  [branch] if(z[1]<-1.0f || z[2]>1.0f){
832  float zFree=((b[0]-b[2])*z[0]+b[3]-b[1])/(z[0]+b[2]-b[0]-b[1]*z[0]);
833  float w1Factor=(z[0]>zFree)?1.0f:0.0f;
834  // Construct a polynomial taking value zero at z[0] and 1, value 1 at -1 and
835  // value w1Factor at zFree. Start with a linear part and then multiply by
836  // linear factors to get the roots.
837  float2 Normalizers;
838  Normalizers.x=w1Factor/((zFree-z[0])*mad(zFree,zFree,-1.0f));
839  Normalizers.y=0.5f/((zFree+1.0f)*(z[0]+1.0f));
840  float4 Polynomial;
841  Polynomial[0]=mad(zFree,Normalizers.y,Normalizers.x);
842  Polynomial[1]=Normalizers.x-Normalizers.y;
843  // Multiply the polynomial by (z-z[0])
844  Polynomial[2]=Polynomial[1];
845  Polynomial[1]=mad(Polynomial[1],-z[0],Polynomial[0]);
846  Polynomial[0]*=-z[0];
847  // Multiply the polynomial by (z-1)
848  Polynomial[3]=Polynomial[2];
849  Polynomial.yz=Polynomial.xy-Polynomial.yz;
850  Polynomial[0]*=-1.0f;
851  // The shadow intensity is the dot product of the coefficients of this
852  // polynomial and the power moments for the respective powers
853  OutShadowIntensity=dot(Polynomial,float4(1.0f,b.xyz));
854  }
855  // Use the solution with three deltas
856  else{
857  float4 Switch=
858  (z[2]<z[0])?float4(z[1],z[0],1.0f,1.0f):(
859  (z[1]<z[0])?float4(z[0],z[1],0.0f,1.0f):
860  float4(0.0f,0.0f,0.0f,0.0f));
861  float Quotient=(Switch[0]*z[2]-b[0]*(Switch[0]+z[2])+b[1])/((z[2]-Switch[1])*(z[0]-z[1]));
862  OutShadowIntensity=Switch[2]+Switch[3]*Quotient;
863  }
864  OutShadowIntensity=saturate(OutShadowIntensity);
865 }
866 
867 
874 void Compute4MomentUnboundedShadowIntensity(out float OutShadowIntensity,
875  float4 Biased4Moments,float FragmentDepth,float DepthBias)
876 {
877  // Use short-hands for the many formulae to come
878  float4 b=Biased4Moments;
879  float3 z;
880  z[0]=FragmentDepth-DepthBias;
881 
882  // Compute a Cholesky factorization of the Hankel matrix B storing only non-
883  // trivial entries or related products
884  float L21D11=mad(-b[0],b[1],b[2]);
885  float D11=mad(-b[0],b[0], b[1]);
886  float SquaredDepthVariance=mad(-b[1],b[1], b[3]);
887  float D22D11=dot(float2(SquaredDepthVariance,-L21D11),float2(D11,L21D11));
888  float InvD11=1.0f/D11;
889  float L21=L21D11*InvD11;
890  float D22=D22D11*InvD11;
891  float InvD22=1.0f/D22;
892 
893  // Obtain a scaled inverse image of bz=(1,z[0],z[0]*z[0])^T
894  float3 c=float3(1.0f,z[0],z[0]*z[0]);
895  // Forward substitution to solve L*c1=bz
896  c[1]-=b.x;
897  c[2]-=b.y+L21*c[1];
898  // Scaling to solve D*c2=c1
899  c[1]*=InvD11;
900  c[2]*=InvD22;
901  // Backward substitution to solve L^T*c3=c2
902  c[1]-=L21*c[2];
903  c[0]-=dot(c.yz,b.xy);
904  // Solve the quadratic equation c[0]+c[1]*z+c[2]*z^2 to obtain solutions
905  // z[1] and z[2]
906  float InvC2=1.0f/c[2];
907  float p=c[1]*InvC2;
908  float q=c[0]*InvC2;
909  float D=(p*p*0.25f)-q;
910  float r=sqrt(D);
911  z[1]=-p*0.5f-r;
912  z[2]=-p*0.5f+r;
913  // Compute the shadow intensity by summing the appropriate weights
914  float4 Switch=
915  (z[2]<z[0])?float4(z[1],z[0],1.0f,1.0f):(
916  (z[1]<z[0])?float4(z[0],z[1],0.0f,1.0f):
917  float4(0.0f,0.0f,0.0f,0.0f));
918  float Quotient=(Switch[0]*z[2]-b[0]*(Switch[0]+z[2])+b[1])/((z[2]-Switch[1])*(z[0]-z[1]));
919  OutShadowIntensity=Switch[2]+Switch[3]*Quotient;
920  OutShadowIntensity=saturate(OutShadowIntensity);
921 }
922 
923 
929 void Compute2TMSMShadowIntensity(out float OutShadowIntensity,
930  float2 pFourierCoefficient[2],float FragmentDepth,float DepthBias,float MomentBias){
931  // Apply biasing
932  pFourierCoefficient[0]*=(1.0f-MomentBias);
933  pFourierCoefficient[1]*=(1.0f-MomentBias);
934  float BiasedDepth=FragmentDepth-DepthBias;
935  OutShadowIntensity=Get2TMSMMinimalWeight(pFourierCoefficient,BiasedDepth*0.5f+0.5f);
936  OutShadowIntensity=saturate(OutShadowIntensity);
937 }
938 
939 
949 void LoadDepthSample1(out float OutDepthSample,Texture2DMS<float,1> ShadowMap,float2 TexCoord,uint SampleIndex,float4 ShadowMapSize){
950  OutDepthSample=ShadowMap.Load(int2(TexCoord*ShadowMapSize.xy),SampleIndex)*2.0f-1.0f;
951 }
952 void LoadDepthSample2(out float OutDepthSample,Texture2DMS<float,2> ShadowMap,float2 TexCoord,uint SampleIndex,float4 ShadowMapSize){
953  OutDepthSample=ShadowMap.Load(int2(TexCoord*ShadowMapSize.xy),SampleIndex)*2.0f-1.0f;
954 }
955 void LoadDepthSample4(out float OutDepthSample,Texture2DMS<float,4> ShadowMap,float2 TexCoord,uint SampleIndex,float4 ShadowMapSize){
956  OutDepthSample=ShadowMap.Load(int2(TexCoord*ShadowMapSize.xy),SampleIndex)*2.0f-1.0f;
957 }
958 void LoadDepthSample8(out float OutDepthSample,Texture2DMS<float,8> ShadowMap,float2 TexCoord,uint SampleIndex,float4 ShadowMapSize){
959  OutDepthSample=ShadowMap.Load(int2(TexCoord*ShadowMapSize.xy),SampleIndex)*2.0f-1.0f;
960 }
962 
969 void AddShadowMapData_float(out float OutSum,float LHS,float RHS){
970  OutSum=LHS+RHS;
971 }
972 void AddShadowMapData_float2(out float2 OutSum,float2 LHS,float2 RHS){
973  OutSum=LHS+RHS;
974 }
975 void AddShadowMapData_float4(out float4 OutSum,float4 LHS,float4 RHS){
976  OutSum=LHS+RHS;
977 }
978 void AddShadowMapData_uint2(out uint2 OutSum,uint2 LHS,uint2 RHS){
979  OutSum=LHS+RHS;
980 }
981 void AddShadowMapData_uint4(out uint4 OutSum,uint4 LHS,uint4 RHS){
982  OutSum=LHS+RHS;
983 }
984 void AddShadowMapData_half4(out half4 OutSum,half4 LHS,half4 RHS){
985  OutSum=LHS+RHS;
986 }
988 
996 void ComputeSampleAverage_float(out float OutSampleAverage,float SampleSum,uint nSample){
997  OutSampleAverage=SampleSum/float(nSample);
998 }
999 void ComputeSampleAverage_float2(out float2 OutSampleAverage,float2 SampleSum,uint nSample){
1000  OutSampleAverage=SampleSum/float(nSample);
1001 }
1002 void ComputeSampleAverage_float4(out float4 OutSampleAverage,float4 SampleSum,uint nSample){
1003  OutSampleAverage=SampleSum/float(nSample);
1004 }
1005 void ComputeSampleAverage_uint2(out uint2 OutSampleAverage,uint2 SampleSum,uint nSample){
1006  OutSampleAverage=SampleSum/nSample;
1007 }
1008 void ComputeSampleAverage_uint4(out uint4 OutSampleAverage,uint4 SampleSum,uint nSample){
1009  OutSampleAverage=SampleSum/nSample;
1010 }
1011 void ComputeSampleAverage_half4(out half4 OutSampleAverage,half4 SampleSum,uint nSample){
1012  OutSampleAverage=half4(float4(SampleSum)/float(nSample));
1013 }
1015 
1016 
1027 void ApplyGaussianFilterHorizontal5_float4(out float4 OutFilteredValue,SSamplerTexturePair2D SourceSampler,float2 TexCoord,float4 TextureSize){
1028  OutFilteredValue=
1029  0.343406478631f*SourceSampler.Texture.Sample(SourceSampler.Sampler,TexCoord+float2(TextureSize.z,TextureSize.w)*float2(0.0f,0.0f))+
1030  0.328296760685f*SourceSampler.Texture.Sample(SourceSampler.Sampler,TexCoord+float2(TextureSize.z,TextureSize.w)*float2(-1.2608285375f,0.0f))+
1031  0.328296760685f*SourceSampler.Texture.Sample(SourceSampler.Sampler,TexCoord+float2(TextureSize.z,TextureSize.w)*float2(1.2608285375f,0.0f));
1032 }
1035 void ApplyGaussianFilterVertical5_float4(out float4 OutFilteredValue,SSamplerTexturePair2D SourceSampler,float2 TexCoord,float4 TextureSize){
1036  OutFilteredValue=
1037  0.343406478631f*SourceSampler.Texture.Sample(SourceSampler.Sampler,TexCoord+float2(TextureSize.z,TextureSize.w)*float2(0.0f,0.0f))+
1038  0.328296760685f*SourceSampler.Texture.Sample(SourceSampler.Sampler,TexCoord+float2(TextureSize.z,TextureSize.w)*float2(0.0f,-1.2608285375f))+
1039  0.328296760685f*SourceSampler.Texture.Sample(SourceSampler.Sampler,TexCoord+float2(TextureSize.z,TextureSize.w)*float2(0.0f,1.2608285375f));
1040 }
1043 void ApplyGaussianFilterHorizontal7_float4(out float4 OutFilteredValue,SSamplerTexturePair2D SourceSampler,float2 TexCoord,float4 TextureSize){
1044  OutFilteredValue=
1045  0.18379524343f*SourceSampler.Texture.Sample(SourceSampler.Sampler,TexCoord+float2(TextureSize.z,TextureSize.w)*float2(-2.31613202819f,0.0f))+
1046  0.432713776807f*SourceSampler.Texture.Sample(SourceSampler.Sampler,TexCoord+float2(TextureSize.z,TextureSize.w)*float2(-0.461496136794f,0.0f))+
1047  0.325387416687f*SourceSampler.Texture.Sample(SourceSampler.Sampler,TexCoord+float2(TextureSize.z,TextureSize.w)*float2(1.38628316249f,0.0f))+
1048  0.0581035630769f*SourceSampler.Texture.Sample(SourceSampler.Sampler,TexCoord+float2(TextureSize.z,TextureSize.w)*float2(3.0f,0.0f));
1049 }
1052 void ApplyGaussianFilterVertical7_float4(out float4 OutFilteredValue,SSamplerTexturePair2D SourceSampler,float2 TexCoord,float4 TextureSize){
1053  OutFilteredValue=
1054  0.18379524343f*SourceSampler.Texture.Sample(SourceSampler.Sampler,TexCoord+float2(TextureSize.z,TextureSize.w)*float2(0.0f,-2.31613202819f))+
1055  0.432713776807f*SourceSampler.Texture.Sample(SourceSampler.Sampler,TexCoord+float2(TextureSize.z,TextureSize.w)*float2(0.0f,-0.461496136794f))+
1056  0.325387416687f*SourceSampler.Texture.Sample(SourceSampler.Sampler,TexCoord+float2(TextureSize.z,TextureSize.w)*float2(0.0f,1.38628316249f))+
1057  0.0581035630769f*SourceSampler.Texture.Sample(SourceSampler.Sampler,TexCoord+float2(TextureSize.z,TextureSize.w)*float2(0.0f,3.0f));
1058 }
1061 void ApplyGaussianFilterHorizontal9_float4(out float4 OutFilteredValue,SSamplerTexturePair2D SourceSampler,float2 TexCoord,float4 TextureSize){
1062  OutFilteredValue=
1063  0.176635428315f*SourceSampler.Texture.Sample(SourceSampler.Sampler,TexCoord+float2(TextureSize.z,TextureSize.w)*float2(0.0f,0.0f))+
1064  0.124914026152f*SourceSampler.Texture.Sample(SourceSampler.Sampler,TexCoord+float2(TextureSize.z,TextureSize.w)*float2(-3.35259798724f,0.0f))+
1065  0.28676825969f*SourceSampler.Texture.Sample(SourceSampler.Sampler,TexCoord+float2(TextureSize.z,TextureSize.w)*float2(-1.43526128506f,0.0f))+
1066  0.28676825969f*SourceSampler.Texture.Sample(SourceSampler.Sampler,TexCoord+float2(TextureSize.z,TextureSize.w)*float2(1.43526128506f,0.0f))+
1067  0.124914026152f*SourceSampler.Texture.Sample(SourceSampler.Sampler,TexCoord+float2(TextureSize.z,TextureSize.w)*float2(3.35259798724f,0.0f));
1068 }
1071 void ApplyGaussianFilterVertical9_float4(out float4 OutFilteredValue,SSamplerTexturePair2D SourceSampler,float2 TexCoord,float4 TextureSize){
1072  OutFilteredValue=
1073  0.176635428315f*SourceSampler.Texture.Sample(SourceSampler.Sampler,TexCoord+float2(TextureSize.z,TextureSize.w)*float2(0.0f,0.0f))+
1074  0.124914026152f*SourceSampler.Texture.Sample(SourceSampler.Sampler,TexCoord+float2(TextureSize.z,TextureSize.w)*float2(0.0f,-3.35259798724f))+
1075  0.28676825969f*SourceSampler.Texture.Sample(SourceSampler.Sampler,TexCoord+float2(TextureSize.z,TextureSize.w)*float2(0.0f,-1.43526128506f))+
1076  0.28676825969f*SourceSampler.Texture.Sample(SourceSampler.Sampler,TexCoord+float2(TextureSize.z,TextureSize.w)*float2(0.0f,1.43526128506f))+
1077  0.124914026152f*SourceSampler.Texture.Sample(SourceSampler.Sampler,TexCoord+float2(TextureSize.z,TextureSize.w)*float2(0.0f,3.35259798724f));
1078 }
1081 void ApplyGaussianFilterHorizontal15_float4(out float4 OutFilteredValue,SSamplerTexturePair2D SourceSampler,float2 TexCoord,float4 TextureSize){
1082  OutFilteredValue=
1083  0.0649299817582f*SourceSampler.Texture.Sample(SourceSampler.Sampler,TexCoord+float2(TextureSize.z,TextureSize.w)*float2(-6.41300869194f,0.0f))+
1084  0.116774251219f*SourceSampler.Texture.Sample(SourceSampler.Sampler,TexCoord+float2(TextureSize.z,TextureSize.w)*float2(-4.43945485337f,0.0f))+
1085  0.169647595987f*SourceSampler.Texture.Sample(SourceSampler.Sampler,TexCoord+float2(TextureSize.z,TextureSize.w)*float2(-2.46624934622f,0.0f))+
1086  0.199094815228f*SourceSampler.Texture.Sample(SourceSampler.Sampler,TexCoord+float2(TextureSize.z,TextureSize.w)*float2(-0.4932400009f,0.0f))+
1087  0.188751042112f*SourceSampler.Texture.Sample(SourceSampler.Sampler,TexCoord+float2(TextureSize.z,TextureSize.w)*float2(1.47972988258f,0.0f))+
1088  0.14455532049f*SourceSampler.Texture.Sample(SourceSampler.Sampler,TexCoord+float2(TextureSize.z,TextureSize.w)*float2(3.45281792154f,0.0f))+
1089  0.0894303463716f*SourceSampler.Texture.Sample(SourceSampler.Sampler,TexCoord+float2(TextureSize.z,TextureSize.w)*float2(5.4261789926f,0.0f))+
1090  0.0268166468338f*SourceSampler.Texture.Sample(SourceSampler.Sampler,TexCoord+float2(TextureSize.z,TextureSize.w)*float2(7.0f,0.0f));
1091 }
1094 void ApplyGaussianFilterVertical15_float4(out float4 OutFilteredValue,SSamplerTexturePair2D SourceSampler,float2 TexCoord,float4 TextureSize){
1095  OutFilteredValue=
1096  0.0649299817582f*SourceSampler.Texture.Sample(SourceSampler.Sampler,TexCoord+float2(TextureSize.z,TextureSize.w)*float2(0.0f,-6.41300869194f))+
1097  0.116774251219f*SourceSampler.Texture.Sample(SourceSampler.Sampler,TexCoord+float2(TextureSize.z,TextureSize.w)*float2(0.0f,-4.43945485337f))+
1098  0.169647595987f*SourceSampler.Texture.Sample(SourceSampler.Sampler,TexCoord+float2(TextureSize.z,TextureSize.w)*float2(0.0f,-2.46624934622f))+
1099  0.199094815228f*SourceSampler.Texture.Sample(SourceSampler.Sampler,TexCoord+float2(TextureSize.z,TextureSize.w)*float2(0.0f,-0.4932400009f))+
1100  0.188751042112f*SourceSampler.Texture.Sample(SourceSampler.Sampler,TexCoord+float2(TextureSize.z,TextureSize.w)*float2(0.0f,1.47972988258f))+
1101  0.14455532049f*SourceSampler.Texture.Sample(SourceSampler.Sampler,TexCoord+float2(TextureSize.z,TextureSize.w)*float2(0.0f,3.45281792154f))+
1102  0.0894303463716f*SourceSampler.Texture.Sample(SourceSampler.Sampler,TexCoord+float2(TextureSize.z,TextureSize.w)*float2(0.0f,5.4261789926f))+
1103  0.0268166468338f*SourceSampler.Texture.Sample(SourceSampler.Sampler,TexCoord+float2(TextureSize.z,TextureSize.w)*float2(0.0f,7.0f));
1104 }
1105 
1106 
1109 void ApplyGaussianFilterHorizontal5_float2(out float4 OutFilteredValue,SSamplerTexturePair2D_float2 SourceSampler,float2 TexCoord,float4 TextureSize){
1110  OutFilteredValue.xy=
1111  0.343406478631f*SourceSampler.Texture.Sample(SourceSampler.Sampler,TexCoord+float2(TextureSize.z,TextureSize.w)*float2(0.0f,0.0f))+
1112  0.328296760685f*SourceSampler.Texture.Sample(SourceSampler.Sampler,TexCoord+float2(TextureSize.z,TextureSize.w)*float2(-1.2608285375f,0.0f))+
1113  0.328296760685f*SourceSampler.Texture.Sample(SourceSampler.Sampler,TexCoord+float2(TextureSize.z,TextureSize.w)*float2(1.2608285375f,0.0f));
1114  OutFilteredValue.zw=float2(0.0f,1.0f);
1115 }
1118 void ApplyGaussianFilterVertical5_float2(out float4 OutFilteredValue,SSamplerTexturePair2D_float2 SourceSampler,float2 TexCoord,float4 TextureSize){
1119  OutFilteredValue.xy=
1120  0.343406478631f*SourceSampler.Texture.Sample(SourceSampler.Sampler,TexCoord+float2(TextureSize.z,TextureSize.w)*float2(0.0f,0.0f))+
1121  0.328296760685f*SourceSampler.Texture.Sample(SourceSampler.Sampler,TexCoord+float2(TextureSize.z,TextureSize.w)*float2(0.0f,-1.2608285375f))+
1122  0.328296760685f*SourceSampler.Texture.Sample(SourceSampler.Sampler,TexCoord+float2(TextureSize.z,TextureSize.w)*float2(0.0f,1.2608285375f));
1123  OutFilteredValue.zw=float2(0.0f,1.0f);
1124 }
1127 void ApplyGaussianFilterHorizontal7_float2(out float4 OutFilteredValue,SSamplerTexturePair2D_float2 SourceSampler,float2 TexCoord,float4 TextureSize){
1128  OutFilteredValue.xy=
1129  0.18379524343f*SourceSampler.Texture.Sample(SourceSampler.Sampler,TexCoord+float2(TextureSize.z,TextureSize.w)*float2(-2.31613202819f,0.0f))+
1130  0.432713776807f*SourceSampler.Texture.Sample(SourceSampler.Sampler,TexCoord+float2(TextureSize.z,TextureSize.w)*float2(-0.461496136794f,0.0f))+
1131  0.325387416687f*SourceSampler.Texture.Sample(SourceSampler.Sampler,TexCoord+float2(TextureSize.z,TextureSize.w)*float2(1.38628316249f,0.0f))+
1132  0.0581035630769f*SourceSampler.Texture.Sample(SourceSampler.Sampler,TexCoord+float2(TextureSize.z,TextureSize.w)*float2(3.0f,0.0f));
1133  OutFilteredValue.zw=float2(0.0f,1.0f);
1134 }
1137 void ApplyGaussianFilterVertical7_float2(out float4 OutFilteredValue,SSamplerTexturePair2D_float2 SourceSampler,float2 TexCoord,float4 TextureSize){
1138  OutFilteredValue.xy=
1139  0.18379524343f*SourceSampler.Texture.Sample(SourceSampler.Sampler,TexCoord+float2(TextureSize.z,TextureSize.w)*float2(0.0f,-2.31613202819f))+
1140  0.432713776807f*SourceSampler.Texture.Sample(SourceSampler.Sampler,TexCoord+float2(TextureSize.z,TextureSize.w)*float2(0.0f,-0.461496136794f))+
1141  0.325387416687f*SourceSampler.Texture.Sample(SourceSampler.Sampler,TexCoord+float2(TextureSize.z,TextureSize.w)*float2(0.0f,1.38628316249f))+
1142  0.0581035630769f*SourceSampler.Texture.Sample(SourceSampler.Sampler,TexCoord+float2(TextureSize.z,TextureSize.w)*float2(0.0f,3.0f));
1143  OutFilteredValue.zw=float2(0.0f,1.0f);
1144 }
1147 void ApplyGaussianFilterHorizontal9_float2(out float4 OutFilteredValue,SSamplerTexturePair2D_float2 SourceSampler,float2 TexCoord,float4 TextureSize){
1148  OutFilteredValue.xy=
1149  0.176635428315f*SourceSampler.Texture.Sample(SourceSampler.Sampler,TexCoord+float2(TextureSize.z,TextureSize.w)*float2(0.0f,0.0f))+
1150  0.124914026152f*SourceSampler.Texture.Sample(SourceSampler.Sampler,TexCoord+float2(TextureSize.z,TextureSize.w)*float2(-3.35259798724f,0.0f))+
1151  0.28676825969f*SourceSampler.Texture.Sample(SourceSampler.Sampler,TexCoord+float2(TextureSize.z,TextureSize.w)*float2(-1.43526128506f,0.0f))+
1152  0.28676825969f*SourceSampler.Texture.Sample(SourceSampler.Sampler,TexCoord+float2(TextureSize.z,TextureSize.w)*float2(1.43526128506f,0.0f))+
1153  0.124914026152f*SourceSampler.Texture.Sample(SourceSampler.Sampler,TexCoord+float2(TextureSize.z,TextureSize.w)*float2(3.35259798724f,0.0f));
1154  OutFilteredValue.zw=float2(0.0f,1.0f);
1155 }
1158 void ApplyGaussianFilterVertical9_float2(out float4 OutFilteredValue,SSamplerTexturePair2D_float2 SourceSampler,float2 TexCoord,float4 TextureSize){
1159  OutFilteredValue.xy=
1160  0.176635428315f*SourceSampler.Texture.Sample(SourceSampler.Sampler,TexCoord+float2(TextureSize.z,TextureSize.w)*float2(0.0f,0.0f))+
1161  0.124914026152f*SourceSampler.Texture.Sample(SourceSampler.Sampler,TexCoord+float2(TextureSize.z,TextureSize.w)*float2(0.0f,-3.35259798724f))+
1162  0.28676825969f*SourceSampler.Texture.Sample(SourceSampler.Sampler,TexCoord+float2(TextureSize.z,TextureSize.w)*float2(0.0f,-1.43526128506f))+
1163  0.28676825969f*SourceSampler.Texture.Sample(SourceSampler.Sampler,TexCoord+float2(TextureSize.z,TextureSize.w)*float2(0.0f,1.43526128506f))+
1164  0.124914026152f*SourceSampler.Texture.Sample(SourceSampler.Sampler,TexCoord+float2(TextureSize.z,TextureSize.w)*float2(0.0f,3.35259798724f));
1165  OutFilteredValue.zw=float2(0.0f,1.0f);
1166 }
1169 void ApplyGaussianFilterHorizontal15_float2(out float4 OutFilteredValue,SSamplerTexturePair2D_float2 SourceSampler,float2 TexCoord,float4 TextureSize){
1170  OutFilteredValue.xy=
1171  0.0649299817582f*SourceSampler.Texture.Sample(SourceSampler.Sampler,TexCoord+float2(TextureSize.z,TextureSize.w)*float2(-6.41300869194f,0.0f))+
1172  0.116774251219f*SourceSampler.Texture.Sample(SourceSampler.Sampler,TexCoord+float2(TextureSize.z,TextureSize.w)*float2(-4.43945485337f,0.0f))+
1173  0.169647595987f*SourceSampler.Texture.Sample(SourceSampler.Sampler,TexCoord+float2(TextureSize.z,TextureSize.w)*float2(-2.46624934622f,0.0f))+
1174  0.199094815228f*SourceSampler.Texture.Sample(SourceSampler.Sampler,TexCoord+float2(TextureSize.z,TextureSize.w)*float2(-0.4932400009f,0.0f))+
1175  0.188751042112f*SourceSampler.Texture.Sample(SourceSampler.Sampler,TexCoord+float2(TextureSize.z,TextureSize.w)*float2(1.47972988258f,0.0f))+
1176  0.14455532049f*SourceSampler.Texture.Sample(SourceSampler.Sampler,TexCoord+float2(TextureSize.z,TextureSize.w)*float2(3.45281792154f,0.0f))+
1177  0.0894303463716f*SourceSampler.Texture.Sample(SourceSampler.Sampler,TexCoord+float2(TextureSize.z,TextureSize.w)*float2(5.4261789926f,0.0f))+
1178  0.0268166468338f*SourceSampler.Texture.Sample(SourceSampler.Sampler,TexCoord+float2(TextureSize.z,TextureSize.w)*float2(7.0f,0.0f));
1179  OutFilteredValue.zw=float2(0.0f,1.0f);
1180 }
1183 void ApplyGaussianFilterVertical15_float2(out float4 OutFilteredValue,SSamplerTexturePair2D_float2 SourceSampler,float2 TexCoord,float4 TextureSize){
1184  OutFilteredValue.xy=
1185  0.0649299817582f*SourceSampler.Texture.Sample(SourceSampler.Sampler,TexCoord+float2(TextureSize.z,TextureSize.w)*float2(0.0f,-6.41300869194f))+
1186  0.116774251219f*SourceSampler.Texture.Sample(SourceSampler.Sampler,TexCoord+float2(TextureSize.z,TextureSize.w)*float2(0.0f,-4.43945485337f))+
1187  0.169647595987f*SourceSampler.Texture.Sample(SourceSampler.Sampler,TexCoord+float2(TextureSize.z,TextureSize.w)*float2(0.0f,-2.46624934622f))+
1188  0.199094815228f*SourceSampler.Texture.Sample(SourceSampler.Sampler,TexCoord+float2(TextureSize.z,TextureSize.w)*float2(0.0f,-0.4932400009f))+
1189  0.188751042112f*SourceSampler.Texture.Sample(SourceSampler.Sampler,TexCoord+float2(TextureSize.z,TextureSize.w)*float2(0.0f,1.47972988258f))+
1190  0.14455532049f*SourceSampler.Texture.Sample(SourceSampler.Sampler,TexCoord+float2(TextureSize.z,TextureSize.w)*float2(0.0f,3.45281792154f))+
1191  0.0894303463716f*SourceSampler.Texture.Sample(SourceSampler.Sampler,TexCoord+float2(TextureSize.z,TextureSize.w)*float2(0.0f,5.4261789926f))+
1192  0.0268166468338f*SourceSampler.Texture.Sample(SourceSampler.Sampler,TexCoord+float2(TextureSize.z,TextureSize.w)*float2(0.0f,7.0f));
1193  OutFilteredValue.zw=float2(0.0f,1.0f);
1194 }
1195 
1196 
1199 void ApplyGaussianFilterHorizontal5_float(out float4 OutFilteredValue,SSamplerTexturePair2D_float SourceSampler,float2 TexCoord,float4 TextureSize){
1200  OutFilteredValue=
1201  0.343406478631f*SourceSampler.Texture.Sample(SourceSampler.Sampler,TexCoord+float2(TextureSize.z,TextureSize.w)*float2(0.0f,0.0f))+
1202  0.328296760685f*SourceSampler.Texture.Sample(SourceSampler.Sampler,TexCoord+float2(TextureSize.z,TextureSize.w)*float2(-1.2608285375f,0.0f))+
1203  0.328296760685f*SourceSampler.Texture.Sample(SourceSampler.Sampler,TexCoord+float2(TextureSize.z,TextureSize.w)*float2(1.2608285375f,0.0f));
1204 }
1207 void ApplyGaussianFilterVertical5_float(out float4 OutFilteredValue,SSamplerTexturePair2D_float SourceSampler,float2 TexCoord,float4 TextureSize){
1208  OutFilteredValue=
1209  0.343406478631f*SourceSampler.Texture.Sample(SourceSampler.Sampler,TexCoord+float2(TextureSize.z,TextureSize.w)*float2(0.0f,0.0f))+
1210  0.328296760685f*SourceSampler.Texture.Sample(SourceSampler.Sampler,TexCoord+float2(TextureSize.z,TextureSize.w)*float2(0.0f,-1.2608285375f))+
1211  0.328296760685f*SourceSampler.Texture.Sample(SourceSampler.Sampler,TexCoord+float2(TextureSize.z,TextureSize.w)*float2(0.0f,1.2608285375f));
1212 }
1215 void ApplyGaussianFilterHorizontal7_float(out float4 OutFilteredValue,SSamplerTexturePair2D_float SourceSampler,float2 TexCoord,float4 TextureSize){
1216  OutFilteredValue=
1217  0.18379524343f*SourceSampler.Texture.Sample(SourceSampler.Sampler,TexCoord+float2(TextureSize.z,TextureSize.w)*float2(-2.31613202819f,0.0f))+
1218  0.432713776807f*SourceSampler.Texture.Sample(SourceSampler.Sampler,TexCoord+float2(TextureSize.z,TextureSize.w)*float2(-0.461496136794f,0.0f))+
1219  0.325387416687f*SourceSampler.Texture.Sample(SourceSampler.Sampler,TexCoord+float2(TextureSize.z,TextureSize.w)*float2(1.38628316249f,0.0f))+
1220  0.0581035630769f*SourceSampler.Texture.Sample(SourceSampler.Sampler,TexCoord+float2(TextureSize.z,TextureSize.w)*float2(3.0f,0.0f));
1221 }
1224 void ApplyGaussianFilterVertical7_float(out float4 OutFilteredValue,SSamplerTexturePair2D_float SourceSampler,float2 TexCoord,float4 TextureSize){
1225  OutFilteredValue=
1226  0.18379524343f*SourceSampler.Texture.Sample(SourceSampler.Sampler,TexCoord+float2(TextureSize.z,TextureSize.w)*float2(0.0f,-2.31613202819f))+
1227  0.432713776807f*SourceSampler.Texture.Sample(SourceSampler.Sampler,TexCoord+float2(TextureSize.z,TextureSize.w)*float2(0.0f,-0.461496136794f))+
1228  0.325387416687f*SourceSampler.Texture.Sample(SourceSampler.Sampler,TexCoord+float2(TextureSize.z,TextureSize.w)*float2(0.0f,1.38628316249f))+
1229  0.0581035630769f*SourceSampler.Texture.Sample(SourceSampler.Sampler,TexCoord+float2(TextureSize.z,TextureSize.w)*float2(0.0f,3.0f));
1230 }
1233 void ApplyGaussianFilterHorizontal9_float(out float4 OutFilteredValue,SSamplerTexturePair2D_float SourceSampler,float2 TexCoord,float4 TextureSize){
1234  OutFilteredValue=
1235  0.176635428315f*SourceSampler.Texture.Sample(SourceSampler.Sampler,TexCoord+float2(TextureSize.z,TextureSize.w)*float2(0.0f,0.0f))+
1236  0.124914026152f*SourceSampler.Texture.Sample(SourceSampler.Sampler,TexCoord+float2(TextureSize.z,TextureSize.w)*float2(-3.35259798724f,0.0f))+
1237  0.28676825969f*SourceSampler.Texture.Sample(SourceSampler.Sampler,TexCoord+float2(TextureSize.z,TextureSize.w)*float2(-1.43526128506f,0.0f))+
1238  0.28676825969f*SourceSampler.Texture.Sample(SourceSampler.Sampler,TexCoord+float2(TextureSize.z,TextureSize.w)*float2(1.43526128506f,0.0f))+
1239  0.124914026152f*SourceSampler.Texture.Sample(SourceSampler.Sampler,TexCoord+float2(TextureSize.z,TextureSize.w)*float2(3.35259798724f,0.0f));
1240 }
1243 void ApplyGaussianFilterVertical9_float(out float4 OutFilteredValue,SSamplerTexturePair2D_float SourceSampler,float2 TexCoord,float4 TextureSize){
1244  OutFilteredValue=
1245  0.176635428315f*SourceSampler.Texture.Sample(SourceSampler.Sampler,TexCoord+float2(TextureSize.z,TextureSize.w)*float2(0.0f,0.0f))+
1246  0.124914026152f*SourceSampler.Texture.Sample(SourceSampler.Sampler,TexCoord+float2(TextureSize.z,TextureSize.w)*float2(0.0f,-3.35259798724f))+
1247  0.28676825969f*SourceSampler.Texture.Sample(SourceSampler.Sampler,TexCoord+float2(TextureSize.z,TextureSize.w)*float2(0.0f,-1.43526128506f))+
1248  0.28676825969f*SourceSampler.Texture.Sample(SourceSampler.Sampler,TexCoord+float2(TextureSize.z,TextureSize.w)*float2(0.0f,1.43526128506f))+
1249  0.124914026152f*SourceSampler.Texture.Sample(SourceSampler.Sampler,TexCoord+float2(TextureSize.z,TextureSize.w)*float2(0.0f,3.35259798724f));
1250 }
1253 void ApplyGaussianFilterHorizontal15_float(out float4 OutFilteredValue,SSamplerTexturePair2D_float SourceSampler,float2 TexCoord,float4 TextureSize){
1254  OutFilteredValue=
1255  0.0649299817582f*SourceSampler.Texture.Sample(SourceSampler.Sampler,TexCoord+float2(TextureSize.z,TextureSize.w)*float2(-6.41300869194f,0.0f))+
1256  0.116774251219f*SourceSampler.Texture.Sample(SourceSampler.Sampler,TexCoord+float2(TextureSize.z,TextureSize.w)*float2(-4.43945485337f,0.0f))+
1257  0.169647595987f*SourceSampler.Texture.Sample(SourceSampler.Sampler,TexCoord+float2(TextureSize.z,TextureSize.w)*float2(-2.46624934622f,0.0f))+
1258  0.199094815228f*SourceSampler.Texture.Sample(SourceSampler.Sampler,TexCoord+float2(TextureSize.z,TextureSize.w)*float2(-0.4932400009f,0.0f))+
1259  0.188751042112f*SourceSampler.Texture.Sample(SourceSampler.Sampler,TexCoord+float2(TextureSize.z,TextureSize.w)*float2(1.47972988258f,0.0f))+
1260  0.14455532049f*SourceSampler.Texture.Sample(SourceSampler.Sampler,TexCoord+float2(TextureSize.z,TextureSize.w)*float2(3.45281792154f,0.0f))+
1261  0.0894303463716f*SourceSampler.Texture.Sample(SourceSampler.Sampler,TexCoord+float2(TextureSize.z,TextureSize.w)*float2(5.4261789926f,0.0f))+
1262  0.0268166468338f*SourceSampler.Texture.Sample(SourceSampler.Sampler,TexCoord+float2(TextureSize.z,TextureSize.w)*float2(7.0f,0.0f));
1263 }
1266 void ApplyGaussianFilterVertical15_float(out float4 OutFilteredValue,SSamplerTexturePair2D_float SourceSampler,float2 TexCoord,float4 TextureSize){
1267  OutFilteredValue=
1268  0.0649299817582f*SourceSampler.Texture.Sample(SourceSampler.Sampler,TexCoord+float2(TextureSize.z,TextureSize.w)*float2(0.0f,-6.41300869194f))+
1269  0.116774251219f*SourceSampler.Texture.Sample(SourceSampler.Sampler,TexCoord+float2(TextureSize.z,TextureSize.w)*float2(0.0f,-4.43945485337f))+
1270  0.169647595987f*SourceSampler.Texture.Sample(SourceSampler.Sampler,TexCoord+float2(TextureSize.z,TextureSize.w)*float2(0.0f,-2.46624934622f))+
1271  0.199094815228f*SourceSampler.Texture.Sample(SourceSampler.Sampler,TexCoord+float2(TextureSize.z,TextureSize.w)*float2(0.0f,-0.4932400009f))+
1272  0.188751042112f*SourceSampler.Texture.Sample(SourceSampler.Sampler,TexCoord+float2(TextureSize.z,TextureSize.w)*float2(0.0f,1.47972988258f))+
1273  0.14455532049f*SourceSampler.Texture.Sample(SourceSampler.Sampler,TexCoord+float2(TextureSize.z,TextureSize.w)*float2(0.0f,3.45281792154f))+
1274  0.0894303463716f*SourceSampler.Texture.Sample(SourceSampler.Sampler,TexCoord+float2(TextureSize.z,TextureSize.w)*float2(0.0f,5.4261789926f))+
1275  0.0268166468338f*SourceSampler.Texture.Sample(SourceSampler.Sampler,TexCoord+float2(TextureSize.z,TextureSize.w)*float2(0.0f,7.0f));
1276 }
1277 
1278 
1287 void ApplyPrefixSumHorizontal_float4(inout RWTexture2D<float4> OutFilteredTexture,SSamplerTexturePair2D SourceSampler,uint3 ThreadID){
1288  uint Width,Height;
1289  OutFilteredTexture.GetDimensions(Width,Height);
1290  float4 PrefixSum=float4(0.0f,0.0f,0.0f,0.0f);
1291  for(uint i=0;i<Width;++i){
1292  PrefixSum+=mad(SourceSampler.Texture.Load(uint3(i,ThreadID.y,0)),2.0f,-1.0f);
1293  OutFilteredTexture[uint2(i,ThreadID.y)]=PrefixSum;
1294  }
1295 }
1296 
1299 void ApplyPrefixSumVertical_float4(inout RWTexture2D<float4> OutFilteredTexture,SSamplerTexturePair2D SourceSampler,uint3 ThreadID){
1300  uint Width,Height;
1301  OutFilteredTexture.GetDimensions(Width,Height);
1302  float4 PrefixSum=float4(0.0f,0.0f,0.0f,0.0f);
1303  for(uint i=0;i<Height;++i){
1304  PrefixSum+=SourceSampler.Texture.Load(uint3(ThreadID.x,i,0));
1305  OutFilteredTexture[uint2(ThreadID.x,i)]=PrefixSum;
1306  }
1307 }
1308 
1312 void ApplyPrefixSumHorizontal_uint4(inout RWTexture2D<uint4> OutFilteredTexture,SSamplerTexturePair2D SourceSampler,uint3 ThreadID,float2 FixedPrecision){
1313  uint Width,Height;
1314  OutFilteredTexture.GetDimensions(Width,Height);
1315  uint4 PrefixSum=uint4(0,0,0,0);
1316  for(uint i=0;i<Width;++i){
1317  PrefixSum+=uint4(SourceSampler.Texture.Load(uint3(i,ThreadID.y,0))*FixedPrecision.x);
1318  OutFilteredTexture[uint2(i,ThreadID.y)]=PrefixSum;
1319  }
1320 }
1321 
1324 void ApplyPrefixSumVertical_uint4(inout RWTexture2D<uint4> OutFilteredTexture,SSamplerTexturePair2D_uint4 SourceSampler,uint3 ThreadID){
1325  uint Width,Height;
1326  OutFilteredTexture.GetDimensions(Width,Height);
1327  uint4 PrefixSum=uint4(0,0,0,0);
1328  for(uint i=0;i<Height;++i){
1329  PrefixSum+=SourceSampler.Texture.Load(uint3(ThreadID.x,i,0));
1330  OutFilteredTexture[uint2(ThreadID.x,i)]=PrefixSum;
1331  }
1332 }
1333 
1335 void ApplyPrefixSumHorizontal_float2(inout RWTexture2D<float2> OutFilteredTexture,SSamplerTexturePair2D_float2 SourceSampler,uint3 ThreadID){
1336  uint Width,Height;
1337  OutFilteredTexture.GetDimensions(Width,Height);
1338  float2 PrefixSum=float2(0.0f,0.0f);
1339  for(uint i=0;i<Width;++i){
1340  PrefixSum+=mad(SourceSampler.Texture.Load(uint3(i,ThreadID.y,0)).xy,2.0f,-1.0f);
1341  OutFilteredTexture[uint2(i,ThreadID.y)]=PrefixSum;
1342  }
1343 }
1344 
1346 void ApplyPrefixSumVertical_float2(inout RWTexture2D<float2> OutFilteredTexture,SSamplerTexturePair2D_float2 SourceSampler,uint3 ThreadID){
1347  uint Width,Height;
1348  OutFilteredTexture.GetDimensions(Width,Height);
1349  float2 PrefixSum=float2(0.0f,0.0f);
1350  for(uint i=0;i<Height;++i){
1351  PrefixSum+=SourceSampler.Texture.Load(uint3(ThreadID.x,i,0)).xy;
1352  OutFilteredTexture[uint2(ThreadID.x,i)]=PrefixSum;
1353  }
1354 }
1355 
1358 void ApplyPrefixSumHorizontal_uint2(inout RWTexture2D<uint2> OutFilteredTexture,SSamplerTexturePair2D_float2 SourceSampler,uint3 ThreadID,float2 FixedPrecision){
1359  uint Width,Height;
1360  OutFilteredTexture.GetDimensions(Width,Height);
1361  uint2 PrefixSum=uint2(0,0);
1362  for(uint i=0;i<Width;++i){
1363  PrefixSum+=uint2(SourceSampler.Texture.Load(uint3(i,ThreadID.y,0))*FixedPrecision.x);
1364  OutFilteredTexture[uint2(i,ThreadID.y)]=PrefixSum;
1365  }
1366 }
1367 
1370 void ApplyPrefixSumVertical_uint2(inout RWTexture2D<uint2> OutFilteredTexture,SSamplerTexturePair2D_uint2 SourceSampler,uint3 ThreadID){
1371  uint Width,Height;
1372  OutFilteredTexture.GetDimensions(Width,Height);
1373  uint2 PrefixSum=uint2(0,0);
1374  for(uint i=0;i<Height;++i){
1375  PrefixSum+=SourceSampler.Texture.Load(uint3(ThreadID.x,i,0));
1376  OutFilteredTexture[uint2(ThreadID.x,i)]=PrefixSum;
1377  }
1378 }
1379 
1382 void ApplyPrefixSumHorizontal_half4(inout RWTexture2D<half4> OutFilteredTexture,SSamplerTexturePair2D SourceSampler,uint3 ThreadID){
1383  uint Width,Height;
1384  OutFilteredTexture.GetDimensions(Width,Height);
1385  float4 PrefixSum=float4(0.0f,0.0f,0.0f,0.0f);
1386  for(uint i=0;i<Width;++i){
1387  PrefixSum+=SourceSampler.Texture.Load(uint3(i,ThreadID.y,0));
1388  OutFilteredTexture[uint2(i,ThreadID.y)]=(half4)(PrefixSum);
1389  }
1390 }
1391 
1394 void ApplyPrefixSumVertical_half4(inout RWTexture2D<half4> OutFilteredTexture,SSamplerTexturePair2D SourceSampler,uint3 ThreadID){
1395  uint Width,Height;
1396  OutFilteredTexture.GetDimensions(Width,Height);
1397  float4 PrefixSum=float4(0.0f,0.0f,0.0f,0.0f);
1398  for(uint i=0;i<Height;++i){
1399  PrefixSum+=SourceSampler.Texture.Load(uint3(ThreadID.x,i,0));
1400  OutFilteredTexture[uint2(ThreadID.x,i)]=(half4)(PrefixSum);
1401  }
1402 }
1403 
1416 void GetSummedAreaTableThreadGroupCount(out uint3 nOutThreadGroupHorizontal,out uint3 nOutThreadGroupVertical,uint3 ThreadGroupSizeHorizontal,uint3 ThreadGroupSizeVertical,float4 TextureSize){
1417  uint Width=(uint)(TextureSize.x);
1418  uint Height=(uint)(TextureSize.y);
1419  nOutThreadGroupHorizontal=uint3(1,Height/ThreadGroupSizeHorizontal.y,1);
1420  nOutThreadGroupVertical=uint3(Width/ThreadGroupSizeVertical.x,1,1);
1421 }
1422 
1423 
1435 void ComputeRectangleAverage_uint4(out float4 OutAverageValue,float2 LeftTop,float2 RightBottom,SSamplerTexturePair2D_uint4 SummedAreaTableSampler,float4 TextureSize,float2 FixedPrecision){
1436  // The summed area table is essentially off by one because the top left texel
1437  // already holds the integral over the top left texel. Compensate for that.
1438  LeftTop-=TextureSize.zw;
1439  RightBottom-=TextureSize.zw;
1440  // Round the texture coordinates to integer texels
1441  float2 LeftTopPixel=LeftTop*TextureSize.xy;
1442  float2 RightBottomPixel=RightBottom*TextureSize.xy;
1443  float2 LeftTopPixelFloor=floor(LeftTopPixel);
1444  float2 RightBottomPixelFloor=floor(RightBottomPixel);
1445  int2 iLeftTop=int2(LeftTopPixelFloor);
1446  int2 iRightBottom=int2(RightBottomPixelFloor);
1447  float2 LeftTopFactor=float2(1.0f,1.0f)-(LeftTopPixel-LeftTopPixelFloor);
1448  float2 RightBottomFactor=RightBottomPixel-RightBottomPixelFloor;
1449  // Sample the summed area table at all relevant locations. The first two indices
1450  // determine whether we are at the left top or right bottom of the rectangle,
1451  // the latter two determine the pixel offset.
1452  uint4 Samples[2][2][2][2];
1453  [unroll] for(int x=0;x!=2;++x){
1454  int TexelX=(x==0)?iLeftTop.x:iRightBottom.x;
1455  [unroll] for(int y=0;y!=2;++y){
1456  int TexelY=(y==0)?iLeftTop.y:iRightBottom.y;
1457  [unroll] for(int z=0;z!=2;++z){
1458  [unroll] for(int w=0;w!=2;++w){
1459  Samples[x][y][z][w]=SummedAreaTableSampler.Texture.Load(int3(TexelX+z,TexelY+w,0));
1460  }
1461  }
1462  }
1463  }
1464  // Compute integrals for various rectangles
1465  float4 pCornerIntegral[2][2];
1466  [unroll] for(int x=0;x!=2;++x){
1467  [unroll] for(int y=0;y!=2;++y){
1468  pCornerIntegral[x][y]=float4(Samples[x][y][0][0]+Samples[x][y][1][1]-Samples[x][y][1][0]-Samples[x][y][0][1]);
1469  }
1470  }
1471  float4 pEdgeIntegral[4]={
1472  // Right edge
1473  float4(Samples[1][0][0][1]+Samples[1][1][1][0]-Samples[1][0][1][1]-Samples[1][1][0][0]),
1474  // Top edge
1475  float4(Samples[0][0][1][0]+Samples[1][0][0][1]-Samples[0][0][1][1]-Samples[1][0][0][0]),
1476  // Left edge
1477  float4(Samples[0][0][0][1]+Samples[0][1][1][0]-Samples[0][0][1][1]-Samples[0][1][0][0]),
1478  // Bottom edge
1479  float4(Samples[0][1][1][0]+Samples[1][1][0][1]-Samples[0][1][1][1]-Samples[1][1][0][0])
1480  };
1481  float4 CenterIntegral=float4(Samples[0][0][1][1]+Samples[1][1][0][0]-Samples[0][1][1][0]-Samples[1][0][0][1]);
1482  // Compute the integral over the given rectangle
1483  float4 Integral=CenterIntegral;
1484  Integral+=pCornerIntegral[0][0]*(LeftTopFactor.x*LeftTopFactor.y);
1485  Integral+=pCornerIntegral[0][1]*(LeftTopFactor.x*RightBottomFactor.y);
1486  Integral+=pCornerIntegral[1][0]*(RightBottomFactor.x*LeftTopFactor.y);
1487  Integral+=pCornerIntegral[1][1]*(RightBottomFactor.x*RightBottomFactor.y);
1488  Integral+=pEdgeIntegral[0]*RightBottomFactor.x;
1489  Integral+=pEdgeIntegral[1]*LeftTopFactor.y;
1490  Integral+=pEdgeIntegral[2]*LeftTopFactor.x;
1491  Integral+=pEdgeIntegral[3]*RightBottomFactor.y;
1492  // Get from a non-normalized integral to moments
1493  float2 Size=RightBottomPixel-LeftTopPixel;
1494  OutAverageValue=Integral*FixedPrecision.y/(Size.x*Size.y);
1495 }
1496 
1497 
1502 void ComputeIntegerRectangleAverage_uint4(out float4 OutAverageValue,float2 LeftTop,float2 RightBottom,SSamplerTexturePair2D_uint4 SummedAreaTableSampler,float4 TextureSize,float2 FixedPrecision){
1503  int2 iLeftTop=int2(round(LeftTop*TextureSize.xy))-1;
1504  int2 iRightBottom=int2(round(RightBottom*TextureSize.xy))-1;
1505  uint4 Sample[2][2]={
1506  {SummedAreaTableSampler.Texture.Load(int3(iLeftTop.x,iLeftTop.y,0)),
1507  SummedAreaTableSampler.Texture.Load(int3(iLeftTop.x,iRightBottom.y,0))},
1508  {SummedAreaTableSampler.Texture.Load(int3(iRightBottom.x,iLeftTop.y,0)),
1509  SummedAreaTableSampler.Texture.Load(int3(iRightBottom.x,iRightBottom.y,0))}
1510  };
1511  uint4 Integral=Sample[0][0]+Sample[1][1]-Sample[0][1]-Sample[1][0];
1512  uint2 Size=iRightBottom-iLeftTop;
1513  OutAverageValue=float4(Integral)*FixedPrecision.y/float(Size.x*Size.y);
1514 }
1515 
1516 
1519 void ComputeRectangleAverage_float4(out float4 OutAverageValue,float2 LeftTop,float2 RightBottom,SSamplerTexturePair2D SummedAreaTableSampler,float4 TextureSize){
1520  // The summed area table is essentially off by one because the top left texel
1521  // already holds the integral over the top left texel, but then again texture
1522  // interpolation places the texel value at 0.5. Compensate for that.
1523  LeftTop-=0.5f*TextureSize.zw;
1524  RightBottom-=0.5f*TextureSize.zw;
1525  // Sample (with interpolation but without mip-mapping) at the given texture
1526  // coordinates
1527  float4 LeftTopSample=SummedAreaTableSampler.Texture.SampleLevel(SummedAreaTableSampler.Sampler,LeftTop,0.0f);
1528  float4 RightTopSample=SummedAreaTableSampler.Texture.SampleLevel(SummedAreaTableSampler.Sampler,float2(RightBottom.x,LeftTop.y),0.0f);
1529  float4 LeftBottomSample=SummedAreaTableSampler.Texture.SampleLevel(SummedAreaTableSampler.Sampler,float2(LeftTop.x,RightBottom.y),0.0f);
1530  float4 RightBottomSample=SummedAreaTableSampler.Texture.SampleLevel(SummedAreaTableSampler.Sampler,RightBottom,0.0f);
1531  // Compute the difference
1532  float4 Integral=(LeftTopSample-RightTopSample)+(RightBottomSample-LeftBottomSample);
1533  float2 Size=(RightBottom-LeftTop)*TextureSize.xy;
1534  OutAverageValue=mad(Integral/(Size.x*Size.y),0.5f,0.5f);
1535 }
1536 
1537 
1540 void ComputeRectangleAverage_uint2(out float2 OutAverageValue,float2 LeftTop,float2 RightBottom,SSamplerTexturePair2D_uint2 SummedAreaTableSampler,float4 TextureSize,float2 FixedPrecision){
1541  // The summed area table is essentially off by one because the top left texel
1542  // already holds the integral over the top left texel. Compensate for that.
1543  LeftTop-=TextureSize.zw;
1544  RightBottom-=TextureSize.zw;
1545  // Round the texture coordinates to integer texels
1546  float2 LeftTopPixel=LeftTop*TextureSize.xy;
1547  float2 RightBottomPixel=RightBottom*TextureSize.xy;
1548  float2 LeftTopPixelFloor=floor(LeftTopPixel);
1549  float2 RightBottomPixelFloor=floor(RightBottomPixel);
1550  int2 iLeftTop=int2(LeftTopPixelFloor);
1551  int2 iRightBottom=int2(RightBottomPixelFloor);
1552  float2 LeftTopFactor=float2(1.0f,1.0f)-(LeftTopPixel-LeftTopPixelFloor);
1553  float2 RightBottomFactor=RightBottomPixel-RightBottomPixelFloor;
1554  // Sample the summed area table at all relevant locations. The first two indices
1555  // determine whether we are at the left top or right bottom of the rectangle,
1556  // the latter two determine the pixel offset.
1557  uint2 Samples[2][2][2][2];
1558  [unroll] for(int x=0;x!=2;++x){
1559  int TexelX=(x==0)?iLeftTop.x:iRightBottom.x;
1560  [unroll] for(int y=0;y!=2;++y){
1561  int TexelY=(y==0)?iLeftTop.y:iRightBottom.y;
1562  [unroll] for(int z=0;z!=2;++z){
1563  [unroll] for(int w=0;w!=2;++w){
1564  Samples[x][y][z][w]=SummedAreaTableSampler.Texture.Load(int3(TexelX+z,TexelY+w,0));
1565  }
1566  }
1567  }
1568  }
1569  // Compute integrals for various rectangles
1570  float2 pCornerIntegral[2][2];
1571  [unroll] for(int x=0;x!=2;++x){
1572  [unroll] for(int y=0;y!=2;++y){
1573  pCornerIntegral[x][y]=float2(Samples[x][y][0][0]+Samples[x][y][1][1]-Samples[x][y][1][0]-Samples[x][y][0][1]);
1574  }
1575  }
1576  float2 pEdgeIntegral[4]={
1577  // Right edge
1578  float2(Samples[1][0][0][1]+Samples[1][1][1][0]-Samples[1][0][1][1]-Samples[1][1][0][0]),
1579  // Top edge
1580  float2(Samples[0][0][1][0]+Samples[1][0][0][1]-Samples[0][0][1][1]-Samples[1][0][0][0]),
1581  // Left edge
1582  float2(Samples[0][0][0][1]+Samples[0][1][1][0]-Samples[0][0][1][1]-Samples[0][1][0][0]),
1583  // Bottom edge
1584  float2(Samples[0][1][1][0]+Samples[1][1][0][1]-Samples[0][1][1][1]-Samples[1][1][0][0])
1585  };
1586  float2 CenterIntegral=float2(Samples[0][0][1][1]+Samples[1][1][0][0]-Samples[0][1][1][0]-Samples[1][0][0][1]);
1587  // Compute the integral over the given rectangle
1588  float2 Integral=CenterIntegral;
1589  Integral+=pCornerIntegral[0][0]*(LeftTopFactor.x*LeftTopFactor.y);
1590  Integral+=pCornerIntegral[0][1]*(LeftTopFactor.x*RightBottomFactor.y);
1591  Integral+=pCornerIntegral[1][0]*(RightBottomFactor.x*LeftTopFactor.y);
1592  Integral+=pCornerIntegral[1][1]*(RightBottomFactor.x*RightBottomFactor.y);
1593  Integral+=pEdgeIntegral[0]*RightBottomFactor.x;
1594  Integral+=pEdgeIntegral[1]*LeftTopFactor.y;
1595  Integral+=pEdgeIntegral[2]*LeftTopFactor.x;
1596  Integral+=pEdgeIntegral[3]*RightBottomFactor.y;
1597  // Get from a non-normalized integral to moments
1598  float2 Size=RightBottomPixel-LeftTopPixel;
1599  OutAverageValue=Integral*FixedPrecision.y/(Size.x*Size.y);
1600 }
1601 
1602 
1604 void ComputeIntegerRectangleAverage_uint2(out float2 OutAverageValue,float2 LeftTop,float2 RightBottom,SSamplerTexturePair2D_uint2 SummedAreaTableSampler,float4 TextureSize,float2 FixedPrecision){
1605  int2 iLeftTop=int2(round(LeftTop*TextureSize.xy))-1;
1606  int2 iRightBottom=int2(round(RightBottom*TextureSize.xy))-1;
1607  uint2 Sample[2][2]={
1608  {SummedAreaTableSampler.Texture.Load(int3(iLeftTop.x,iLeftTop.y,0)),
1609  SummedAreaTableSampler.Texture.Load(int3(iLeftTop.x,iRightBottom.y,0))},
1610  {SummedAreaTableSampler.Texture.Load(int3(iRightBottom.x,iLeftTop.y,0)),
1611  SummedAreaTableSampler.Texture.Load(int3(iRightBottom.x,iRightBottom.y,0))}
1612  };
1613  uint2 Integral=Sample[0][0]+Sample[1][1]-Sample[0][1]-Sample[1][0];
1614  uint2 Size=iRightBottom-iLeftTop;
1615  OutAverageValue=float2(Integral)*FixedPrecision.y/float(Size.x*Size.y);
1616 }
1617 
1618 
1621 void ComputeRectangleAverage_float2(out float2 OutAverageValue,float2 LeftTop,float2 RightBottom,SSamplerTexturePair2D_float2 SummedAreaTableSampler,float4 TextureSize){
1622  // The summed area table is essentially off by one because the top left texel
1623  // already holds the integral over the top left texel, but then again texture
1624  // interpolation places the texel value at 0.5. Compensate for that.
1625  LeftTop-=0.5f*TextureSize.zw;
1626  RightBottom-=0.5f*TextureSize.zw;
1627  // Sample (with interpolation but without mip-mapping) at the given texture
1628  // coordinates
1629  float2 LeftTopSample=SummedAreaTableSampler.Texture.SampleLevel(SummedAreaTableSampler.Sampler,LeftTop,0.0f);
1630  float2 RightTopSample=SummedAreaTableSampler.Texture.SampleLevel(SummedAreaTableSampler.Sampler,float2(RightBottom.x,LeftTop.y),0.0f);
1631  float2 LeftBottomSample=SummedAreaTableSampler.Texture.SampleLevel(SummedAreaTableSampler.Sampler,float2(LeftTop.x,RightBottom.y),0.0f);
1632  float2 RightBottomSample=SummedAreaTableSampler.Texture.SampleLevel(SummedAreaTableSampler.Sampler,RightBottom,0.0f);
1633  // Compute the difference
1634  float2 Integral=(LeftTopSample-RightTopSample)+(RightBottomSample-LeftBottomSample);
1635  float2 Size=(RightBottom-LeftTop)*TextureSize.xy;
1636  OutAverageValue=mad(Integral/(Size.x*Size.y),0.5f,0.5f);
1637 }
1638 
1639 
1652 void ComputeFixedPrecision(out float2 OutFixedPrecision,float3x2 KernelSizeParameter,float2 ShadowMapSize){
1653  float2 MaxKernelSizeInPixels=ceil(1.0f+2.0f*KernelSizeParameter._21_22*ShadowMapSize.xy);
1654  OutFixedPrecision.x=4294967295.0f/(MaxKernelSizeInPixels.x*MaxKernelSizeInPixels.y);
1655  OutFixedPrecision.y=1.0f/OutFixedPrecision.x;
1656 }
1657 
1658 
1668 void GetBlockerSearchRectangle(out float2 OutSearchRegionLeftTop,out float2 OutSearchRegionRightBottom,float2 SearchRegionCenter,float3x2 KernelSizeParameter,float4 ShadowMapSize){
1669  OutSearchRegionLeftTop=saturate(SearchRegionCenter-KernelSizeParameter._21_22-0.5f*ShadowMapSize.zw);
1670  OutSearchRegionRightBottom=saturate(SearchRegionCenter+KernelSizeParameter._21_22+0.5f*ShadowMapSize.zw);
1671 }
1672 
1673 
1682 void GetShadowFilterRectangle(out float2 OutFilterRegionLeftTop,out float2 OutFilterRegionRightBottom,float2 FilterRegionCenter,float2 KernelSize){
1683  OutFilterRegionLeftTop=saturate(FilterRegionCenter-KernelSize);
1684  OutFilterRegionRightBottom=saturate(FilterRegionCenter+KernelSize);
1685 }
1686 
1687 
1714 void EstimatePenumbraSize(out float2 OutKernelSize,out float OutDepthBias,float OccluderDepth,float FragmentDepth,float3x2 LightParameter,float3x2 KernelSizeParameter,float MaxDepthBias){
1715  float2 Numerator=LightParameter._11_12*(FragmentDepth-OccluderDepth);
1716  float2 Denominator=LightParameter._21_22*OccluderDepth+LightParameter._31_32;
1717  OutKernelSize=max(KernelSizeParameter._11_12,min(KernelSizeParameter._21_22,Numerator/Denominator));
1718  OutDepthBias=MaxDepthBias*clamp(OutKernelSize.x*KernelSizeParameter._31,KernelSizeParameter._32,1.0f);
1719 }
1720 
1721 
1731 void ComputeDirectionalLightSoftShadowParameters(out float3x2 OutLightParameter,float4x4 ViewToProjectionSpace,float2 LightSourceAngle){
1732  // Compute the bounding box dimensions of the view frustum of the shadow map
1733  float3 FrustumExtents=float3(
1734  2.0f*(ViewToProjectionSpace._11*ViewToProjectionSpace._44-ViewToProjectionSpace._14*ViewToProjectionSpace._41)/
1735  (ViewToProjectionSpace._11*ViewToProjectionSpace._11-ViewToProjectionSpace._41*ViewToProjectionSpace._41),
1736  2.0f*(ViewToProjectionSpace._22*ViewToProjectionSpace._44-ViewToProjectionSpace._24*ViewToProjectionSpace._42)/
1737  (ViewToProjectionSpace._22*ViewToProjectionSpace._22-ViewToProjectionSpace._42*ViewToProjectionSpace._42),
1738  dot(float4(ViewToProjectionSpace._43,-ViewToProjectionSpace._43,-ViewToProjectionSpace._33,ViewToProjectionSpace._33),float4(ViewToProjectionSpace._33,ViewToProjectionSpace._43,ViewToProjectionSpace._34,ViewToProjectionSpace._44))/
1739  (ViewToProjectionSpace._33*(ViewToProjectionSpace._33-ViewToProjectionSpace._43))
1740  );
1741  // Compute a factor that turns a depth difference into a kernel size as texture
1742  // coordinate
1743  OutLightParameter._11=0.5f*tan(0.5f*LightSourceAngle.x)*FrustumExtents.z/FrustumExtents.x;
1744  OutLightParameter._12=0.5f*tan(0.5f*LightSourceAngle.y)*FrustumExtents.z/FrustumExtents.y;
1745  // The denominator is constant one
1746  OutLightParameter._21_22=float2(0.0f,0.0f);
1747  OutLightParameter._31_32=float2(1.0f,1.0f);
1748 }
1749 
1750 
1755 void Compute2MomentAverageBlockerDepth(out float OutAverageBlockerDepth,out float OutBlockerSearchShadowIntensity,float2 BlockerSearchBiased2Moments,float FragmentDepth,float DepthBias){
1756  // Estimate how much of the kernel is covered by surfaces closer than the
1757  // fragment depth
1758  float Expectation=BlockerSearchBiased2Moments.x;
1759  float Variance=BlockerSearchBiased2Moments.y-Expectation*Expectation;
1760  float BiasedDepth=FragmentDepth-DepthBias;
1761  float MeanDepthDifference=BiasedDepth-Expectation;
1762  float BlockerWeight=(MeanDepthDifference<=0.0f)?0.0f:(1.0f-Variance/(Variance+MeanDepthDifference*MeanDepthDifference));
1763  // Solve for the depth of these surfaces (assuming that there are only two
1764  // distinct depths in the kernel)
1765  OutAverageBlockerDepth=(Expectation-FragmentDepth*(1.0f-BlockerWeight))/BlockerWeight;
1766  OutAverageBlockerDepth=clamp(OutAverageBlockerDepth,-1.0f,1.0f);
1767  // Are we in the umbra or fully lit?
1768  bool Umbra=(BlockerWeight>0.99f);
1769  OutBlockerSearchShadowIntensity=(Umbra?1.0f:(-1.0f));
1770 }
1771 
1772 
1777 void Compute4MomentAverageBlockerDepth(out float OutAverageBlockerDepth,out float OutBlockerSearchShadowIntensity,float4 BlockerSearchBiased4Moments,float FragmentDepth){
1778  // Use short-hands for the many formulae to come
1779  float4 b=BlockerSearchBiased4Moments;
1780  float3 z;
1781  z[0]=FragmentDepth;
1782 
1783  // Compute a Cholesky factorization of the Hankel matrix B storing only non-
1784  // trivial entries or related products
1785  float L21D11=mad(-b[0],b[1],b[2]);
1786  float D11=mad(-b[0],b[0], b[1]);
1787  float SquaredDepthVariance=mad(-b[1],b[1], b[3]);
1788  float D22D11=dot(float2(SquaredDepthVariance,-L21D11),float2(D11,L21D11));
1789  float InvD11=1.0f/D11;
1790  float L21=L21D11*InvD11;
1791 
1792  // Obtain a scaled inverse image of bz=(1,z[0],z[0]*z[0])^T
1793  float3 c=float3(1.0f,z[0],z[0]*z[0]);
1794  // Forward substitution to solve L*c1=bz
1795  c[1]-=b.x;
1796  c[2]-=b.y+L21*c[1];
1797  // Scaling to solve D*c2=c1
1798  c[1]*=InvD11;
1799  c[2]*=D11/D22D11;
1800  // Backward substitution to solve L^T*c3=c2
1801  c[1]-=L21*c[2];
1802  c[0]-=dot(c.yz,b.xy);
1803  // Solve the quadratic equation c[0]+c[1]*z+c[2]*z^2 to obtain solutions
1804  // z[1] and z[2]
1805  z.yz=GetRoots(c);
1806  // Compute weights of the Dirac-deltas at the roots
1807  float3 Weight;
1808  Weight[0]=(z[1]*z[2]-b[0]*(z[1]+z[2])+b[1])/((z[0]-z[1])*(z[0]-z[2]));
1809  Weight[1]=(z[0]*z[2]-b[0]*(z[0]+z[2])+b[1])/((z[2]-z[1])*(z[0]-z[1]));
1810  Weight[2]=1.0f-Weight[0]-Weight[1];
1811  // Compute the shadow intensity and the unnormalized average depth of occluders
1812  float AverageBlockerDepthIntegral=((z[1]<z[0])?(Weight[1]*z[1]):0.0f)+((z[2]<z[0])?(Weight[2]*z[2]):0.0f);
1813  float BlockerSearchShadowIntensity=((z[1]<z[0])?Weight[1]:0.0f)+((z[2]<z[0])?Weight[2]:0.0f);
1814  const float FullyLitBias=1.0e-3f;
1815  OutAverageBlockerDepth=clamp((FullyLitBias*z[0]+AverageBlockerDepthIntegral)/(FullyLitBias+BlockerSearchShadowIntensity),-1.0f,1.0f);
1816  OutBlockerSearchShadowIntensity=(BlockerSearchShadowIntensity>0.99f)?1.0f:(-1.0f);
1817 }
1818 
1819 
1829 void ComputePCSSAverageBlockerDepth(out float OutAverageBlockerDepth,out float OutBlockerSearchShadowIntensity,SSamplerTexturePair2D_float ShadowMapSampler,float2 ShadowMapTexCoord,float FragmentDepth,float4 ShadowMapSize,float DepthBias,float3x2 KernelSizeParameter){
1830  OutAverageBlockerDepth=0.0f;
1831  float TotalWeight=0.0f;
1832  float2 KernelSizePixels=KernelSizeParameter._21_22*ShadowMapSize.xy;
1833  float2 iShadowMapTexel=ShadowMapTexCoord*ShadowMapSize.xy;
1834  int2 iLeftTop=int2(iShadowMapTexel-KernelSizePixels);
1835  int2 iRightBottom=iLeftTop+int2(2.0001f*KernelSizePixels);
1836  DepthBias*=KernelSizeParameter._32;
1837  float BiasedDepth=mad(FragmentDepth-DepthBias,0.5f,0.5f);
1838  for(int x=iLeftTop.x;x<=iRightBottom.x;++x){
1839  for(int y=iLeftTop.y;y<=iRightBottom.y;++y){
1840  float Depth=ShadowMapSampler.Texture.Load(int3(x,y,0));
1841  float Weight=(Depth<BiasedDepth)?1.0f:0.0f;
1842  OutAverageBlockerDepth+=Weight*Depth;
1843  TotalWeight+=Weight;
1844  }
1845  }
1846  OutAverageBlockerDepth=(TotalWeight<=0.0f)?1.0f:OutAverageBlockerDepth/TotalWeight;
1847  OutAverageBlockerDepth=OutAverageBlockerDepth*2.0f-1.0f;
1848  // Are we in the umbra or fully lit?
1849  float2 KernelSize=1.0f+float2(iRightBottom-iLeftTop);
1850  float nKernelTexel=KernelSize.x*KernelSize.y;
1851  bool Umbra=(TotalWeight>nKernelTexel*0.99f);
1852  bool FullyLit=(TotalWeight<nKernelTexel*0.01f);
1853  OutBlockerSearchShadowIntensity=(Umbra?1.0f:(FullyLit?0.0f:(-1.0f)));
1854 }
1855 
1856 
1867 void PickShadowIntensity(out float OutShadowIntensity,float FilteredShadowIntensity,float BlockerSearchShadowIntensity){
1868  [branch] if(BlockerSearchShadowIntensity>=0.0f){
1869  OutShadowIntensity=BlockerSearchShadowIntensity;
1870  }
1871  else{
1872  OutShadowIntensity=FilteredShadowIntensity;
1873  }
1874 }
1875 
1876 
1882 void ComputeIntegerPCSSShadowIntensity(out float OutShadowIntensity,SSamplerTexturePair2D_float ShadowMapSampler,float2 FilterRegionLeftTop,float2 FilterRegionRightBottom,float FragmentDepth,float4 ShadowMapSize,float DepthBias){
1883  float BiasedDepth=mad(FragmentDepth-DepthBias,0.5f,0.5f);
1884  // Round the corners of the rectangle to the grid
1885  float2 iLeftTop=round(FilterRegionLeftTop*ShadowMapSize.xy);
1886  float2 iRightBottom=round(FilterRegionRightBottom*ShadowMapSize.xy);
1887  // Determine the number of required samples and whether the tap count is odd
1888  float2 nFractionalSample=0.5f*(iRightBottom-iLeftTop)-0.01f;
1889  float2 nSample=ceil(nFractionalSample);
1890  bool2 TapCountOdd=(nFractionalSample+0.25f<nSample);
1891  // Prepare sampling of the last row and last column
1892  float2 RightBottomWeight=TapCountOdd?float2(1.0f,1.0f):float2(2.0f,2.0f);
1893  float2 RightBottomTexCoord=(TapCountOdd?(iRightBottom-0.5f):(iRightBottom-1.0f))*ShadowMapSize.zw;
1894  // Sample everything except for the right column
1895  float2 InteriorLeftTop=(iLeftTop+1.0f)*ShadowMapSize.zw;
1896  float2 StepSize=2.0f*ShadowMapSize.zw;
1897  float2 InteriorRightBottom=InteriorLeftTop+(nSample-1.0f)*StepSize-ShadowMapSize.zw;
1898  OutShadowIntensity=0.0f;
1899  float TotalWeight=0.0f;
1900  [loop] for(float x=InteriorLeftTop.x;x<InteriorRightBottom.x;x+=StepSize.x){
1901  [loop] for(float y=InteriorLeftTop.y;y<InteriorRightBottom.y;y+=StepSize.y){
1902  OutShadowIntensity+=ShadowMapSampler.Texture.SampleCmpLevelZero(ShadowMapSampler.SamplerComparison,float2(x,y),BiasedDepth);
1903  TotalWeight+=1.0f;
1904  }
1905  // Here is a good spot to take care of the bottom row
1906  OutShadowIntensity+=0.5f*RightBottomWeight.y*ShadowMapSampler.Texture.SampleCmpLevelZero(ShadowMapSampler.SamplerComparison,float2(x,RightBottomTexCoord.y),BiasedDepth);
1907  TotalWeight+=0.5f*RightBottomWeight.y;
1908  }
1909  OutShadowIntensity*=2.0f;
1910  TotalWeight*=2.0f;
1911  // Now take care of the right column
1912  [loop] for(float y=InteriorLeftTop.y;y<InteriorRightBottom.y;y+=StepSize.y){
1913  OutShadowIntensity+=RightBottomWeight.x*ShadowMapSampler.Texture.SampleCmpLevelZero(ShadowMapSampler.SamplerComparison,float2(RightBottomTexCoord.x,y),BiasedDepth);
1914  TotalWeight+=RightBottomWeight.x;
1915  }
1916  OutShadowIntensity*=2.0f;
1917  TotalWeight*=2.0f;
1918  // Finish it with the bottom right
1919  OutShadowIntensity+=RightBottomWeight.x*RightBottomWeight.y*ShadowMapSampler.Texture.SampleCmpLevelZero(ShadowMapSampler.SamplerComparison,RightBottomTexCoord,BiasedDepth);
1920  TotalWeight+=RightBottomWeight.x*RightBottomWeight.y;
1921  // Normalize
1922  float2 KernelSize=iRightBottom-iLeftTop;
1923  OutShadowIntensity/=KernelSize.x*KernelSize.y;
1924 }
1925 
1926 
1932 void ComputePCSSShadowIntensity(out float OutShadowIntensity,float BlockerSearchShadowIntensity,SSamplerTexturePair2D_float ShadowMapSampler,float2 FilterRegionLeftTop,float2 FilterRegionRightBottom,float FragmentDepth,float4 ShadowMapSize,float DepthBias){
1933  // Abort early if the blocker search solved the problem already
1934  [branch] if(BlockerSearchShadowIntensity>=0.0f){
1935  OutShadowIntensity=BlockerSearchShadowIntensity;
1936  return;
1937  }
1938  float BiasedDepth=mad(FragmentDepth-DepthBias,0.5f,0.5f);
1939  // Figure out the geometry of the kernel with respect to the pixel grid
1940  float2 iLeftTop;
1941  float2 LeftTopFactor=modf(FilterRegionLeftTop*ShadowMapSize.xy,iLeftTop);
1942  float2 iRightBottom;
1943  float2 RightBottomFactor=modf(FilterRegionRightBottom*ShadowMapSize.xy,iRightBottom);
1944  // Determine how many samples will be needed (one sample fetches four adjacent
1945  // texels)
1946  float2 nFractionalSample=0.5f*(iRightBottom+float2(0.99f,0.99f)-iLeftTop);
1947  float2 nSample=ceil(nFractionalSample);
1948  bool2 TapCountOdd=(nFractionalSample+0.25f<nSample);
1949  // Determine where the first and last samples need to be located between texels
1950  // to get the right relative weighting and how much weight they need in total
1951  float2 LeftTopWeight=2.0f-LeftTopFactor;
1952  float2 LeftTopOffset=1.0f/LeftTopWeight;
1953  float2 RightBottomWeight=TapCountOdd?RightBottomFactor:(1.0f+RightBottomFactor);
1954  float2 RightBottomOffset=TapCountOdd?float2(0.0f,0.0f):(1.0f-1.0f/RightBottomWeight);
1955  // Handle the case of kernels with a single column and/or a single row of
1956  // samples
1957  bool2 SingleSample=(nSample<1.5f);
1958  float2 SingleWeight=(1.0f-LeftTopFactor)+RightBottomFactor;
1959  float2 SingleOffset=RightBottomFactor/SingleWeight;
1960  LeftTopWeight=SingleSample?SingleWeight:LeftTopWeight;
1961  LeftTopOffset=SingleSample?SingleOffset:LeftTopOffset;
1962  RightBottomWeight=SingleSample?float2(0.0f,0.0f):RightBottomWeight;
1963  RightBottomOffset=SingleSample?float2(0.0f,0.0f):RightBottomOffset;
1964  // Sample the interior of the filter kernel (where weighting is trivial). While
1965  // taking care of this it is opportune to also take care of the top and bottom
1966  // edge.
1967  float TotalOcclusion=0.0f;
1968  float2 LeftTopTexCoord=(iLeftTop+0.5f+LeftTopOffset)*ShadowMapSize.zw;
1969  float2 RightBottomTexCoord=(iLeftTop-1.5f+2.0f*nSample+RightBottomOffset)*ShadowMapSize.zw;
1970  float2 StepSize=2.0f*ShadowMapSize.zw;
1971  float2 InteriorLeftTop=(iLeftTop+3.0f)*ShadowMapSize.zw;
1972  float2 InteriorPastEnd=InteriorLeftTop+(nSample-2.5f)*StepSize;
1973  [loop] for(float x=InteriorLeftTop.x;x<InteriorPastEnd.x;x+=StepSize.x){
1974  // Top
1975  TotalOcclusion+=0.5f*LeftTopWeight.y*ShadowMapSampler.Texture.SampleCmpLevelZero(ShadowMapSampler.SamplerComparison,float2(x,LeftTopTexCoord.y),BiasedDepth);
1976  // Interior
1977  [loop] for(float y=InteriorLeftTop.y;y<InteriorPastEnd.y;y+=StepSize.y){
1978  TotalOcclusion+=ShadowMapSampler.Texture.SampleCmpLevelZero(ShadowMapSampler.SamplerComparison,float2(x,y),BiasedDepth);
1979  }
1980  // Bottom
1981  TotalOcclusion+=0.5f*RightBottomWeight.y*ShadowMapSampler.Texture.SampleCmpLevelZero(ShadowMapSampler.SamplerComparison,float2(x,RightBottomTexCoord.y),BiasedDepth);
1982  }
1983  TotalOcclusion*=4.0f;
1984  // Sample the remainder of the outer rim piece by piece
1985  // Left top
1986  TotalOcclusion+=LeftTopWeight.x*LeftTopWeight.y*ShadowMapSampler.Texture.SampleCmpLevelZero(ShadowMapSampler.SamplerComparison,LeftTopTexCoord,BiasedDepth);
1987  // Right top
1988  if(!SingleSample.x){
1989  TotalOcclusion+=RightBottomWeight.x*LeftTopWeight.y*ShadowMapSampler.Texture.SampleCmpLevelZero(ShadowMapSampler.SamplerComparison,float2(RightBottomTexCoord.x,LeftTopTexCoord.y),BiasedDepth);
1990  }
1991  // Continue with the vertical edges
1992  [loop] for(float y=InteriorLeftTop.y;y<InteriorPastEnd.y;y+=StepSize.y){
1993  // Left
1994  TotalOcclusion+=LeftTopWeight.x*2.0f*ShadowMapSampler.Texture.SampleCmpLevelZero(ShadowMapSampler.SamplerComparison,float2(LeftTopTexCoord.x,y),BiasedDepth);
1995  // Right
1996  TotalOcclusion+=RightBottomWeight.x*2.0f*ShadowMapSampler.Texture.SampleCmpLevelZero(ShadowMapSampler.SamplerComparison,float2(RightBottomTexCoord.x,y),BiasedDepth);
1997  }
1998  // Left bottom
1999  if(!SingleSample.y){
2000  TotalOcclusion+=LeftTopWeight.x*RightBottomWeight.y*ShadowMapSampler.Texture.SampleCmpLevelZero(ShadowMapSampler.SamplerComparison,float2(LeftTopTexCoord.x,RightBottomTexCoord.y),BiasedDepth);
2001  }
2002  // Right bottom
2003  if(!SingleSample.x && !SingleSample.y){
2004  TotalOcclusion+=RightBottomWeight.x*RightBottomWeight.y*ShadowMapSampler.Texture.SampleCmpLevelZero(ShadowMapSampler.SamplerComparison,RightBottomTexCoord,BiasedDepth);
2005  }
2006  // Divide by the area of the filter kernel to get the end result
2007  float2 KernelSize=(FilterRegionRightBottom-FilterRegionLeftTop)*ShadowMapSize.xy;
2008  TotalOcclusion/=KernelSize.x*KernelSize.y;
2009  OutShadowIntensity=TotalOcclusion;
2010 }
void Sample2TMSMShadowMap(out float2 pOutFourierCoefficient[2], SSamplerTexturePair2D _2TMSMShadowMapSampler, float2 ShadowMapTexCoord)
Definition: Shadow.fx:452
void Convert2MomentToCanonical(out float2 OutBiased2Moments, float2 Moments0, float MomentBias=0.0f)
Definition: Shadow.fx:479
void ComputePCSSShadowIntensity(out float OutShadowIntensity, float BlockerSearchShadowIntensity, SSamplerTexturePair2D_float ShadowMapSampler, float2 FilterRegionLeftTop, float2 FilterRegionRightBottom, float FragmentDepth, float4 ShadowMapSize, float DepthBias)
Definition: Shadow.fx:1932
void ApplyPrefixSumHorizontal_uint4(inout RWTexture2D< uint4 > OutFilteredTexture, SSamplerTexturePair2D SourceSampler, uint3 ThreadID, float2 FixedPrecision)
Definition: Shadow.fx:1312
void Compute4MomentUnboundedShadowIntensity(out float OutShadowIntensity, float4 Biased4Moments, float FragmentDepth, float DepthBias)
Definition: Shadow.fx:874
void ApplyGaussianFilterHorizontal7_float2(out float4 OutFilteredValue, SSamplerTexturePair2D_float2 SourceSampler, float2 TexCoord, float4 TextureSize)
Definition: Shadow.fx:1127
void ComputePCFShadowIntensity9x9(out float OutShadowIntensity, SSamplerTexturePair2D_float ShadowMapSampler, float2 ShadowMapTexCoord, float FragmentDepth, float4 ShadowMapSize, float DepthBias)
Definition: Shadow.fx:628
void AddShadowMapData_float(out float OutSum, float LHS, float RHS)
Definition: Shadow.fx:969
void ApplyGaussianFilterHorizontal5_float4(out float4 OutFilteredValue, SSamplerTexturePair2D SourceSampler, float2 TexCoord, float4 TextureSize)
Definition: Shadow.fx:1027
void ComputePCFShadowIntensity1x1(out float OutShadowIntensity, SSamplerTexturePair2D_float ShadowMapSampler, float2 ShadowMapTexCoord, float FragmentDepth, float4 ShadowMapSize, float DepthBias)
Definition: Shadow.fx:595
void ApplyPrefixSumVertical_uint2(inout RWTexture2D< uint2 > OutFilteredTexture, SSamplerTexturePair2D_uint2 SourceSampler, uint3 ThreadID)
Definition: Shadow.fx:1370
void ApplyGaussianFilterHorizontal15_float2(out float4 OutFilteredValue, SSamplerTexturePair2D_float2 SourceSampler, float2 TexCoord, float4 TextureSize)
Definition: Shadow.fx:1169
void ApplyGaussianFilterVertical15_float(out float4 OutFilteredValue, SSamplerTexturePair2D_float SourceSampler, float2 TexCoord, float4 TextureSize)
Definition: Shadow.fx:1266
void GetShadowFilterRectangle(out float2 OutFilterRegionLeftTop, out float2 OutFilterRegionRightBottom, float2 FilterRegionCenter, float2 KernelSize)
Definition: Shadow.fx:1682
float3 GetRoots(float4 Coefficient)
void ComputeExponentialShadowIntensity(out float OutShadowIntensity, float ExponentialShadowMapSample, float FragmentDepth, float DepthBias, float Factor=80.0f)
Definition: Shadow.fx:679
void ComputeMomentVector4MomentsOptimized_float4(out float4 Out4MomentsOptimized_float4, float FragmentDepth)
Definition: Shadow.fx:173
void ComputeWorldSpacePositionUnderCursor(out float3 OutWorldSpacePosition, Texture2DMS< float, 1 > SceneDepthTexture, float4 SceneDepthTextureSize, int2 iCursorPosition, float4x4 CameraProjectionToWorldSpace)
Definition: Shadow.fx:321
void ComputeTrigonometricMomentVector(out float4 OutFourier1_2, float FragmentDepth)
Definition: Shadow.fx:122
void ApplyGaussianFilterVertical7_float4(out float4 OutFilteredValue, SSamplerTexturePair2D SourceSampler, float2 TexCoord, float4 TextureSize)
Definition: Shadow.fx:1052
void ApplyPrefixSumHorizontal_float2(inout RWTexture2D< float2 > OutFilteredTexture, SSamplerTexturePair2D_float2 SourceSampler, uint3 ThreadID)
Definition: Shadow.fx:1335
void ComputeSpotLightCamera(out float4x4 OutViewToWorldSpace, out float4x4 OutViewToProjectionSpace, float3 WorldSpaceLightPosition, float3 WorldSpaceConeAxisDirection, float OuterConeAngle, float NearClippingPlane, float FarClippingPlane)
Definition: Shadow.fx:273
void ApplyGaussianFilterVertical5_float4(out float4 OutFilteredValue, SSamplerTexturePair2D SourceSampler, float2 TexCoord, float4 TextureSize)
Definition: Shadow.fx:1035
void ComputeMomentVectorExponential(out float OutExponential, float FragmentDepth, float Factor=80.0f)
Definition: Shadow.fx:54
void ApplyGaussianFilterVertical5_float(out float4 OutFilteredValue, SSamplerTexturePair2D_float SourceSampler, float2 TexCoord, float4 TextureSize)
Definition: Shadow.fx:1207
void SampleExponentialVarianceShadowMap(out float4 OutExponentialVarianceVector, SSamplerTexturePair2D ExponentialVarianceShadowMapSampler0, float2 ShadowMapTexCoord)
Definition: Shadow.fx:348
void ComputeMomentVector4Moments_float2_float2(out float2 Out4Moments0_float2, out float2 Out4Moments1_float2, float FragmentDepth)
Definition: Shadow.fx:185
void Sample4MomentOptimizedSplitShadowMap(out float4 OutBiased4Moments, SSamplerTexturePair2D_float2 _4MomentOptimizedShadowMapSampler0, SSamplerTexturePair2D_float2 _4MomentOptimizedShadowMapSampler1, float2 ShadowMapTexCoord, float MomentBias=6.0e-5f)
Definition: Shadow.fx:529
void Compute4MomentAverageBlockerDepth(out float OutAverageBlockerDepth, out float OutBlockerSearchShadowIntensity, float4 BlockerSearchBiased4Moments, float FragmentDepth)
Definition: Shadow.fx:1777
void EstimatePenumbraSize(out float2 OutKernelSize, out float OutDepthBias, float OccluderDepth, float FragmentDepth, float3x2 LightParameter, float3x2 KernelSizeParameter, float MaxDepthBias)
Definition: Shadow.fx:1714
void ApplyGaussianFilterVertical5_float2(out float4 OutFilteredValue, SSamplerTexturePair2D_float2 SourceSampler, float2 TexCoord, float4 TextureSize)
Definition: Shadow.fx:1118
void ComputePCFShadowIntensity15x15(out float OutShadowIntensity, SSamplerTexturePair2D_float ShadowMapSampler, float2 ShadowMapTexCoord, float FragmentDepth, float4 ShadowMapSize, float DepthBias)
Definition: Shadow.fx:639
void ComputeRectangleAverage_uint2(out float2 OutAverageValue, float2 LeftTop, float2 RightBottom, SSamplerTexturePair2D_uint2 SummedAreaTableSampler, float4 TextureSize, float2 FixedPrecision)
Definition: Shadow.fx:1540
void ApplyPrefixSumVertical_float2(inout RWTexture2D< float2 > OutFilteredTexture, SSamplerTexturePair2D_float2 SourceSampler, uint3 ThreadID)
Definition: Shadow.fx:1346
void ComputeRectangleAverage_float4(out float4 OutAverageValue, float2 LeftTop, float2 RightBottom, SSamplerTexturePair2D SummedAreaTableSampler, float4 TextureSize)
Definition: Shadow.fx:1519
void ComputeDirectionalLightSoftShadowParameters(out float3x2 OutLightParameter, float4x4 ViewToProjectionSpace, float2 LightSourceAngle)
Definition: Shadow.fx:1731
void ComputeConvolutionShadowIntensity8(out float OutShadowIntensity, float2 pFourierCoefficient[8], float FragmentDepth, float DepthBias)
Definition: Shadow.fx:690
void ApplyGaussianFilterHorizontal9_float4(out float4 OutFilteredValue, SSamplerTexturePair2D SourceSampler, float2 TexCoord, float4 TextureSize)
Definition: Shadow.fx:1061
void ComputeShadowMapCoordinate(out float2 OutShadowMapTexCoord, out float OutShadowMapDepth, float4 ShadowMapProjectionSpacePosition, float4 ShadowMapSize)
Definition: Shadow.fx:299
void Compute2MomentShadowIntensity(out float OutShadowIntensity, float2 Biased2Moments, float FragmentDepth, float DepthBias)
Definition: Shadow.fx:777
void Convert4MomentOptimizedToCanonical(out float4 OutBiased4Moments, float4 OptimizedMoments0, float MomentBias=6.0e-5f)
Definition: Shadow.fx:556
void ConvertShadowIntensityToColor(out float4 OutColor, float ShadowIntensity)
Definition: Shadow.fx:46
void ConvertSplit4MomentOptimizedToCanonical(out float4 OutBiased4Moments, float2 OptimizedMoments0, float2 OptimizedMoments1, float MomentBias=6.0e-5f)
Definition: Shadow.fx:563
void ApplyGaussianFilterHorizontal15_float4(out float4 OutFilteredValue, SSamplerTexturePair2D SourceSampler, float2 TexCoord, float4 TextureSize)
Definition: Shadow.fx:1081
void ComputePCFShadowIntensityPoisson(out float OutShadowIntensity, SSamplerTexturePair2D_float ShadowMapSampler, float2 ShadowMapTexCoord, float FragmentDepth, float4 ShadowMapSize, float DepthBias, float KernelDiameter)
Definition: Shadow.fx:651
float2 Square(float2 Z)
void ApplyGaussianFilterHorizontal7_float(out float4 OutFilteredValue, SSamplerTexturePair2D_float SourceSampler, float2 TexCoord, float4 TextureSize)
Definition: Shadow.fx:1215
float2 Multiply(float2 LHS, float2 RHS)
void ApplyGaussianFilterHorizontal5_float(out float4 OutFilteredValue, SSamplerTexturePair2D_float SourceSampler, float2 TexCoord, float4 TextureSize)
Definition: Shadow.fx:1199
void Sample4MomentOptimizedShadowMap(out float4 OutBiased4Moments, SSamplerTexturePair2D _4MomentOptimizedShadowMapSampler, float2 ShadowMapTexCoord, float MomentBias=6.0e-5f)
Definition: Shadow.fx:501
void ApplyPrefixSumHorizontal_uint2(inout RWTexture2D< uint2 > OutFilteredTexture, SSamplerTexturePair2D_float2 SourceSampler, uint3 ThreadID, float2 FixedPrecision)
Definition: Shadow.fx:1358
void ApplyGaussianFilterHorizontal15_float(out float4 OutFilteredValue, SSamplerTexturePair2D_float SourceSampler, float2 TexCoord, float4 TextureSize)
Definition: Shadow.fx:1253
void Sample4MomentShadowMap(out float4 OutBiased4Moments, SSamplerTexturePair2D _4MomentShadowMapSampler, float2 ShadowMapTexCoord, float MomentBias=3.0e-7f)
Definition: Shadow.fx:489
void SampleConvolutionShadowMap8(out float2 pOutFourierCoefficient[8], SSamplerTexturePair2D ConvolutionShadowMapSampler0, SSamplerTexturePair2D ConvolutionShadowMapSampler1, SSamplerTexturePair2D ConvolutionShadowMapSampler2, SSamplerTexturePair2D ConvolutionShadowMapSampler3, float2 ShadowMapTexCoord)
Definition: Shadow.fx:382
void SampleShadowMap(out float OutShadowMapDepth, SSamplerTexturePair2D_float ShadowMapSampler, float2 ShadowMapTexCoord)
Definition: Shadow.fx:342
void ComputeMomentVector4MomentsOptimized_float2_float2(out float2 Out4MomentsOptimized0_float2, out float2 Out4MomentsOptimized1_float2, float FragmentDepth)
Definition: Shadow.fx:196
void ComputeIntegerRectangleAverage_uint4(out float4 OutAverageValue, float2 LeftTop, float2 RightBottom, SSamplerTexturePair2D_uint4 SummedAreaTableSampler, float4 TextureSize, float2 FixedPrecision)
Definition: Shadow.fx:1502
void ApplyGaussianFilterVertical9_float4(out float4 OutFilteredValue, SSamplerTexturePair2D SourceSampler, float2 TexCoord, float4 TextureSize)
Definition: Shadow.fx:1071
void ApplyPrefixSumHorizontal_float4(inout RWTexture2D< float4 > OutFilteredTexture, SSamplerTexturePair2D SourceSampler, uint3 ThreadID)
Definition: Shadow.fx:1287
void CombineVectorWithAlpha_float4(out float4 OutVectorWithAlpha, float4 Vector)
Definition: Shadow.fx:39
void ApplyPrefixSumHorizontal_half4(inout RWTexture2D< half4 > OutFilteredTexture, SSamplerTexturePair2D SourceSampler, uint3 ThreadID)
Definition: Shadow.fx:1382
void ApplyPrefixSumVertical_uint4(inout RWTexture2D< uint4 > OutFilteredTexture, SSamplerTexturePair2D_uint4 SourceSampler, uint3 ThreadID)
Definition: Shadow.fx:1324
void ComputeMomentVectorFourier8(out float4 OutFourier1_2, out float4 OutFourier3_4, out float4 OutFourier5_6, out float4 OutFourier7_8, float FragmentDepth)
Definition: Shadow.fx:60
void CombineVectorWithAlpha_float1(out float4 OutVectorWithAlpha, float Vector, float Alpha)
Definition: Shadow.fx:26
void ComputePCFShadowIntensity(out float OutShadowIntensity, Texture2D ShadowMap, SamplerState ShadowMapSampler, float2 ShadowMapTexCoord, float FragmentDepth, float4 ShadowMapSize, const float StandardDeviation, const int KernelRadius, float DepthBias)
void LoadDepthSample1(out float OutDepthSample, Texture2DMS< float, 1 > ShadowMap, float2 TexCoord, uint SampleIndex, float4 ShadowMapSize)
Definition: Shadow.fx:949
void ApplyGaussianFilterVertical15_float2(out float4 OutFilteredValue, SSamplerTexturePair2D_float2 SourceSampler, float2 TexCoord, float4 TextureSize)
Definition: Shadow.fx:1183
void ComputePCFShadowIntensity7x7(out float OutShadowIntensity, SSamplerTexturePair2D_float ShadowMapSampler, float2 ShadowMapTexCoord, float FragmentDepth, float4 ShadowMapSize, float DepthBias)
Definition: Shadow.fx:617
void ComputePCFShadowIntensity5x5(out float OutShadowIntensity, SSamplerTexturePair2D_float ShadowMapSampler, float2 ShadowMapTexCoord, float FragmentDepth, float4 ShadowMapSize, float DepthBias)
Definition: Shadow.fx:606
void SampleExponentialVarianceSplitShadowMap(out float4 OutExponentialVarianceVector, SSamplerTexturePair2D_float2 ExponentialVarianceShadowMapSampler0, SSamplerTexturePair2D_float2 ExponentialVarianceShadowMapSampler1, float2 ShadowMapTexCoord)
Definition: Shadow.fx:359
void GetBlockerSearchRectangle(out float2 OutSearchRegionLeftTop, out float2 OutSearchRegionRightBottom, float2 SearchRegionCenter, float3x2 KernelSizeParameter, float4 ShadowMapSize)
Definition: Shadow.fx:1668
void ComputeMomentVectorFourier16(out float4 OutFourier1_2, out float4 OutFourier3_4, out float4 OutFourier5_6, out float4 OutFourier7_8, out float4 OutFourier9_10, out float4 OutFourier11_12, out float4 OutFourier13_14, out float4 OutFourier15_16, float FragmentDepth)
Definition: Shadow.fx:87
void PickShadowIntensity(out float OutShadowIntensity, float FilteredShadowIntensity, float BlockerSearchShadowIntensity)
Definition: Shadow.fx:1867
void GetSummedAreaTableThreadGroupCount(out uint3 nOutThreadGroupHorizontal, out uint3 nOutThreadGroupVertical, uint3 ThreadGroupSizeHorizontal, uint3 ThreadGroupSizeVertical, float4 TextureSize)
Definition: Shadow.fx:1416
void ApplyGaussianFilterVertical15_float4(out float4 OutFilteredValue, SSamplerTexturePair2D SourceSampler, float2 TexCoord, float4 TextureSize)
Definition: Shadow.fx:1094
void ComputeShadowMapDepth(out float OutShadowMapDepth, float FragmentDepth)
Definition: Shadow.fx:20
void ComputeSampleAverage_float(out float OutSampleAverage, float SampleSum, uint nSample)
Definition: Shadow.fx:996
void ComputeExponentialVarianceVector(out float4 OutDepthExponentialVariance, float FragmentDepth, float2 ExponentialVarianceFactors)
Definition: Shadow.fx:138
void ComputeFixedPrecision(out float2 OutFixedPrecision, float3x2 KernelSizeParameter, float2 ShadowMapSize)
Definition: Shadow.fx:1652
void CombineVectorWithAlpha_float2(out float4 OutVectorWithAlpha, float2 Vector, float Alpha)
Definition: Shadow.fx:31
void ApplyGaussianFilterVertical9_float2(out float4 OutFilteredValue, SSamplerTexturePair2D_float2 SourceSampler, float2 TexCoord, float4 TextureSize)
Definition: Shadow.fx:1158
void ComputePCSSAverageBlockerDepth(out float OutAverageBlockerDepth, out float OutBlockerSearchShadowIntensity, SSamplerTexturePair2D_float ShadowMapSampler, float2 ShadowMapTexCoord, float FragmentDepth, float4 ShadowMapSize, float DepthBias, float3x2 KernelSizeParameter)
Definition: Shadow.fx:1829
void ComputeFragmentDepth(out float OutFragmentDepth, float4 ProjectionSpacePosition)
Definition: Shadow.fx:13
void ComputeRectangleAverage_float2(out float2 OutAverageValue, float2 LeftTop, float2 RightBottom, SSamplerTexturePair2D_float2 SummedAreaTableSampler, float4 TextureSize)
Definition: Shadow.fx:1621
void ApplyGaussianFilterVertical7_float(out float4 OutFilteredValue, SSamplerTexturePair2D_float SourceSampler, float2 TexCoord, float4 TextureSize)
Definition: Shadow.fx:1224
void ComputeIntegerPCSSShadowIntensity(out float OutShadowIntensity, SSamplerTexturePair2D_float ShadowMapSampler, float2 FilterRegionLeftTop, float2 FilterRegionRightBottom, float FragmentDepth, float4 ShadowMapSize, float DepthBias)
Definition: Shadow.fx:1882
void ComputeConvolutionShadowIntensity16(out float OutShadowIntensity, float2 pFourierCoefficient[16], float FragmentDepth, float DepthBias)
Definition: Shadow.fx:716
void Compute4MomentShadowIntensity(out float OutShadowIntensity, float4 Biased4Moments, float FragmentDepth, float DepthBias)
Definition: Shadow.fx:791
void Compute2TMSMShadowIntensity(out float OutShadowIntensity, float2 pFourierCoefficient[2], float FragmentDepth, float DepthBias, float MomentBias)
Definition: Shadow.fx:929
void Convert4MomentToCanonical(out float4 OutBiased4Moments, float4 Moments0, float MomentBias=3.0e-7f)
Definition: Shadow.fx:545
void SampleExponentialShadowMap(out float OutExponentialShadowMap, SSamplerTexturePair2D_float ExponentialShadowMapSampler, float2 ShadowMapTexCoord)
Definition: Shadow.fx:371
void ComputeMomentVector2Moments_float2(out float2 Out2Moments_float2, float FragmentDepth)
Definition: Shadow.fx:158
void ComputeHardShadowIntensity(out float OutShadowIntensity, float SampledShadowMapDepth, float FragmentDepth, float DepthBias)
Definition: Shadow.fx:587
void ApplyPrefixSumVertical_float4(inout RWTexture2D< float4 > OutFilteredTexture, SSamplerTexturePair2D SourceSampler, uint3 ThreadID)
Definition: Shadow.fx:1299
void ComputePCFShadowIntensityBilinear(out float OutShadowIntensity, Texture2D< float > ShadowMap, SamplerComparisonState ShadowMapSampler, float2 ShadowMapTexCoord, float FragmentDepth, float4 ShadowMapSize, const float StandardDeviation, const int KernelRadius, float DepthBias)
void ApplyGaussianFilterVertical7_float2(out float4 OutFilteredValue, SSamplerTexturePair2D_float2 SourceSampler, float2 TexCoord, float4 TextureSize)
Definition: Shadow.fx:1137
void ComputeMomentVector4Moments_float4(out float4 Out4Moments_float4, float FragmentDepth)
Definition: Shadow.fx:165
void Compute2MomentAverageBlockerDepth(out float OutAverageBlockerDepth, out float OutBlockerSearchShadowIntensity, float2 BlockerSearchBiased2Moments, float FragmentDepth, float DepthBias)
Definition: Shadow.fx:1755
void ApplyGaussianFilterHorizontal9_float2(out float4 OutFilteredValue, SSamplerTexturePair2D_float2 SourceSampler, float2 TexCoord, float4 TextureSize)
Definition: Shadow.fx:1147
void ApplyGaussianFilterHorizontal7_float4(out float4 OutFilteredValue, SSamplerTexturePair2D SourceSampler, float2 TexCoord, float4 TextureSize)
Definition: Shadow.fx:1043
void ApplyGaussianFilterHorizontal5_float2(out float4 OutFilteredValue, SSamplerTexturePair2D_float2 SourceSampler, float2 TexCoord, float4 TextureSize)
Definition: Shadow.fx:1109
void ComputeDirectionalLightCamera(out float4x4 OutViewToWorldSpace, out float4x4 OutViewToProjectionSpace, float3 WorldSpaceBoundingBoxMin, float3 WorldSpaceBoundingBoxMax, float3 WorldSpaceLightDirection)
Definition: Shadow.fx:212
void Sample4MomentSplitShadowMap(out float4 OutBiased4Moments, SSamplerTexturePair2D_float2 _4MomentShadowMapSampler0, SSamplerTexturePair2D_float2 _4MomentShadowMapSampler1, float2 ShadowMapTexCoord, float MomentBias=3.0e-7f)
Definition: Shadow.fx:515
void ConvertSplit4MomentToCanonical(out float4 OutBiased4Moments, float2 Moments0, float2 Moments1, float MomentBias=3.0e-7f)
Definition: Shadow.fx:550
float Get2TMSMMinimalWeight(float2 pTrigonometricMoment[2], float IntervalEnd)
void ComputeExponentialVarianceVectorSplit(out float2 OutDepthExponentialVariance0, out float2 OutDepthExponentialVariance1, float FragmentDepth, float2 ExponentialVarianceFactors)
Definition: Shadow.fx:147
void Sample2MomentShadowMap(out float2 OutBiased2Moments, SSamplerTexturePair2D_float2 _2MomentShadowMapSampler, float2 ShadowMapTexCoord, float MomentBias=0.0f)
Definition: Shadow.fx:467
void ApplyGaussianFilterHorizontal9_float(out float4 OutFilteredValue, SSamplerTexturePair2D_float SourceSampler, float2 TexCoord, float4 TextureSize)
Definition: Shadow.fx:1233
void ScaleShadowIntensity(out float OutShadowIntensity, float ShadowIntensity, float ShadowIntensityFactor, float2 ShadowMapTexCoord, float FragmentDepth)
Definition: Shadow.fx:575
void CombineVectorWithAlpha_float3(out float4 OutVectorWithAlpha, float3 Vector, float Alpha)
Definition: Shadow.fx:35
void ComputeExponentialVarianceShadowIntensity(out float OutShadowIntensity, float4 ExponentialVarianceVector, float FragmentDepth, float DepthBias, float2 ExponentialVarianceFactors)
Definition: Shadow.fx:745
void ComputeRectangleAverage_uint4(out float4 OutAverageValue, float2 LeftTop, float2 RightBottom, SSamplerTexturePair2D_uint4 SummedAreaTableSampler, float4 TextureSize, float2 FixedPrecision)
Definition: Shadow.fx:1435
void ApplyGaussianFilterVertical9_float(out float4 OutFilteredValue, SSamplerTexturePair2D_float SourceSampler, float2 TexCoord, float4 TextureSize)
Definition: Shadow.fx:1243
void ApplyPrefixSumVertical_half4(inout RWTexture2D< half4 > OutFilteredTexture, SSamplerTexturePair2D SourceSampler, uint3 ThreadID)
Definition: Shadow.fx:1394
void ComputeIntegerRectangleAverage_uint2(out float2 OutAverageValue, float2 LeftTop, float2 RightBottom, SSamplerTexturePair2D_uint2 SummedAreaTableSampler, float4 TextureSize, float2 FixedPrecision)
Definition: Shadow.fx:1604
void SampleConvolutionShadowMap16(out float2 pOutFourierCoefficient[16], SSamplerTexturePair2D ConvolutionShadowMapSampler0, SSamplerTexturePair2D ConvolutionShadowMapSampler1, SSamplerTexturePair2D ConvolutionShadowMapSampler2, SSamplerTexturePair2D ConvolutionShadowMapSampler3, SSamplerTexturePair2D ConvolutionShadowMapSampler4, SSamplerTexturePair2D ConvolutionShadowMapSampler5, SSamplerTexturePair2D ConvolutionShadowMapSampler6, SSamplerTexturePair2D ConvolutionShadowMapSampler7, float2 ShadowMapTexCoord)
Definition: Shadow.fx:408
void HeavisideStepFunction(out float OutShadowIntensity, float BlockerDepth, float FragmentDepth)
Definition: Shadow.fx:335
float GetRandomNumber(uint Seed)