// asmtool.py -i --fix-fcprimal-volumetric-fog --only-autofixed -f 08e56ca875f16eb4-cs.txt
//
// Generated by Microsoft (R) HLSL Shader Compiler 9.29.952.3111
//
//   using 3Dmigoto v1.2.31 on Wed Mar 02 08:06:24 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 [unused]
//   float4 VFFogDensityTop;            // Offset:  240 Size:    16 [unused]
//   float4 VFFogParams0;               // Offset:  256 Size:    16
//   float4 VFFogParams1;               // Offset:  272 Size:    16
//   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 [unused]
//
// }
//
// cbuffer CSunShadowProvider
// {
//
//   float4 CSMSlice0_0;                // Offset:    0 Size:    16 [unused]
//   float4 CSMSlice0_1;                // Offset:   16 Size:    16 [unused]
//   float4 CSMSlice0_2;                // Offset:   32 Size:    16 [unused]
//   float4 CSMSlice1_0;                // Offset:   48 Size:    16 [unused]
//   float4 CSMSlice1_1;                // Offset:   64 Size:    16 [unused]
//   float4 CSMSlice1_2;                // Offset:   80 Size:    16 [unused]
//   float4 CSMSlice2_0;                // Offset:   96 Size:    16 [unused]
//   float4 CSMSlice2_1;                // Offset:  112 Size:    16 [unused]
//   float4 CSMSlice2_2;                // Offset:  128 Size:    16 [unused]
//   float4 CSMSliceFade;               // Offset:  144 Size:    16 [unused]
//   float4 ShadowMapSize;              // Offset:  160 Size:    16 [unused]
//   float4 SunColor;                   // Offset:  176 Size:    16
//   float4 SunDirection;               // Offset:  192 Size:    16
//
// }
//
// cbuffer CSceneTerrainSkyOcclusionAtlasPrivateData
// {
//
//   float4 SectorOcclusion_OffsetScale;// Offset:    0 Size:    16
//   float3 SectorOcclusion_DistanceFade;// Offset:   16 Size:    12
//   float2 SectorOcclusion_HeightOffsetScale;// Offset:   32 Size:     8
//
// }
//
// cbuffer CAmbientProvider
// {
//
//   float4 CascadeDistanceScales[5];   // Offset:    0 Size:    80
//   float4 CascadeNearFarSnappedOffsetCamera[5];// Offset:   80 Size:    80
//   float4 CascadeNearFarRcpUVSize[5]; // Offset:  160 Size:    80
//   float4 UndergroundSHR;             // Offset:  240 Size:    16
//   float4 UndergroundSHG;             // Offset:  256 Size:    16
//   float4 UndergroundSHB;             // Offset:  272 Size:    16
//   float InvUndergroundBlendEndHeight;// Offset:  288 Size:     4
//   float IndirectLightingScale;       // Offset:  292 Size:     4 [unused]
//
// }
//
// Resource bind info for ExposureBuffer
// {
//
//   float4 $Element;                   // Offset:    0 Size:    16
//
// }
//
// Resource bind info for SkyParamBuffer
// {
//
//   struct ComputedSkyParameters
//   {
//       
//       float r[9];                    // Offset:    0
//       float g[9];                    // Offset:   36
//       float b[9];                    // Offset:   72
//       float3 sunColor;               // Offset:  108
//       float3 moonColor;              // Offset:  120
//
//   } $Element;                        // Offset:    0 Size:   132
//
// }
//
//
// Resource Bindings:
//
// Name                                 Type  Format         Dim Slot Elements
// ------------------------------ ---------- ------- ----------- ---- --------
// LinearVolumeSamplerState          sampler      NA          NA    0        1
// SectorHemiMapSamplerStateLinear    sampler      NA          NA    1        1
// VFMaxDepthDiv2Texture             texture   float          2d    0        1
// ExposureBuffer                    texture  struct         r/o    1        1
// SHOccTextureR                     texture  float4          3d    2        1
// SHOccTextureG                     texture  float4          3d    3        1
// SHOccTextureB                     texture  float4          3d    4        1
// SkyParamBuffer                    texture  struct         r/o    5        1
// SectorOcclusion_HeightTexture__TexObj__    texture  float4          2d    6        1
// VFDensityVolumeTexture            texture  float4          3d    7        1
// VFShadowVolumeTexture             texture  float4          3d    8        1
// VFOutputBufferRGB                     UAV  float3          3d    0        1
// VFOutputBufferAlpha                   UAV   float          3d    1        1
// CViewportShaderParameterProvider    cbuffer      NA          NA    0        1
// CVolumetricFogProvider            cbuffer      NA          NA    1        1
// CSunShadowProvider                cbuffer      NA          NA    2        1
// CSceneTerrainSkyOcclusionAtlasPrivateData    cbuffer      NA          NA    3        1
// CAmbientProvider                  cbuffer      NA          NA    4        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[13], immediateIndexed
dcl_constantbuffer cb3[3], immediateIndexed
dcl_constantbuffer cb4[19], dynamicIndexed
dcl_sampler s0, mode_default
dcl_sampler s1, mode_default
dcl_resource_texture2d (float,float,float,float) t0
dcl_resource_structured t1, 16 
dcl_resource_texture3d (float,float,float,float) t2
dcl_resource_texture3d (float,float,float,float) t3
dcl_resource_texture3d (float,float,float,float) t4
dcl_resource_structured t5, 132 
dcl_resource_texture2d (float,float,float,float) t6
dcl_resource_texture3d (float,float,float,float) t7
dcl_resource_texture3d (float,float,float,float) t8
dcl_uav_typed_texture3d (float,float,float,float) u0
dcl_uav_typed_texture3d (float,float,float,float) u1
dcl_input vThreadGroupID.xyz
dcl_input vThreadIDInGroup.xy
dcl_temps 10
dcl_thread_group 16, 16, 1

