//clipping fixed by losti
// MANUALLY DUMPED [ShaderRegex\ShaderFixes\Plague_DHR.ini\_Shadows1]
//
// Generated by Microsoft (R) HLSL Shader Compiler 10.1
//
//   using 3Dmigoto v1.3.16 on Tue Dec 29 10:16:36 2020
//
//
// Buffer Definitions:
//
// cbuffer CBufferGlobalConstant_Z
// {
//
//   struct StructGlobalConstant_Z
//   {
//
//       float4 c[90];                  // Offset:    0
//
//   } Global;                          // Offset:    0 Size:  1440
//
// }
//
// cbuffer CBufferUserConstant_Z
// {
//
//   struct StructUserConstant_Z
//   {
//
//       float4 c[58];                  // Offset:    0
//
//   } User;                            // Offset:    0 Size:   928
//
// }
//
// cbuffer CBufferLightList_Z
// {
//
//   struct StructLightList_Z
//   {
//
//       struct ShaderOmni_Z
//       {
//
//           float4 Pos;                // Offset:    0
//           float4 Dir;                // Offset:   16
//           float4 Color;              // Offset:   32
//           float4 Value;              // Offset:   48
//           float4 Value2;             // Offset:   64
//           float4 Value3;             // Offset:   80
//           float4x4 ViewMat;          // Offset:   96
//           float4x4 ProjMat;          // Offset:  160
//
//       } m_Light[256];                // Offset:    0
//
//       struct ShaderOmniBounds_Z
//       {
//
//           float4 m_BSphere;          // Offset: 57344
//
//       } m_Bounds[256];               // Offset: 57344
//       uint m_Count;                  // Offset: 61440
//
//   } LightList;                       // Offset:    0 Size: 61444
//
// }
//
// Resource bind info for gLightList
// {
//
//   uint $Element;                     // Offset:    0 Size:     4
//
// }
//
//
// Resource Bindings:
//
// Name                                 Type  Format         Dim Slot Elements
// ------------------------------ ---------- ------- ----------- ---- --------
// sZBuffer                          texture  float4          2d    1        1
// gLightList                            UAV  struct         r/w    0        1
// CBufferGlobalConstant_Z           cbuffer      NA          NA    0        1
// CBufferUserConstant_Z             cbuffer      NA          NA    1        1
// CBufferLightList_Z                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[57], immediateIndexed
dcl_constantbuffer cb1[2], immediateIndexed
dcl_constantbuffer cb2[3841], dynamicIndexed
dcl_resource_texture2d (float,float,float,float) t1
dcl_uav_structured u0, 4
dcl_input vThreadIDInGroupFlattened
dcl_input vThreadGroupID.xy
dcl_temps 12
dcl_indexableTemp x0[2], 4
dcl_tgsm_raw g0, 4
dcl_tgsm_raw g1, 4
dcl_tgsm_raw g2, 4
dcl_tgsm_structured g3, 4, 2
dcl_tgsm_raw g4, 4
dcl_tgsm_structured g5, 4, 256
dcl_tgsm_structured g6, 4, 256
dcl_thread_group 64, 1, 1
dcl_resource_texture2d (float,float,float,float) t125
bfi r0.x, l(2), l(2), vThreadIDInGroupFlattened.x, l(0)
imad r0.z, vThreadGroupID.x, l(16), r0.x
ushr r1.x, vThreadIDInGroupFlattened.x, l(2)
imad r0.w, vThreadGroupID.y, l(16), r1.x
add r1.xy, cb1[1].xyxx, l(-1.000000, -1.000000, 0.000000, 0.000000)
ftou r1.xy, r1.xyxx
umin r2.xy, r0.zwzz, r1.xyxx
mov r2.zw, l(0,0,0,0)
ld_indexable(texture2d)(float,float,float,float) r1.z, r2.xyzw, t1.yzxw
add r1.z, r1.z, -cb0[51].z
div r1.z, cb0[51].w, r1.z
min r1.w, r1.z, l(340282346638528860000000000000000000000.000000)
max r1.z, r1.z, l(0.000000)
iadd r0.xy, r0.zzzz, l(1, 3, 0, 0)
umin r2.xy, r0.xwxx, r1.xyxx
mov r2.zw, l(0,0,0,0)
ld_indexable(texture2d)(float,float,float,float) r0.x, r2.xyzw, t1.xyzw
add r0.x, r0.x, -cb0[51].z
div r0.x, cb0[51].w, r0.x
min r1.w, r0.x, r1.w
max r0.x, r0.x, r1.z
iadd r2.y, r0.z, l(2)
mov r2.z, r0.w
umin r3.xy, r1.xyxx, r2.yzyy
mov r3.zw, l(0,0,0,0)
ld_indexable(texture2d)(float,float,float,float) r1.z, r3.xyzw, t1.yzxw
add r1.z, r1.z, -cb0[51].z
div r1.z, cb0[51].w, r1.z
min r1.w, r1.z, r1.w
max r0.x, r0.x, r1.z
umin r3.xy, r0.ywyy, r1.xyxx
mov r3.zw, l(0,0,0,0)
ld_indexable(texture2d)(float,float,float,float) r0.y, r3.xyzw, t1.yxzw
add r0.y, r0.y, -cb0[51].z
div r0.y, cb0[51].w, r0.y
min r0.w, r0.y, r1.w
max r0.x, r0.y, r0.x
if_z vThreadIDInGroupFlattened.x
  store_raw g0.x, l(0), l(340282346638528860000000000000000000000.000000)
  store_raw g1.x, l(0), l(0)
  store_raw g2.x, l(0), l(0)
