// Ambient Occlusion (pass 1)
//
// Generated by Microsoft (R) HLSL Shader Compiler 9.29.952.3111
//
//   using 3Dmigoto v1.2.31 on Wed Mar 02 08:06:51 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
//   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 [unused]
//   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 CSSBCProvider
// {
//
//   float4 CamProjectionParams;        // Offset:    0 Size:    16
//   float4 DepthTextureSize;           // Offset:   16 Size:    16
//   float4 ParamsSSBC0;                // Offset:   32 Size:    16
//   float4 ParamsSSBC1;                // Offset:   48 Size:    16
//   float4 QuadParams;                 // Offset:   64 Size:    16 [unused]
//   float4 TemporalRotationVector;     // Offset:   80 Size:    16
//
// }
//
//
// Resource Bindings:
//
// Name                                 Type  Format         Dim Slot Elements
// ------------------------------ ---------- ------- ----------- ---- --------
// PointSampler                      sampler      NA          NA    0        1
// PointSamplerNullBorder            sampler      NA          NA    1        1
// LinearDepthTexture                texture   float          2d    0        1
// NoiseTexture                      texture  float4          2d    1        1
// NormalWSTexture                   texture  float4          2d    2        1
// HalfLinearDepthTexture            texture   float          2d    3        1
// MotionVectorsTexture              texture  float2          2d    4        1
// SSBCHistoryTexture                texture   float          2d    5        1
// outInterleavedDataBuffer              UAV   float          2d    0        1
// CViewportShaderParameterProvider    cbuffer      NA          NA    0        1
// CSSBCProvider                     cbuffer      NA          NA    1        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_immediateConstantBuffer { { 0.0239521991, 0.0577281788, 0, 0},
                              { -0.173355699, -0.0714426637, 0, 0},
                              { 0.288354, -0.120450102, 0, 0},
                              { -0.165732801, 0.404893696, 0, 0},
                              { -0.218049303, -0.518517911, 0, 0},
                              { 0.636881828, 0.258916587, 0, 0},
                              { -0.748215675, 0.316748410, 0, 0},
                              { 0.350992292, -0.869316220, 0, 0} }
dcl_constantbuffer cb0[32], immediateIndexed
dcl_constantbuffer cb1[6], immediateIndexed
dcl_sampler s0, mode_default
dcl_sampler s1, mode_default
dcl_resource_texture2d (float,float,float,float) t0
dcl_resource_texture2d (float,float,float,float) t1
dcl_resource_texture2d (float,float,float,float) t2
dcl_resource_texture2d (float,float,float,float) t3
dcl_resource_texture2d (float,float,float,float) t4
dcl_resource_texture2d (float,float,float,float) t5
dcl_uav_typed_texture2d (float,float,float,float) u0
dcl_input vThreadID.xy
dcl_temps 11
dcl_thread_group 8, 8, 1

dcl_resource_texture2d (float,float,float,float) t125

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

utof r0.xy, vThreadID.xyxx
add r0.xy, r0.xyxx, l(0.500000, 0.500000, 0.000000, 0.000000)
mul r0.zw, r0.xxxy, cb1[1].zzzw
mov r1.xy, vThreadID.xyxx
mov r1.zw, l(0,0,0,0)
ld_indexable(texture2d)(float,float,float,float) r2.xy, r1.xyww, t4.xyzw
ld_indexable(texture2d)(float,float,float,float) r2.z, r1.xyww, t0.yzxw
mul r2.w, r2.z, cb0[31].y

// Confirmed r2.w is the linear depth by setting convergence to 1.0 and
// verifying that everything beyond screen depth was solid red
//store_uav_typed u0.xyzw, vThreadID.xyyy, r2.w