// 3DMigoto StereoParams:
dcl_resource_texture2d (float,float,float,float) t125

ld_indexable(texture2d)(float,float,float,float) r7.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 r2.z, r1.w, -r2.y
  add r1.w, r1.w, r2.y
  mul r3.xyz, r1.wwww, r1.xyzx
  mul r2.yw, r3.xxxy, l(0.000000, 0.500000, 0.000000, 0.500000)
  mad r3.xyz, r3.xyzx, l(0.500000, 0.500000, 0.500000, 0.000000), cb0[42].xyzx

// Volumetric Fog fix inserted with DarkStarSword's asmtool.py:
// asmtool.py -i --fix-fcprimal-volumetric-fog --only-autofixed -f 08e56ca875f16eb4-cs.txt

mov r8.xyz, r3.xyzx
mov r8.w, l(1.0)
dp4 r9.w, r8.xyzw, cb0[19].xyzw
add r9.x, r9.w, -r7.y
mul r9.x, r9.x, -r7.x
mul r9.x, r9.x, cb0[0].x
mov r9.yzw, l(0.0)
dp4 r8.x, r9.xyzw, cb0[4].xyzw
dp4 r8.y, r9.xyzw, cb0[5].xyzw
dp4 r8.z, r9.xyzw, cb0[6].xyzw
add r3.xyz, r3.xyzw, r8.xyzx

  iadd r4.xy, cb1[22].xyxx, l(-1, -1, 0, 0)
  umin r4.xy, r0.xyxx, r4.xyxx
  mov r4.zw, l(0,0,0,0)
  ld_indexable(texture2d)(float,float,float,float) r1.w, r4.xyzw, t0.yzwx
  mad r1.w, r1.w, cb0[31].y, -cb1[12].w
  div r1.w, r1.w, cb1[12].z
  log r1.w, r1.w
  mul r1.w, r2.x, r1.w
  mad r1.w, r1.w, l(0.250000), l(1.000000)
  ftou r1.w, r1.w
  uge r1.w, r1.w, vThreadGroupID.z
  if_nz r1.w
    dp3 r1.w, r1.xyzx, r1.xyzx
    rsq r1.w, r1.w
    mul r1.xyz, r1.wwww, r1.xyzx
    mov r0.z, vThreadGroupID.z
    mov r0.w, l(0)
    ld_indexable(texture3d)(float,float,float,float) r1.w, r0.xyzw, t7.yzwx
    mul r2.x, r1.w, cb1[16].x
    ld_indexable(texture3d)(float,float,float,float) r3.w, r0.xyzw, t8.yzwx
    dp2 r2.y, r2.ywyy, r2.ywyy
    sqrt r2.w, r2.y
    lt r4.x, r2.w, cb4[2].y
    movc r4.x, r4.x, l(2), l(3)
    lt r4.y, r2.w, cb4[1].y
    movc r4.x, r4.y, l(1), r4.x
    lt r4.y, r2.w, cb4[0].y
    movc r4.x, r4.y, l(0), r4.x
    add r5.xyzw, r3.xyxy, -cb4[r4.x + 5].xyzw
    mul r5.xyzw, r5.xyzw, cb4[r4.x + 10].xxyy
    utof r4.y, r4.x
    add r4.yz, r4.yyyy, l(0.000000, 0.500000, 1.500000, 0.000000)
    mul r6.xz, r4.yyzy, l(0.200000, 0.000000, 0.200000, 0.000000)
    mov r6.yw, r5.xxxy
    sample_l_indexable(texture3d)(float,float,float,float) r4.y, r6.ywxy, t2.yxzw, s0, l(0.000000)
    sample_l_indexable(texture3d)(float,float,float,float) r4.z, r6.ywxy, t3.yzxw, s0, l(0.000000)
    sample_l_indexable(texture3d)(float,float,float,float) r4.w, r6.ywxy, t4.yzwx, s0, l(0.000000)
    mov r6.xy, r5.zwzz
    sample_l_indexable(texture3d)(float,float,float,float) r5.x, r6.xyzx, t2.xyzw, s0, l(0.000000)
    sample_l_indexable(texture3d)(float,float,float,float) r5.y, r6.xyzx, t3.yxzw, s0, l(0.000000)
    sample_l_indexable(texture3d)(float,float,float,float) r5.z, r6.xyzx, t4.yzxw, s0, l(0.000000)
    mad_sat r2.w, r2.w, cb4[r4.x + 0].z, cb4[r4.x + 0].w
    add r4.x, -r4.y, r5.x
    mad r4.x, r2.w, r4.x, r4.y
    add r4.y, -r4.z, r5.y
    mad r4.y, r2.w, r4.y, r4.z
    add r4.z, -r4.w, r5.z
    mad r2.w, r2.w, r4.z, r4.w
    ld_structured_indexable(structured_buffer, stride=132)(mixed,mixed,mixed,mixed) r5.xyzw, l(0), l(108), t5.xywz
    dp3 r4.z, r5.xywx, l(0.212600, 0.715200, 0.072200, 0.000000)
    ld_structured_indexable(structured_buffer, stride=132)(mixed,mixed,mixed,mixed) r5.xy, l(0), l(124), t5.xyxx
    dp3 r4.w, r5.zxyz, l(0.212600, 0.715200, 0.072200, 0.000000)
    max r4.z, r4.w, r4.z
    ld_structured_indexable(structured_buffer, stride=132)(mixed,mixed,mixed,mixed) r4.w, l(0), l(0), t5.xxxx
    ld_structured_indexable(structured_buffer, stride=132)(mixed,mixed,mixed,mixed) r5.x, l(0), l(36), t5.xxxx
    ld_structured_indexable(structured_buffer, stride=132)(mixed,mixed,mixed,mixed) r5.y, l(0), l(72), t5.xxxx
    max r5.x, r5.y, r5.x
    max r4.w, r4.w, r5.x
    add r4.z, r4.w, r4.z
    mul r4.xy, r4.zzzz, r4.xyxx
    mul r2.w, r2.w, r4.z
    mul r5.xy, r4.xyxx, l(0.282094806, 0.282094806, 0.000000, 0.000000)
    mul r5.z, r2.w, l(0.282094806)
    max r4.xyz, r5.xyzx, l(0.000000, 0.000000, 0.000000, 0.000000)
    mul r2.w, cb4[15].x, l(0.282094806)
    mul r4.w, cb4[16].x, l(0.282094806)
    mul r5.x, cb4[17].x, l(0.282094806)
    max r6.x, r2.w, l(0.000000)
    max r6.y, r4.w, l(0.000000)
    max r6.z, r5.x, l(0.000000)
    mad r3.xy, r3.yxyy, cb3[0].yxyy, cb3[0].wzww
    sample_l_indexable(texture2d)(float,float,float,float) r2.w, r3.xyxx, t6.xzwy, s1, l(0.000000)
    mad r2.w, r2.w, cb3[2].x, cb3[2].y
    add r2.w, -r2.w, r3.z
    mul_sat r2.w, -r2.w, cb4[18].x
    sqrt r2.w, r2.w
    mad r2.y, cb3[1].x, r2.y, cb3[1].y
    mul_sat r2.y, r2.y, l(3.000000)
    mul r2.y, r2.w, r2.y
    add r3.xyz, -r4.xyzx, r6.xyzx
    mad r3.xyz, r2.yyyy, r3.xyzx, r4.xyzx
    mul r4.xyz, r3.wwww, cb2[11].xyzx
    dp3 r1.x, cb2[12].xyzx, r1.xyzx
    mad r1.y, -cb1[16].y, cb1[16].y, l(1.000000)
    mad r1.z, cb1[16].y, cb1[16].y, l(1.000000)
    dp2 r1.x, r1.xxxx, cb1[16].yyyy
    add r1.x, -r1.x, r1.z
    log r1.x, |r1.x|
    mul r1.x, r1.x, l(1.500000)
    exp r1.x, r1.x
    div r1.x, r1.y, r1.x
    mul r1.x, r1.x, l(0.785398185)
    mad r1.xyz, r4.xyzx, r1.xxxx, r3.xyzx
    ld_structured_indexable(structured_buffer, stride=16)(mixed,mixed,mixed,mixed) r2.y, l(0), l(0), t1.xxxx
    mul r1.xyz, r1.xyzx, r2.yyyy
    max r1.xyz, r1.xyzx, l(0.0000610351999, 0.0000610351999, 0.0000610351999, 0.000000)
    min r1.xyz, r1.xyzx, l(8192.000000, 8192.000000, 8192.000000, 0.000000)
    mul r1.xyz, r1.xyzx, cb1[17].yzwy
    mul r3.xyz, r2.xxxx, r1.xyzx
    mad r3.w, cb1[17].x, r1.w, r2.x
    mul r1.xyzw, r2.zzzz, r3.xyzw
  else 
    mov r1.xyzw, l(0,0,0,0)
  endif 
  mov r0.zw, vThreadGroupID.zzzz
  store_uav_typed u0.xyzw, r0.xyww, r1.xyzx
  store_uav_typed u1.xyzw, r0.xyzw, r1.wwww
endif 
ret 
// Approximately 141 instruction slots used