// Tile Lighting fixing
// Generated by Microsoft (R) HLSL Shader Compiler 9.29.952.3111
//
//   using 3Dmigoto v1.2.57 on Sat May 06 19:54:45 2017
//
//
// Buffer Definitions: 
//
// cbuffer SceneBuffer
// {
//
//   float4x4 g_View;                   // Offset:    0 Size:    64 [unused]
//   float4x4 g_Proj;                   // Offset:   64 Size:    64
//   float4x4 g_ViewProjection;         // Offset:  128 Size:    64 [unused]
//   float4x4 g_ViewInverseMatrix;      // Offset:  192 Size:    64 [unused]
//
// }
//
// cbuffer HPixel_Buffer
// {
//
//   float4 g_TargetUvParam;            // Offset:    0 Size:    16
//
// }
//
// cbuffer CamParam_HPixel_Buffer
// {
//
//   float4 g_CameraParam;              // Offset:    0 Size:    16
//   float4 g_CameraVec;                // Offset:   16 Size:    16 [unused]
//
// }
//
// cbuffer PSParamBuffer1
// {
//
//   float4 g_lightColor;               // Offset:    0 Size:    16 [unused]
//   float4 g_lightVec;                 // Offset:   16 Size:    16 [unused]
//   float4 g_FogParam;                 // Offset:   32 Size:    16 [unused]
//   float4 g_ScreenTileSize;           // Offset:   48 Size:    16
//   float4 g_SpParam;                  // Offset:   64 Size:    16 [unused]
//   uint4 g_spotShadowNo;              // Offset:   80 Size:    16 [unused]
//   float4 g_ScreenTileOffset;         // Offset:   96 Size:    16 [unused]
//   float4 g_FogColor;                 // Offset:  112 Size:    16 [unused]
//
// }
//
// Resource bind info for g_LightAry
// {
//
//   struct sPointLight
//   {
//       
//       float4 worldPos;               // Offset:    0
//       float4 viewPos;                // Offset:   16
//       float4 lightCol;               // Offset:   32
//
//   } $Element;                        // Offset:    0 Size:    48
//
// }
//
// Resource bind info for gFramebuffer
// {
//
//   uint $Element;                     // Offset:    0 Size:     4
//
// }
//
//
// Resource Bindings:
//
// Name                                 Type  Format         Dim Slot Elements
// ------------------------------ ---------- ------- ----------- ---- --------
// g_GBufferTextures0                texture  float4          2d    0        1
// g_LightAry                        texture  struct         r/o    5        1
// gFramebuffer                          UAV  struct         r/w    0        1
// SceneBuffer                       cbuffer      NA          NA    0        1
// PSParamBuffer1                    cbuffer      NA          NA    2        1
// HPixel_Buffer                     cbuffer      NA          NA   12        1
// CamParam_HPixel_Buffer            cbuffer      NA          NA   13        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[6], immediateIndexed
dcl_constantbuffer cb12[1], immediateIndexed
dcl_constantbuffer cb13[1], immediateIndexed
dcl_constantbuffer cb2[4], immediateIndexed
dcl_resource_texture2d (float,float,float,float) t0
dcl_resource_structured t5, 48 
dcl_uav_structured u0, 4
dcl_input vThreadGroupID.xy
dcl_input vThreadIDInGroup.xy
dcl_input vThreadID.xy

dcl_resource_texture2d (float,float,float,float) t125
dcl_temps 6


dcl_tgsm_raw g0, 4
dcl_tgsm_raw g1, 4
dcl_tgsm_raw g2, 4
dcl_tgsm_structured g3, 4, 512
dcl_tgsm_raw g4, 4
dcl_tgsm_structured g5, 4, 512
dcl_thread_group 32, 30, 1
ftou r0.xy, cb12[0].zwzz
ftou r0.z, cb2[3].x
imad r0.w, vThreadIDInGroup.y, l(32), vThreadIDInGroup.x
bufinfo_indexable(structured_buffer, stride=48)(mixed,mixed,mixed,mixed) r1.x, t5.xyzw
if_z r0.w
  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)
  store_raw g4.x, l(0), l(0)
endif 
sync_g_t
ult r0.xy, vThreadID.xyxx, r0.xyxx
and r0.x, r0.y, r0.x
if_nz r0.x
  mov r2.xy, vThreadID.xyxx
  mov r2.zw, l(0,0,0,0)
  ld_aoffimmi_indexable(0,0,0)(texture2d)(float,float,float,float) r0.x, r2.xyzw, t0.xyzw
  mad r0.x, r0.x, cb13[0].y, cb13[0].x
  atomic_umin g0, l(0), r0.x
  atomic_umax g1, l(0), r0.x
