// Volumetric fog - populates VFShadowVolumeTexture (light shafts)
// Related shaders:
// CS 008f4b4539a0cab7 - VFLightVolumeTexture (point lights)
// CS ad7a6a5c9182e26e - VFLightVolumeTexture (point lights in cutscenes)
// CS 79d2dd1629dd2fd3 - VFLightVolumeTexture (point lights in enemy camp)
// CS 63156ad276e52990 - VFLightVolumeTexture (light shafts in cave)
// CS 8b431e0726c6115e - VFShadowVolumeTexture (light shafts outside)
// CS 6bdcbf1223c89177 - VFShadowVolumeTexture (as above, but for cutscenes)
// CS 5b5e5a3ac5bc8145 - VFDensityVolumeTexture (bad density near mountains)
// CS ac73802804100e3f - combines this & other fog buffers together
// CS b353330000eff5ed - intermediate stage
// CS 30f0ac937c0b3451 - intermediate stage x 2
// PS 2b6cfbaa250d7a51 - output to screen

//
// Generated by Microsoft (R) HLSL Shader Compiler 9.29.952.3111
//
//   using 3Dmigoto v1.2.31 on Wed Mar 02 08:06:59 2016
//
//
// Buffer Definitions: 
//
// cbuffer CViewportShaderParameterProvider
// {
//
//   float4x4 InvProjectionMatrix;      // Offset:    0 Size:    64 [unused]
//   float4x4 InvViewMatrix;            // Offset:   64 Size:    64 [unused]
//   float4x4 ProjectionMatrix;         // Offset:  128 Size:    64 [unused]
//   float4x4 ViewMatrix;               // Offset:  192 Size:    64 [unused]
//   float4x4 ViewProjectionMatrix;     // Offset:  256 Size:    64 [unused]
//   float4x4 ViewRotProjectionMatrix;  // Offset:  320 Size:    64 [unused]
//   float4x4 ViewRotProjectionMatrix_Previous;// Offset:  384 Size:    64 [unused]
//   float4 AmbientSHR;                 // Offset:  448 Size:    16 [unused]
//   float4 AmbientSHG;                 // Offset:  464 Size:    16 [unused]
//   float4 AmbientSHB;                 // Offset:  480 Size:    16 [unused]
//   float4 CameraDistances;            // Offset:  496 Size:    16 [unused]
//   float4 CameraNearPlaneSize;        // Offset:  512 Size:    16 [unused]
//   float4 DepthScale;                 // Offset:  528 Size:    16 [unused]
//   float4 DepthTextureScaleOffset;    // Offset:  544 Size:    16 [unused]
//   float4 FogParams;                  // Offset:  560 Size:    16 [unused]
//   float4 FogSHB;                     // Offset:  576 Size:    16 [unused]
//   float4 FogSHG;                     // Offset:  592 Size:    16 [unused]
//   float4 FogSHR;                     // Offset:  608 Size:    16 [unused]
//   float4 HeightFogParams;            // Offset:  624 Size:    16 [unused]
//   float4 ViewportSize;               // Offset:  640 Size:    16 [unused]
//   float3 ViewPoint;                  // Offset:  656 Size:    12 [unused]
//   float3 CameraPosition;             // Offset:  672 Size:    12
//   float3 CameraPosition_Previous;    // Offset:  688 Size:    12 [unused]
//   float3 CameraPositionFractions;    // Offset:  704 Size:    12 [unused]
//   float3 CameraPositionFractions_Previous;// Offset:  720 Size:    12 [unused]
//   float3 CameraRight;                // Offset:  736 Size:    12 [unused]
//   float3 CameraUp;                   // Offset:  752 Size:    12 [unused]
//   float3 CameraDirection;            // Offset:  768 Size:    12 [unused]
//   float3 EnvironmentMapColorOffset;  // Offset:  784 Size:    12 [unused]
//   float3 EnvironmentMapColorScale;   // Offset:  800 Size:    12 [unused]
//   float3 AmbientOcclusionRanges;     // Offset:  816 Size:    12 [unused]
//   float3 DepthTextureRcpSize;        // Offset:  832 Size:    12 [unused]
//   float2 MotionVectorOffsets;        // Offset:  848 Size:     8 [unused]
//   float2 DepthRangeCompression;      // Offset:  856 Size:     8 [unused]
//   float ShadowProjDepthMinValue;     // Offset:  864 Size:     4 [unused]
//   float DistanceScale;               // Offset:  868 Size:     4 [unused]
//   float WorldSpaceZOffset;           // Offset:  872 Size:     4 [unused]
//   float WorldSpaceZOffset_Previous;  // Offset:  876 Size:     4 [unused]
//   float CameraFOVDeg;                // Offset:  880 Size:     4 [unused]
//   float EffectsEmissiveEVBias;       // Offset:  884 Size:     4 [unused]
//   float ShadowCSMLastSliceIndex;     // Offset:  888 Size:     4
//   float UseNormalization;            // Offset:  892 Size:     4 [unused]
//   float FogUndergroundColorScale;    // Offset:  896 Size:     4 [unused]
//
// }
//
// cbuffer CVolumetricFogProvider
// {
//
//   float4 VFSampleDistribution[4];    // Offset:    0 Size:    64
//   float4x4 VPrevWorldToVolumetricShadowMatrix;// Offset:   64 Size:    64
//   float4x4 VFInvViewMatrix;          // Offset:  128 Size:    64 [unused]
//   float4 VFDepthDistribution;        // Offset:  192 Size:    16
//   float4 VFDepthParams;              // Offset:  208 Size:    16 [unused]
//   float4 VFFogDensityBottom;         // Offset:  224 Size:    16 [unused]
//   float4 VFFogDensityTop;            // Offset:  240 Size:    16 [unused]
//   float4 VFFogParams0;               // Offset:  256 Size:    16 [unused]
//   float4 VFFogParams1;               // Offset:  272 Size:    16 [unused]
//   float4 VFFogParams2;               // Offset:  288 Size:    16 [unused]
//   float4 VFFogParams3;               // Offset:  304 Size:    16 [unused]
//   float4 VFShadowParams;             // Offset:  320 Size:    16 [unused]
//   float4 VFViewDirReconstruction;    // Offset:  336 Size:    16
//   int4 VFCellParams;                 // Offset:  352 Size:    16
//   float3 VFCameraXAxis;              // Offset:  368 Size:    12
//   float3 VFCameraYAxis;              // Offset:  384 Size:    12
//   float3 VFCameraZAxis;              // Offset:  400 Size:    12
//   float4 VFTemporalParams;           // Offset:  416 Size:    16
//
// }
//
// cbuffer CSunShadowProvider
// {
//
//   float4 CSMSlice0_0;                // Offset:    0 Size:    16
//   float4 CSMSlice0_1;                // Offset:   16 Size:    16
//   float4 CSMSlice0_2;                // Offset:   32 Size:    16
//   float4 CSMSlice1_0;                // Offset:   48 Size:    16
//   float4 CSMSlice1_1;                // Offset:   64 Size:    16
//   float4 CSMSlice1_2;                // Offset:   80 Size:    16
//   float4 CSMSlice2_0;                // Offset:   96 Size:    16
//   float4 CSMSlice2_1;                // Offset:  112 Size:    16
//   float4 CSMSlice2_2;                // Offset:  128 Size:    16
//   float4 CSMSliceFade;               // Offset:  144 Size:    16 [unused]
//   float4 ShadowMapSize;              // Offset:  160 Size:    16 [unused]
//   float4 SunColor;                   // Offset:  176 Size:    16 [unused]
//   float4 SunDirection;               // Offset:  192 Size:    16 [unused]
//
// }
//
//
// Resource Bindings:
//
// Name                                 Type  Format         Dim Slot Elements
// ------------------------------ ---------- ------- ----------- ---- --------
// ShadowCmpSampler                sampler_c      NA          NA    0        1
// ColorPointClamp3D                 sampler      NA          NA    1        1
// ShadowCmpSampler_TextureObject    texture  float4     2darray    0        1
// VFPrevShadowVolumeTexture         texture  float4          3d    1        1
// VFOutputBuffer                        UAV   float          3d    0        1
// CViewportShaderParameterProvider    cbuffer      NA          NA    0        1
// CVolumetricFogProvider            cbuffer      NA          NA    1        1
// CSunShadowProvider                cbuffer      NA          NA    2        1
//
//
//
// Input signature:
//
// Name                 Index   Mask Register SysValue  Format   Used
// -------------------- ----- ------ -------- -------- ------- ------
// no Input
//
// Output signature:
//
// Name                 Index   Mask Register SysValue  Format   Used
// -------------------- ----- ------ -------- -------- ------- ------
// no Output
cs_5_0
dcl_globalFlags refactoringAllowed
dcl_constantbuffer cb0[56], immediateIndexed
dcl_constantbuffer cb1[27], immediateIndexed
dcl_constantbuffer cb2[9], immediateIndexed
dcl_sampler s0, mode_comparison
dcl_sampler s1, mode_default
dcl_resource_texture2darray (float,float,float,float) t0
dcl_resource_texture3d (float,float,float,float) t1
dcl_uav_typed_texture3d (float,float,float,float) u0
dcl_input vThreadGroupID.xyz
dcl_input vThreadIDInGroup.xy
dcl_temps 10
dcl_thread_group 16, 16, 1