endif
sync_g_t
atomic_umin g0, l(0), r0.w
atomic_umax g1, l(0), r0.x
sync_g_t
ld_raw r0.x, l(0), g0.xxxx
ld_raw r0.y, l(0), g1.xxxx



mul r1.zw, cb1[1].xxxy, l(0.000000, 0.000000, 0.031250, 0.031250)
utof r2.yw, vThreadGroupID.xxxy


//clipping fix by losti - 29.12.2020
//fixes clipping right - 0.034250 instead of 0.031250, but needs correction below
mad r3.zw, cb1[1].xxxy, l(0.000000, 0.000000, 0.034250, 0.031250), -r2.yyyw

//mad r3.zw, cb1[1].xxxy, l(0.000000, 0.000000, 0.031250, 0.031250), -r2.yyyw

mul r3.y, r1.z, cb0[49].x
mul r3.x, r1.w, -cb0[50].y
//fix clipping left, 20 instead of 2
add r4.xyzw, -r3.yzxw, l(0.000000, 20.000000, 0.000000, 2.000000)

//add r4.xyzw, -r3.yzxw, l(0.000000, 2.000000, 0.000000, 2.000000)




dp2 r0.w, r3.yzyy, r3.yzyy
sqrt r0.w, r0.w
rcp r0.w, r0.w
mul r1.zw, r0.wwww, r3.yyyz
dp2 r0.w, r4.xyxx, r4.xyxx
sqrt r0.w, r0.w
rcp r0.w, r0.w
mul r2.yw, r0.wwww, r4.xxxy
dp2 r0.w, r3.xwxx, r3.xwxx
sqrt r0.w, r0.w
rcp r0.w, r0.w
mul r3.xy, r0.wwww, r3.xwxx
dp2 r0.w, r4.zwzz, r4.zwzz
sqrt r0.w, r0.w
rcp r0.w, r0.w
mul r3.zw, r0.wwww, r4.zzzw
umin r0.w, l(256), cb2[3840].x
mov r4.x, vThreadIDInGroupFlattened.x
loop
  uge r4.y, r4.x, r0.w
  breakc_nz r4.y
  dp2 r4.y, cb2[r4.x + 3584].xzxx, r1.zwzz
  dp2 r4.z, cb2[r4.x + 3584].xzxx, r2.ywyy
  ge r4.yz, r4.yyzy, -cb2[r4.x + 3584].wwww
  and r4.y, r4.z, r4.y
  dp2 r4.z, cb2[r4.x + 3584].yzyy, r3.xyxx
  ge r4.z, r4.z, -cb2[r4.x + 3584].w
  and r4.y, r4.z, r4.y
  dp2 r4.z, cb2[r4.x + 3584].yzyy, r3.zwzz
  ge r4.z, r4.z, -cb2[r4.x + 3584].w
  and r4.y, r4.z, r4.y
  if_nz r4.y
    add r4.y, -r0.x, cb2[r4.x + 3584].z
    add r4.z, r0.y, -cb2[r4.x + 3584].z
    ge r4.yz, r4.yyzy, -cb2[r4.x + 3584].wwww
    and r4.y, r4.z, r4.y
    if_nz r4.y
      imm_atomic_iadd r5.x, g2, l(0), l(1)
      store_structured g5.x, r5.x, l(0), r4.x
    endif
  endif
  iadd r4.x, r4.x, l(64)
endloop
ult r0.xy, vThreadIDInGroupFlattened.xxxx, l(2, 32, 0, 0)
if_nz r0.x
  store_structured g3.x, vThreadIDInGroupFlattened.x, l(0), l(0)
