//CLIPPING FIX UNKNOWN WORKING 3
// Generated by Microsoft (R) HLSL Shader Compiler 10.0.10011.16384
//
//   using 3Dmigoto v1.3.11 on Sun Nov 18 11:56:17 2018
//
//
// Buffer Definitions:
//
// cbuffer TiledLightBuffer_CB
// {
//
//   struct tFogOnlyLightData
//   {
//
//       float3 mPosition;              // Offset:    0
//       float mRadius;                 // Offset:   12
//       float3 mColor;                 // Offset:   16
//       float mSphereLightSize;        // Offset:   28
//       float3 mDirection;             // Offset:   32
//       float mHalfCosConeAngle;       // Offset:   44
//
//   } TiledLightBuffer[512];           // Offset:    0 Size: 24576
//
// }
//
// cbuffer TiledLightCountBuffer_CB
// {
//
//   struct tLightCountData
//   {
//
//       uint mNumLights;               // Offset:    0
//       uint mNumXTiles;               // Offset:    4
//       uint mNumYTiles;               // Offset:    8
//       uint mSHScalesReflectionFlag;  // Offset:   12
//
//   } TiledLightCountBuffer;           // Offset:    0 Size:    16
//
// }
//
// Resource bind info for Light2DBounds
// {
//
//   struct t2DBounds
//   {
//
//       int mLeft;                     // Offset:    0
//       int mRight;                    // Offset:    4
//       int mTop;                      // Offset:    8
//       int mBottom;                   // Offset:   12
//
//   } $Element;                        // Offset:    0 Size:    16
//
// }
//
// Resource bind info for input_frustum_spheres
// {
//
//   struct tFrustumSphere
//   {
//
//       float3 mPosition;              // Offset:    0
//       float mRadius;                 // Offset:   12
//
//   } $Element;                        // Offset:    0 Size:    16
//
// }
//
// Resource bind info for output_lights_per_tile
// {
//
//   uint $Element;                     // Offset:    0 Size:     4
//
// }
//
// Resource bind info for output_num_lights_per_tile
// {
//
//   uint $Element;                     // Offset:    0 Size:     4
//
// }
//
//
// Resource Bindings:
//
// Name                                 Type  Format         Dim Slot Elements
// ------------------------------ ---------- ------- ----------- ---- --------
// Light2DBounds                     texture  struct         r/o    0        1
// input_frustum_spheres             texture  struct         r/o    1        1
// output_lights_per_tile                UAV  struct         r/w    0        1
// output_num_lights_per_tile            UAV  struct         r/w    1        1
// TiledLightBuffer_CB               cbuffer      NA          NA    1        1
// TiledLightCountBuffer_CB          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 cb1[1536], dynamicIndexed
dcl_constantbuffer cb2[1], immediateIndexed
dcl_resource_structured t0, 16
dcl_resource_structured t1, 16
dcl_uav_structured u0, 4
dcl_uav_structured u1, 4
dcl_input vThreadID.xy
dcl_temps 3
dcl_thread_group 8, 32, 1
bufinfo_indexable(structured_buffer, stride=16)(mixed,mixed,mixed,mixed) r0.x, t1.xyzw
uge r0.y, vThreadID.x, cb2[0].x
uge r0.x, vThreadID.y, r0.x
or r0.x, r0.x, r0.y
if_nz r0.x
  ret
endif
udiv r0.x, r1.x, vThreadID.y, cb2[0].y
ld_structured_indexable(structured_buffer, stride=16)(mixed,mixed,mixed,mixed) r2.xyzw, vThreadID.x, l(0), t0.xyzw
ige r0.y, r1.x, r2.x
ige r0.z, r2.y, r1.x
and r0.y, r0.z, r0.y
ige r0.z, r0.x, r2.z
and r0.y, r0.z, r0.y
ige r0.x, r2.w, r0.x
and r0.x, r0.x, r0.y
if_z r0.x
  ret
endif
ld_structured_indexable(structured_buffer, stride=16)(mixed,mixed,mixed,mixed) r0.xyzw, vThreadID.y, l(0), t1.xyzw
lt r1.x, r0.w, l(0.000000)
if_nz r1.x
  mov r1.x, l(0)
else
  imul null, r1.y, vThreadID.x, l(3)
  add r0.xyz, r0.xyzx, -cb1[r1.y + 0].xyzx
  dp3 r1.z, r0.xyzx, r0.xyzx
  sqrt r1.w, r1.z
  dp3 r0.x, r0.xyzx, cb1[r1.y + 2].xyzx
  mad r0.y, -r0.x, r0.x, r1.z
  max r0.y, r0.y, l(0.000000)
  mad r0.z, -cb1[r1.y + 2].w, cb1[r1.y + 2].w, l(1.000000)

//mad r0.z, -cb1[r1.y + 2].w, cb1[r1.y + 2].w, l(10000.0)

  sqrt r0.yz, r0.yyzy
  mul r1.z, r0.x, cb1[r1.y + 2].w
  mad r1.z, r0.z, r0.y, r1.z
  mul r0.y, r0.y, cb1[r1.y + 2].w
  mad r0.x, r0.z, r0.x, -r0.y
  max r0.y, r1.z, l(0.000000)
  min r0.y, r0.y, cb1[r1.y + 0].w
  add r0.y, -r0.y, r1.z
  mul r0.z, r0.x, r0.x
  mad r0.y, r0.y, r0.y, r0.z
  ge r0.x, r0.x, l(0.000000)
  add r0.z, r0.w, cb1[r1.y + 0].w

//intended to make clipping on other areas ... not sure ... NEED CHECK
//clipping light/shadow fix - LOSTI 28.11.2018
mul r0.z, r0.z, l(2.0)
/////////////////////////////////////////

  ge r0.z, r0.z, r1.w
  mul r0.w, r0.w, r0.w
  ge r0.y, r0.w, r0.y
  and r0.x, r0.z, r0.x
  or r1.x, r0.y, r0.x
endif
if_z r1.x
  ret
endif
mov r0.x, vThreadID.y
mov r0.y, l(0)
imm_atomic_iadd r0.x, u1, r0.xyxx, l(1)
ishl r0.y, vThreadID.y, l(8)
iadd r0.x, r0.x, r0.y
store_structured u0.x, r0.x, l(0), vThreadID.x
ret
// Approximately 60 instruction slots used