dcl_resource_texture2d (float,float,float,float) t125

ld_indexable(texture2d)(float,float,float,float) r6.xyzw, l(0, 0, 0, 0), t125.xyzw

imad r0.xy, vThreadGroupID.xyxx, l(16, 16, 0, 0), vThreadIDInGroup.xyxx
ult r1.xy, r0.xyxx, cb1[22].xyxx
and r1.x, r1.y, r1.x
if_nz r1.x
  utof r1.xy, r0.xyxx
  add r1.xy, r1.xyxx, l(0.500000, 0.500000, 0.000000, 0.000000)
  itof r1.zw, cb1[22].xxxy
  div r1.xy, r1.xyxx, r1.zwzz
  mad r1.xy, r1.xyxx, l(2.000000, 2.000000, 0.000000, 0.000000), l(-1.000000, -1.000000, 0.000000, 0.000000)
  mul r1.xy, r1.yxyy, cb1[21].yxyy
  mul r1.x, r1.x, l(-1.000000)
  mul r1.xzw, r1.xxxx, cb1[24].xxyz
  mad r1.xyz, r1.yyyy, cb1[23].xyzx, r1.xzwx
  add r1.xyz, r1.xyzx, cb1[25].xyzx
  iadd r1.w, vThreadGroupID.z, l(1)
  utof r1.w, r1.w
  ushr r2.x, cb1[22].z, l(1)
  utof r2.x, r2.x
  div r1.w, r1.w, r2.x
  mul r1.w, r1.w, l(4.000000)
  exp r1.w, r1.w
  mad r1.w, r1.w, cb1[12].z, cb1[12].w
  utof r2.y, vThreadGroupID.z
  div r2.y, r2.y, r2.x
  mul r2.y, r2.y, l(4.000000)
  exp r2.y, r2.y
  mad r2.y, r2.y, cb1[12].z, cb1[12].w
  add r1.w, r1.w, -r2.y
  mad r1.w, r1.w, l(0.500000), r2.y