endif
sync_g_t
ld_raw r0.x, l(0), g2.xxxx
umin r0.x, r0.x, l(64)
mov x0[0].x, l(0)
mov x0[1].x, l(0)
mov r3.zw, l(0,0,0,0)
mov r4.w, l(1.000000)
mov r0.w, l(0)
loop
  uge r1.z, r0.w, r0.x
  breakc_nz r1.z
  ld_structured r1.z, r0.w, l(0), g5.xxxx
  mov r1.w, l(0)
  mov r2.y, l(0)
  loop
    ige r2.w, r2.y, l(4)
    breakc_nz r2.w
    iadd r2.x, r0.z, r2.y
    umin r3.xy, r1.xyxx, r2.xzxx
    ld_indexable(texture2d)(float,float,float,float) r4.z, r3.xyzw, t1.yzxw
    utof r2.xw, r3.xxxy
    add r2.xw, r2.xxxw, l(0.500000, 0.000000, 0.000000, 0.500000)
    mul r2.xw, r2.xxxw, cb1[1].zzzw
    mad r4.xy, r2.xwxx, l(2.00000, -2.000000, 0.000000, 0.000000), l(-1.000000, 1.00000, 0.000000, 0.000000)

// Pattern Fix for Shadows, Lights and Reflections 1:

ld_indexable(texture2d)(float,float,float,float) r6.xyzw, l(0, 0, 0, 0), t125.xyzw
dp4 r8.x, r4.xyzw, cb0[56].xyzw
mul r7.x r6.y, r8.x
add r7.x, r7.x, l(-1.0)
mul r7.x, r6.x, r7.x
add r4.x, r4.x, r7.x


    dp4 r5.x, r4.xyzw, cb0[53].xyzw
    dp4 r5.y, r4.xyzw, cb0[54].xyzw
    dp4 r5.z, r4.xyzw, cb0[55].xyzw
    dp4 r2.x, r4.xyzw, cb0[56].xyzw
    div r4.xyz, r5.xyzx, r2.xxxx
    add r4.xyz, r4.xyzx, -cb2[r1.z + 3584].xyzx
    dp3 r2.x, r4.xyzx, r4.xyzx
    sqrt r2.x, r2.x
    lt r2.x, r2.x, cb2[r1.z + 3584].w
    movc r1.w, r2.x, l(1), r1.w
    iadd r2.y, r2.y, l(1)
  endloop
  ult r1.z, r0.w, l(32)
  movc r1.z, r1.z, l(0), l(1)
  ishl r2.x, r1.w, r0.w
  mov r2.y, x0[r1.z + 0].x
  or r2.x, r2.x, r2.y
  mov x0[r1.z + 0].x, r2.x
  iadd r0.w, r0.w, l(1)
endloop
mov r0.z, x0[0].x
atomic_or g3, l(0, 0, 0, 0), r0.z
mov r0.z, x0[1].x
atomic_or g3, l(1, 0, 0, 0), r0.z
if_z vThreadIDInGroupFlattened.x
  store_raw g4.x, l(0), l(0)
endif
sync_g_t
ult r0.x, vThreadIDInGroupFlattened.x, r0.x
movc r0.y, r0.y, l(0), l(1)
ld_structured r0.y, r0.y, l(0), g3.xxxx
ishl r0.z, l(1), vThreadIDInGroupFlattened.x
and r0.y, r0.z, r0.y
ine r0.y, r0.y, l(0)
and r0.x, r0.y, r0.x
if_nz r0.x
  imm_atomic_iadd r0.x, g4, l(0), l(1)
  ld_structured r0.y, vThreadIDInGroupFlattened.x, l(0), g5.xxxx
  store_structured g6.x, r0.x, l(0), r0.y
endif
sync_g_t
if_z vThreadIDInGroupFlattened.x
  utof r0.xy, vThreadGroupID.yxyy
  mad r0.x, r0.x, cb1[0].x, r0.y
  ftou r0.x, r0.x
  ishl r0.x, r0.x, l(8)
  ld_raw r0.y, l(0), g4.xxxx
  store_structured u0.x, r0.x, l(0), r0.y
  mov r0.z, l(0)
  loop
    uge r0.w, r0.z, r0.y
    breakc_nz r0.w
    iadd r0.w, r0.z, r0.x
    iadd r0.w, r0.w, l(1)
    ld_structured r1.x, r0.z, l(0), g6.xxxx
    store_structured u0.x, r0.w, l(0), r1.x
    iadd r0.z, r0.z, l(1)
  endloop
endif
ret
// Approximately 185 instruction slots used