mad r3.x, r2.z, cb0[31].y, -cb1[3].z
mul_sat r3.x, r3.x, cb1[3].w
add r3.x, -r3.x, l(1.000000)
lt r3.y, l(0.010000), r3.x
if_nz r3.y
  ld_indexable(texture2d)(float,float,float,float) r1.xyz, r1.xyzw, t2.xyzw
  mad r1.xyz, r1.xyzx, l(2.000000, 2.000000, 2.000000, 0.000000), l(-1.000000, -1.000000, -1.000000, 0.000000)
  dp3 r4.x, r1.xyzx, cb0[12].xyzx
  dp3 r4.y, r1.xyzx, cb0[13].xyzx
  dp3 r4.z, r1.xyzx, cb0[14].xyzx
  mul r1.x, r2.w, cb1[2].z
  rcp r1.y, r1.x
  mul r1.z, r2.w, l(0.001000)
  mad r3.yz, r0.zzwz, l(0.000000, 2.000000, -2.000000, 0.000000), l(0.000000, -1.000000, 1.000000, 0.000000)
  mul r5.xy, r3.yzyy, cb1[0].xyxx
  mov r5.z, l(-1.000000)
  mul r3.yzw, r2.wwww, r5.xxyz

add r10.w, r3.w, -r10.x
mul r10.w, r10.w, r10.x
mul r10.w, r10.w, cb0[0].x
add r3.y, r3.y, r10.w

  and r5.xy, vThreadID.xyxx, l(3, 3, 0, 0)
  mov r5.zw, l(0,0,0,0)
  ld_indexable(texture2d)(float,float,float,float) r5.xy, r5.xyzw, t1.xyzw
  mad r5.xy, r5.yxyy, l(2.000000, 2.000000, 0.000000, 0.000000), l(-1.000000, -1.000000, 0.000000, 0.000000)
  dp2 r6.x, r5.xyxx, cb1[5].xyxx
  mul r6.zw, cb1[5].xxxy, l(0.000000, 0.000000, -1.000000, 1.000000)
  dp2 r6.y, r5.yxyy, r6.zwzz
  mov r5.zw, -r5.xxxx
  dp2 r7.x, r5.yzyy, cb1[5].xyxx
  dp2 r7.y, r5.wyww, r6.zwzz
  rcp r1.w, r2.w
  mul r1.w, r1.w, r1.x
  min r1.w, r1.w, l(0.100000)
  mul r5.xy, r1.wwww, cb1[0].zwzz
  mul r1.x, r1.x, l(-2.000000)
  mov r8.z, l(-1.000000)
  mov r1.w, l(0)
  mov r2.w, l(0)
  loop 
    ige r4.w, r2.w, l(4)
    breakc_nz r4.w
    dp2 r9.x, r6.xyxx, icb[r2.w + 0].xyxx
    dp2 r9.y, r7.xyxx, icb[r2.w + 0].xyxx
    mad r5.zw, r5.xxxy, r9.xxxy, r0.zzzw

// r4.w has linear depth (blurred):
    sample_l_indexable(texture2d)(float,float,float,float) r4.w, r5.zwzz, t3.yzwx, s0, l(0.000000)
    mad r4.w, r4.w, cb0[31].y, r1.z

    mad r5.zw, r5.zzzw, l(0.000000, 0.000000, 2.000000, -2.000000), l(0.000000, 0.000000, -1.000000, 1.000000)
    mul r8.xy, r5.zwzz, cb1[0].xyxx

    // Split this instruction:
    //mad r8.xyw, r8.xyxz, r4.wwww, -r3.yzyw
    mul r8.xyw, r8.xyxz, r4.wwww

add r10.w, r8.w, -r10.x
mul r10.w, r10.w, r10.x
mul r10.w, r10.w, cb0[0].x
add r8.x, r8.x, r10.w

    add r8.xyw, r8.xyzw, -r3.yzyw

    dp3 r4.w, r8.xywx, r8.xywx
    ishr r5.z, r4.w, l(1)
    iadd r5.z, l(0x5f37642f), -r5.z
    mul r8.xyw, r5.zzzz, r8.xyxw
    dp3 r5.w, r4.xyzx, r8.xywx
    mad_sat r5.w, cb1[3].y, r5.w, -cb1[3].x
    mad r4.w, r4.w, r5.z, r1.x
    mad_sat r4.w, -r4.w, r1.y, l(1.000000)
    mad r1.w, r5.w, r4.w, r1.w
    iadd r2.w, r2.w, l(1)
  endloop 
  mov r8.z, l(-1.000000)
  mov r2.w, r1.w
  mov r4.w, l(4)
  loop 
    ige r5.z, r4.w, l(8)
    breakc_nz r5.z
    dp2 r9.x, r6.xyxx, icb[r4.w + 0].xyxx
    dp2 r9.y, r7.xyxx, icb[r4.w + 0].xyxx
    mad r5.zw, r5.xxxy, r9.xxxy, r0.zzzw