//CameraPosition:
  mad r1.xyz, r1.xyzx, r1.wwww, cb0[42].xyzx
  mov r1.w, l(1.000000)

mov r9.xyzw, r1.xyzw

// ViewProjectionMatrix:
dp4 r8.w, r9.xyzw, cb0[19].xyzw
// Adjustment amount:
add r6.w, r8.w, -r6.y
mul r8.x, -r6.w, r6.x
mov r8.yzw, l(0.0)
// InvProjectionMatrix:
dp4 r7.x, r8.xyzw, cb0[0].xyzw
dp4 r7.y, r8.xyzw, cb0[1].xyzw
dp4 r7.z, r8.xyzw, cb0[2].xyzw
dp4 r7.w, r8.xyzw, cb0[3].xyzw
// InvViewMatrix:
dp4 r8.x, r7.xyzw, cb0[4].xyzw
dp4 r8.y, r7.xyzw, cb0[5].xyzw
dp4 r8.z, r7.xyzw, cb0[6].xyzw
// Add adjustment:
add r9.xyz, r9.xyz, r8.xyz

// Use corrected coordinate for CSMSlice*:
  dp4 r3.x, r9.xyzw, cb2[6].xyzw
  dp4 r3.y, r9.xyzw, cb2[7].xyzw
  dp4 r3.z, r9.xyzw, cb2[8].xyzw
  dp4 r4.x, r9.xyzw, cb2[3].xyzw
  dp4 r4.y, r9.xyzw, cb2[4].xyzw
  dp4 r4.z, r9.xyzw, cb2[5].xyzw

  add r2.yzw, r4.xxyz, l(0.000000, -0.000000, -0.000000, -0.001000)
  ge r5.xyz, r2.yzwy, l(0.000000, 0.000000, 0.000000, 0.000000)
  and r5.xyz, r5.xyzx, l(0x3f800000, 0x3f800000, 0x3f800000, 0)
  ge r2.yzw, l(0.000000, 1.000000, 1.000000, 1.000000), r2.yyzw
  and r2.yzw, r2.yyzw, l(0, 0x3f800000, 0x3f800000, 0x3f800000)
  mul r2.yzw, r2.yyzw, r5.xxyz
  dp3 r2.y, r2.yzwy, l(1.000000, 1.000000, 1.000000, 0.000000)
  ge r2.y, r2.y, l(3.000000)
  mov r4.w, l(1.000000)
  mov r3.w, l(2.000000)
  movc r3.xyzw, r2.yyyy, r4.xyzw, r3.xyzw

