// Volumetric fog - populates VFDensityVolumeTexture (bad density near mountains)
// 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:46 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
//   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 [unused]
//   float UseNormalization;            // Offset:  892 Size:     4 [unused]
//   float FogUndergroundColorScale;    // Offset:  896 Size:     4 [unused]
//
// }
//
// cbuffer CVolumetricFogProvider
// {
//
//   float4 VFSampleDistribution[4];    // Offset:    0 Size:    64 [unused]
//   float4x4 VPrevWorldToVolumetricShadowMatrix;// Offset:   64 Size:    64 [unused]
//   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
//   float4 VFFogDensityTop;            // Offset:  240 Size:    16
//   float4 VFFogParams0;               // Offset:  256 Size:    16 [unused]
//   float4 VFFogParams1;               // Offset:  272 Size:    16 [unused]
//   float4 VFFogParams2;               // Offset:  288 Size:    16
//   float4 VFFogParams3;               // Offset:  304 Size:    16
//   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 [unused]
//
// }
//
// cbuffer CDensityVolumeTextureProvider
// {
//
//   float4 WorldOffsetScale;           // Offset:    0 Size:    16
//
// }
//
//
// Resource Bindings:
//
// Name                                 Type  Format         Dim Slot Elements
// ------------------------------ ---------- ------- ----------- ---- --------
// ColorClamp2D                      sampler      NA          NA    0        1
// VFMaxDepthDiv2Texture             texture   float          2d    0        1
// VFWorldSpaceDensityTexture        texture  float3          2d    1        1
// VFOutputBuffer                        UAV   float          3d    0        1
// CViewportShaderParameterProvider    cbuffer      NA          NA    0        1
// CVolumetricFogProvider            cbuffer      NA          NA    1        1
// CDensityVolumeTextureProvider     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[43], immediateIndexed
dcl_constantbuffer cb1[26], immediateIndexed
dcl_constantbuffer cb2[1], immediateIndexed
dcl_sampler s0, mode_default
dcl_resource_texture2d (float,float,float,float) t0
dcl_resource_texture2d (float,float,float,float) t1
dcl_uav_typed_texture3d (float,float,float,float) u0
dcl_input vThreadGroupID.xyz
dcl_input vThreadIDInGroup.xy
dcl_temps 8
dcl_thread_group 16, 16, 1

dcl_resource_texture2d (float,float,float,float) t125
dcl_resource_texture1d (float,float,float,float) t120

ld_indexable(texture2d)(float,float,float,float) r3.xyzw, l(0, 0, 0, 0), t125.xyzw
ld_indexable(texture1d)(float,float,float,float) r7.xyzw, l(0, 0, 0, 0), t120.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
  iadd r1.xy, cb1[22].xyxx, l(-1, -1, 0, 0)
  umin r1.xy, r0.xyxx, r1.xyxx
  mov r1.zw, l(0,0,0,0)
  ld_indexable(texture2d)(float,float,float,float) r1.x, r1.xyzw, t0.xyzw
  mad r1.x, r1.x, cb0[31].y, -cb1[12].w
  div r1.x, r1.x, cb1[12].z
  log r1.x, r1.x
  mul r1.x, r1.x, l(0.250000)
  ushr r1.y, cb1[22].z, l(1)
  utof r1.y, r1.y
  mad r1.x, r1.x, r1.y, l(1.000000)
  ftou r1.x, r1.x
  uge r1.x, r1.x, vThreadGroupID.z
  if_nz r1.x
    utof r1.xz, r0.xxyx
    add r1.xz, r1.xxzx, l(0.500000, 0.000000, 0.500000, 0.000000)
    itof r2.xy, cb1[22].xyxx
    div r1.xz, r1.xxzx, r2.xxyx
    mad r1.xz, r1.xxzx, l(2.000000, 0.000000, 2.000000, 0.000000), l(-1.000000, 0.000000, -1.000000, 0.000000)
    mul r1.xz, r1.zzxz, cb1[21].yyxy
    mul r1.x, r1.x, l(-1.000000)
    mul r2.xyz, r1.xxxx, cb1[24].xyzx
    mad r1.xzw, r1.zzzz, cb1[23].xxyz, r2.xxyz
    add r1.xzw, r1.xxzw, cb1[25].xxyz
    iadd r2.x, vThreadGroupID.z, l(1)
    utof r2.x, r2.x
    div r2.x, r2.x, r1.y
    mul r2.x, r2.x, l(4.000000)
    exp r2.x, r2.x
    mad r2.x, r2.x, cb1[12].z, cb1[12].w
    utof r2.y, vThreadGroupID.z
    div r1.y, r2.y, r1.y
    mul r1.y, r1.y, l(4.000000)
    exp r1.y, r1.y
    mad r1.y, r1.y, cb1[12].z, cb1[12].w
    add r1.y, r1.y, r2.x
    mul r1.xyz, r1.yyyy, r1.xzwx
    mad r1.xyz, r1.xyzx, l(0.500000, 0.500000, 0.500000, 0.000000), cb0[42].xyzx

mov r6.xyz, r1.xyz
mov r6.w, l(1.0)

// ViewProjectionMatrix:
dp4 r5.w, r6.xyzw, cb0[19].xyzw
// Adjustment amount:
add r3.w, r5.w, -r3.y
mul r5.x, -r3.w, r3.x
mul r5.x, r5.x, cb0[0].x
mov r5.yzw, l(0.0)
// InvViewMatrix:
dp4 r4.x, r5.xyzw, cb0[4].xyzw
dp4 r4.y, r5.xyzw, cb0[5].xyzw
dp4 r4.z, r5.xyzw, cb0[6].xyzw
// Add adjustment:
add r6.xyz, r6.xyz, r4.xyz

mov r1.xyz, r6.xyz

    add r1.xy, r1.xyxx, cb2[0].xyxx
    mul r2.x, r1.x, cb2[0].z
    mad r2.z, -r1.y, cb2[0].w, l(1.000000)
    sample_l_indexable(texture2d)(float,float,float,float) r1.xyw, r2.xzxx, t1.xywz, s0, l(0.000000)
    add r1.xyw, r1.xyxw, l(-0.000000, -1.000000, 0.000000, -1.000000)
    mad r1.xyw, cb1[19].zzzz, r1.xyxw, l(0.000000, 1.000000, 0.000000, 1.000000)
    mad r2.x, r1.x, l(500.000000), cb1[14].x
    mul r2.yz, r1.yywy, cb1[14].yyzy
    mad r1.x, r1.x, l(500.000000), cb1[15].x
    mul r1.yw, r1.yyyw, cb1[15].yyyz
    add r2.x, r1.z, -r2.x
    max r2.y, r2.y, l(0.000001)
    div_sat r2.x, r2.x, r2.y
    add r2.x, -r2.x, l(1.000000)
    mul r2.x, r2.z, r2.x
    add r1.x, -r1.x, r1.z
    max r1.y, r1.y, l(0.000001)
    div_sat r1.x, r1.x, -r1.y
    add r1.x, -r1.x, l(1.000000)
    mul r1.x, r1.w, r1.x
    max r1.x, r1.x, r2.x
    mul r1.x, r1.x, cb1[18].z
    max r1.x, r1.x, cb1[18].w
  else 
    mov r1.x, cb1[18].w
  endif 
  mov r0.zw, vThreadGroupID.zzzz
  store_uav_typed u0.xyzw, r0.xyzw, r1.xxxx
endif 
ret 
// Approximately 72 instruction slots used