// r6.z has blurred linear depth:
    sample_l_indexable(texture2d)(float,float,float,float) r6.z, r5.zwzz, t3.yzxw, s0, l(0.000000)
    mad r6.z, r6.z, cb0[31].y, r1.z

    mad r5.zw, r5.zzzw, l(0.000000, 0.000000, 2.000000, -2.000000), l(0.000000, 0.000000, -1.000000, 1.000000)
    mul r8.xy, r5.zwzz, cb1[0].xyxx

// Split this instruction:
    //mad r8.xyw, r8.xyxz, r6.zzzz, -r3.yzyw
    mul r8.xyw, r8.xyxz, r6.zzzz

add r10.w, r8.w, -r10.x
mul r10.w, r10.w, r10.x
mul r10.w, r10.w, cb0[0].x
add r8.x, r8.x, r10.w

    add r8.xyw, r8.xyxw, -r3.yzyw

    dp3 r5.z, r8.xywx, r8.xywx
    ishr r5.w, r5.z, l(1)
    iadd r5.w, l(0x5f37642f), -r5.w
    mul r8.xyw, r5.wwww, r8.xyxw
    dp3 r6.z, r4.xyzx, r8.xywx
    mad_sat r6.z, cb1[3].y, r6.z, -cb1[3].x
    mad r5.z, r5.z, r5.w, r1.x
    mad_sat r5.z, -r5.z, r1.y, l(1.000000)
    mad r2.w, r6.z, r5.z, r2.w
    iadd r4.w, r4.w, l(1)
  endloop 
else 
  mov r2.w, l(0)
endif 
mul r0.z, r2.w, l(0.125000)
mad r0.z, r3.x, -r0.z, l(1.000000)
mad r0.xy, r0.xyxx, cb1[1].zwzz, r2.xyxx

// SSBCHistoryTexture
//sample_l_indexable(texture2d)(float,float,float,float) r0.w, r0.xyxx, t5.yzwx, s1, l(0.000000)

// The velocity buffer is broken by a bunch of forward pass shaders. The fix is
// straight forward (e.g. see the pattern in PS c644573b2e962d5d), but doesn't
// seem to add much vs just disabling the velocity buffer here, and this way we
// can skip shipping another 400 shaders. If there are any other more serious
// problems associated with disabling the velocity buffer I might revisit this.
mov r0.w, l(0)

f16tof32 r1.x, r0.w
ushr r0.w, r0.w, l(24)
utof r0.w, r0.w
mul r1.y, r0.w, l(0.00392156886)
add r1.x, -r2.z, r1.x
rcp r1.z, r2.z
mul r1.x, r1.z, |r1.x|
mad_sat r1.x, cb1[5].w, r1.x, cb1[5].z
div r3.xyzw, l(20.000000, 20.000000, 2.000000, 2.000000), cb1[1].xyxy
add r1.zw, -r3.xxxy, l(0.000000, 0.000000, 1.000000, 1.000000)
lt r1.zw, r1.zzzw, r0.xxxy
lt r0.xy, r0.xyxx, r3.xyxx
or r0.xy, r0.xyxx, r1.zwzz
and r0.xy, r0.xyxx, l(0x3f800000, 0x3f800000, 0, 0)
lt r1.zw, r3.zzzw, |r2.yyyy|
and r0.xy, r0.xyxx, r1.zwzz
add r0.x, r0.x, r1.x
add r0.x, r0.y, r0.x
min r0.x, r0.x, l(1.000000)
mad r0.y, -r0.w, l(0.00392156886), r0.z
mad r0.x, r0.x, r0.y, r1.y
f32tof16 r0.y, r2.z
mul r0.x, r0.x, l(255.000000)
ftou r0.x, r0.x
bfi r0.x, l(8), l(24), r0.x, r0.y
store_uav_typed u0.xyzw, vThreadID.xyyy, r0.xxxx
ret 
// Approximately 124 instruction slots used