// Use corrected coordinate for CSMSlice*:
  dp4 r4.x, r9.xyzw, cb2[0].xyzw
  dp4 r4.y, r9.xyzw, cb2[1].xyzw
  dp4 r4.z, r9.xyzw, cb2[2].xyzw

  add r2.yzw, r4.xxyz, l(0.000000, -0.000000, -0.000000, -0.001000)
  ge r5.xyz, r2.yzwy, l(0.000000, 0.000000, 0.000000, 0.000000)
  and r5.xyz, r5.xyzx, l(0x3f800000, 0x3f800000, 0x3f800000, 0)
  ge r2.yzw, l(0.000000, 1.000000, 1.000000, 1.000000), r2.yyzw
  and r2.yzw, r2.yyzw, l(0, 0x3f800000, 0x3f800000, 0x3f800000)
  mul r2.yzw, r2.yyzw, r5.xxyz
  dp3 r2.y, r2.yzwy, l(1.000000, 1.000000, 1.000000, 0.000000)
  ge r2.y, r2.y, l(3.000000)
  mov r4.w, l(0)
  movc r3.xyzw, r2.yyyy, r4.xyzw, r3.xyzw
  min r2.y, r3.w, cb0[55].z
  eq r2.y, r2.y, cb0[55].z
  mad r2.zw, r3.xxxy, l(0.000000, 0.000000, 2.000000, 2.000000), l(0.000000, 0.000000, -1.000000, -1.000000)
  add r2.zw, |r2.zzzw|, l(0.000000, 0.000000, -0.800000, -0.800000)
  mul_sat r2.zw, r2.zzzw, l(0.000000, 0.000000, 5.000000, 5.000000)
  add r2.zw, -r2.zzzw, l(0.000000, 0.000000, 1.000000, 1.000000)
  add r4.x, r3.z, l(-0.500000)
  mad r4.x, -|r4.x|, l(2.000000), l(1.000000)
  max r4.x, r4.x, l(0.000000)
  min r4.x, r4.x, l(0.200000)
  mul r4.x, r4.x, l(5.000000)
  min r2.z, r2.w, r2.z
  min r2.z, r4.x, r2.z
  movc r2.y, r2.y, r2.z, l(1.000000)
  lt r2.z, l(0.000000), r2.y
  if_nz r2.z
    mad r4.xy, cb1[0].xyxx, l(0.00146484375, 0.00146484375, 0.000000, 0.000000), r3.xyxx
    mov r4.zw, r3.zzzw
    sample_c_lz_aoffimmi_indexable(0,0,0)(texture2darray)(float,float,float,float) r2.z, r4.xywx, t0.xxxx, s0, r4.z
    mad r3.xy, cb1[0].zwzz, l(0.00146484375, 0.00146484375, 0.000000, 0.000000), r3.xyxx
    sample_c_lz_aoffimmi_indexable(0,0,0)(texture2darray)(float,float,float,float) r2.w, r3.xywx, t0.xxxx, s0, r3.z
    add r2.z, r2.w, r2.z
    mul r2.w, r2.y, r2.y
    mad r2.z, r2.z, l(0.500000), -r2.w
    mad r2.y, r2.y, r2.z, r2.w
  else 
    mov r2.y, l(0)
  endif 

// Use uncorrected coordinate for previous frame:
  dp4 r3.x, r1.xyzw, cb1[4].xyzw
  dp4 r3.y, r1.xyzw, cb1[5].xyzw
  dp4 r2.z, r1.xyzw, cb1[6].xyzw
  dp4 r1.x, r1.xyzw, cb1[7].xyzw
  lt r1.y, l(0.000000), r1.x
  if_nz r1.y
    div r1.xy, r3.xyxx, r1.xxxx
    mad r1.xy, r1.xyxx, l(0.500000, -0.500000, 0.000000, 0.000000), l(0.500000, 0.500000, 0.000000, 0.000000)
    add r1.w, r2.z, -cb1[12].w
    div r1.w, r1.w, cb1[12].z
    log r1.w, r1.w
    mul r1.w, r2.x, r1.w
    mul r1.w, r1.w, l(0.250000)
    iadd r2.x, cb1[22].z, l(-1)
    itof r2.x, r2.x
    div r1.z, r1.w, r2.x
    sample_l_indexable(texture3d)(float,float,float,float) r1.x, r1.xyzx, t1.xyzw, s1, l(0.000000)
  else 
    mov r1.x, l(0)
  endif 
  add_sat r1.x, r1.x, l(-0.00392156886)
  add r1.y, -r1.x, r2.y
  mad r1.x, cb1[26].x, r1.y, r1.x
  mov r0.zw, vThreadGroupID.zzzz
  store_uav_typed u0.xyzw, r0.xyzw, r1.xxxx
endif 
ret 
// Approximately 116 instruction slots used