endif 
sync_g_t
ld_raw r0.x, l(0), g0.xxxx
ld_raw r2.x, l(0), g1.xxxx
mul r1.yz, l(0.000000, 0.015625, 0.0166666675, 0.000000), cb12[0].zzwz
utof r3.xy, vThreadGroupID.xyxx
mad r3.xy, cb12[0].zwzz, l(0.015625, 0.0166666675, 0.000000, 0.000000), -r3.xyxx
mul r4.y, r1.y, cb0[4].x
mul r4.x, r1.z, -cb0[5].y
mov r4.zw, -r3.xxxy

ld_indexable(texture2d)(float,float,float,float) r5.xyzw, l(0, 0, 0, 0), t125.xyzw
add r5.y, r4.z, r5.y
mul r5.x, r5.x, r5.y
rcp r5.w, cb0[4].x
mul r5.x, r5.x, r5.w
//add r4.x, r4.x, r5.x



add r3.xyzw, -r4.yzxw, l(0.000000, -1.000000, 0.000000, -1.000000)
mov r2.z, -r0.x
dp2 r0.x, r3.xyxx, r3.xyxx
sqrt r0.x, r0.x
rcp r0.x, r0.x
mul r0.xy, r0.xxxx, r3.xyxx
dp2 r1.y, r4.yzyy, r4.yzyy
sqrt r1.y, r1.y
rcp r1.y, r1.y
mul r1.yz, r1.yyyy, r4.yyzy
dp2 r1.w, r3.zwzz, r3.zwzz
sqrt r1.w, r1.w
rcp r1.w, r1.w
mul r3.xy, r1.wwww, r3.zwzz
dp2 r1.w, r4.xwxx, r4.xwxx
sqrt r1.w, r1.w
rcp r1.w, r1.w
mul r3.zw, r1.wwww, r4.xxxw
mov r1.w, r0.w
loop 
  uge r2.w, r1.w, r1.x
  breakc_nz r2.w
  ld_structured_indexable(structured_buffer, stride=48)(mixed,mixed,mixed,mixed) r4.xyzw, r1.w, l(12), t5.xyzw
  dp2 r2.w, r0.xyxx, r4.ywyy
  ge r2.w, r2.w, -r4.x
  dp2 r4.y, r1.yzyy, r4.ywyy
  ge r4.y, r4.y, -r4.x
  and r2.w, r2.w, r4.y
  dp2 r4.y, r3.xyxx, r4.zwzz
  ge r4.y, r4.y, -r4.x
  and r2.w, r2.w, r4.y
  dp2 r4.y, r3.zwzz, r4.zwzz
  ge r4.y, r4.y, -r4.x
  and r2.w, r2.w, r4.y
  mov r2.y, r4.w
  dp2 r4.y, l(1.000000, 1.000000, 0.000000, 0.000000), r2.xyxx
  ge r4.y, r4.y, -r4.x
  and r2.w, r2.w, r4.y
  //if_nz r2.w
    dp2 r2.y, l(-1.000000, 1.000000, 0.000000, 0.000000), r2.yzyy
    ge r2.y, r2.y, -r4.x
    if_nz r2.y
      imm_atomic_iadd r4.x, g2, l(0), l(1)
      store_structured g3.x, r4.x, l(0), r1.w
    else 
      imm_atomic_iadd r4.x, g4, l(0), l(1)
      store_structured g5.x, r4.x, l(0), r1.w
    endif 
  //endif 
  iadd r1.w, r1.w, l(960)
endloop 
sync_g_t
imad r0.x, vThreadGroupID.y, r0.z, vThreadGroupID.x
iadd r0.y, r1.x, l(2)
ld_raw r0.z, l(0), g2.xxxx
mov r1.x, r0.w
loop 
  uge r1.y, r1.x, r0.z
  breakc_nz r1.y
  imad r1.y, r0.x, r0.y, r1.x
  ld_structured r1.z, r1.x, l(0), g3.xxxx
  store_structured u0.x, r1.y, l(0), r1.z
  iadd r1.x, r1.x, l(960)
endloop 
ld_raw r0.z, l(0), g2.xxxx
imad r1.x, r0.x, r0.y, r0.z
store_structured u0.x, r1.x, l(0), l(0x0000ffff)
ld_raw r1.x, l(0), g4.xxxx
mov r1.y, r0.w
loop 
  uge r1.z, r1.y, r1.x
  breakc_nz r1.z
  imad r1.z, r0.x, r0.y, r1.y
  iadd r1.z, r1.z, r0.z
  iadd r1.z, r1.z, l(1)
  ld_structured r1.w, r1.y, l(0), g5.xxxx
  store_structured u0.x, r1.z, l(0), r1.w
  iadd r1.y, r1.y, l(960)
endloop 
ld_raw r0.w, l(0), g4.xxxx
iadd r0.z, r0.z, r0.w
imad r0.x, r0.x, r0.y, r0.z
iadd r0.x, r0.x, l(1)
store_structured u0.x, r0.x, l(0), l(0x0000fffe)
ret 
// Approximately 115 instruction slots used
