//Screen space reflections border.
//
// Generated by Microsoft (R) HLSL Shader Compiler 10.0.10011.16384
//
//   using 3Dmigoto v1.3.16 on Fri Jan 14 20:06:33 2022
//
//
// Note: shader requires additional functionality:
//       64 UAV slots
//
//
// Buffer Definitions:
//
// cbuffer ConstBuf__constants
// {
//
//   struct SSReflectionsConstants
//   {
//
//       int enable;                    // Index:    0
//       int filterSize;                // Index:    0.y
//       float temporalMotionScale;     // Index:    0.z
//       float2 motionRescale;          // Index:    1
//       float minGlossScale;           // Index:    1.z
//       float minGlossBias;            // Index:    1.w
//       float borderScale;             // Index:    2
//       float borderBias;              // Index:    2.y
//       float temporalMaxConvergence;  // Index:    2.z
//       float temporalBaseStrength;    // Index:    2.w
//       float temporalHoleFillingStrength;// Index:    3
//       float temporalMotionRejection; // Index:    3.y
//
//   } srtInput__constants;             // Index:    0-3.y            Components:    14
                                        // Textures:  t0-t5
//
// }
//
// cbuffer ConstBuf__tileConstants
// {
//
//   struct SSReflectionsTileConstants
//   {
//
//       uint tilesHorz;                // Index:    0
//       uint tilesVert;                // Index:    0.y
//       uint permutationOffset;        // Index:    0.z
//       uint firstGroupOffset;         // Index:    0.w
//
//   } srtInput__tileConstants;         // Index:    0.xyzw           Components:     4
//
// }
//
// cbuffer ConstBuf__gbuffers
// {
//
//   struct GBufferStruct
//   {
//
//       float4x4 invViewProjNoZReproj; // Index:    0
//       float4x4 directionProjMatrix;  // Index:    4
//       float2 viewportScale;          // Index:    8
//       float2 viewportBias;           // Index:    8.z
//       float2 invViewportSize;        // Index:    9
//       float2 viewportSize;           // Index:    9.z
//       uint2 viewportSizeUint;        // Index:   10
//       float3 eyePos;                 // Index:   11
//
//   } srtInput__gbuffers;              // Index:    0-11.z           Components:    47
                                        // Textures:  t7-t10
//
// }
//
// Resource bind info for srtInput__constants.texLights
// {
//
//   uint $Element;                     // Index:    0.x              Components:     1
//
// }
//
//
// Resource Bindings:
//
// Name                                 Type  Format         Dim Slot Elements
// ------------------------------ ---------- ------- ----------- ---- --------
// srtInput__constants__smpLinearClamp    sampler      NA          NA    0        1
// srtInput__constants.InputSSRRayColor    texture  float3          2d    0        1
// srtInput__constants.InputSSRRayInfo    texture  float4          2d    1        1
// srtInput__constants.InputMotionVectorsDilated    texture  float2          2d    2        1
// srtInput__constants.InputSSRResolvedTemporal    texture  float4          2d    3        1
// srtInput__constants.texLights     texture  struct         r/o    5        1
// srtInput__gbuffers.linearDepthTexture    texture   float          2d    7        1
// srtInput__gbuffers.normalTexture    texture  float4          2d    9        1
// srtInput__gbuffers.propertiesTexture    texture  float4          2d   10        1
// srtInput__constants.OutputSSRResolved        UAV  float4          2d    8        1
// ConstBuf__constants               cbuffer      NA          NA    0        1
// ConstBuf__tileConstants           cbuffer      NA          NA    1        1
// ConstBuf__gbuffers                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_immediateConstantBuffer { { 0.356642, 0, 0, 0},
                              { 0.239400, 0, 0, 0},
                              { 0.072410, 0, 0, 0},
                              { 0.009869, 0, 0, 0} }
dcl_constantbuffer cb0[4], immediateIndexed
dcl_constantbuffer cb1[1], immediateIndexed
dcl_constantbuffer cb2[12], immediateIndexed
dcl_sampler s0, 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_structured t5, 4
dcl_resource_texture2d (float,float,float,float) t7
dcl_resource_texture2d (float,float,float,float) t9
dcl_resource_texture2d (float,float,float,float) t10
dcl_uav_typed_texture2d (float,float,float,float) u8
dcl_input vThreadIDInGroupFlattened
dcl_input vThreadGroupID.x
dcl_temps 50
dcl_tgsm_structured g0, 16, 64
dcl_tgsm_structured g1, 16, 64
dcl_thread_group 64, 1, 1
dcl_resource_texture2d (float,float,float,float) t125
ld_indexable(texture2d)(float,float,float,float) r40.xyzw, l(0, 0, 0, 0), t125.xyzw
iadd r0.x, vThreadGroupID.x, cb1[0].w
ushr r0.y, r0.x, l(2)
and r1.x, r0.x, l(1)
ubfe r1.y, l(1), l(1), r0.x
udiv r0.x, r2.x, r0.y, cb1[0].x
and r3.x, vThreadIDInGroupFlattened.x, l(7)
ushr r3.y, vThreadIDInGroupFlattened.x, l(3)
ishl r0.zw, r1.xxxy, l(0, 0, 3, 3)
mov r2.y, r0.x
bfi r0.xz, l(31, 0, 31, 0), l(4, 0, 4, 0), r2.xxyx, r0.zzwz
iadd r4.xy, r0.xzxx, r3.xyxx
ieq r0.x, l(0), cb0[0].x
if_z cb0[0].x
  store_uav_typed u8.xyzw, r4.xyyy, l(0,0,0,0)
endif
if_z r0.x
  imul null, r0.x, r0.y, l(3)
  ld_structured_indexable(structured_buffer, stride=4)(mixed,mixed,mixed,mixed) r0.x, r0.x, l(0), t5.xxxx
  and r0.xy, r0.xxxx, l(0x00100000, 0x01000000, 0, 0)
  ine r0.x, r0.x, l(0)
  ieq r0.y, r0.y, l(0)
  or r0.x, r0.x, r0.y
  if_nz r0.x
    store_uav_typed u8.xyzw, r4.xyyy, l(0,0,0,0)
  endif
  if_z r0.x
    ishl r0.xy, r1.xyxx, l(2, 2, 0, 0)
    bfi r0.xy, l(31, 31, 0, 0), l(3, 3, 0, 0), r2.xyxx, r0.xyxx
    iadd r0.xy, r3.xyxx, r0.xyxx
    iadd r0.xy, r0.xyxx, l(-2, -2, 0, 0)
    mov r0.zw, l(0,0,0,0)
    ld_indexable(texture2d)(float,float,float,float) r1.xyzw, r0.xyww, t1.xyzw
    store_structured g0.xyzw, vThreadIDInGroupFlattened.x, l(0), r1.xyzw
    ld_indexable(texture2d)(float,float,float,float) r0.xyz, r0.xyzw, t0.xyzw
    store_structured g1.xyz, vThreadIDInGroupFlattened.x, l(0), r0.xyzx
    utof r0.xy, r4.xyxx
    add r0.xy, r0.xyxx, l(0.500000, 0.500000, 0.000000, 0.000000)
    ftoi r1.xy, r0.xyxx
    mad r0.zw, r0.xxxy, cb2[8].xxxy, cb2[8].zzzw
    mul r2.xy, r0.xyxx, cb2[9].xyxx
    mov r1.zw, l(0,0,0,0)
    ld_indexable(texture2d)(float,float,float,float) r5.z, r1.xyww, t7.yzxw
    mul r5.xy, r0.zwzz, r5.zzzz
    mov r5.w, l(1.000000)
	
	//Disabled with new TAA fix.
	add r40.w, r5.z, -r40.y
    //mad r5.x, -r40.x, r40.w, r5.x
	
	mov r42.x, r5.z
	
    dp4 r6.x, r5.xyzw, cb2[0].xyzw
    dp4 r6.y, r5.xyzw, cb2[1].xyzw
    dp4 r6.z, r5.xyzw, cb2[2].xyzw
    ld_indexable(texture2d)(float,float,float,float) r3.xzw, r1.xyww, t9.xwyz
    mad r3.xzw, r3.xxzw, l(2.000000, 0.000000, 2.000000, 2.000000), l(-1.000000, 0.000000, -1.000000, -1.000000)
    dp3 r0.z, r3.xzwx, r3.xzwx
    rsq r0.z, r0.z
    mul r3.xzw, r0.zzzz, r3.xxzw
    ld_indexable(texture2d)(float,float,float,float) r0.z, r1.xyzw, t10.xyzw
    add r1.xyz, -r6.xyzx, cb2[11].xyzx
	
    //Specular CS.
    mul r41.x, r40.y, cb2[0].x
    mul r41.y, r40.y, cb2[1].x
    mul r41.z, r40.y, cb2[2].x
    mad r1.x, r40.x, r41.x, r1.x
    mad r1.y, r40.x, r41.y, r1.y
    mad r1.z, r40.x, r41.z, r1.z
	
    dp3 r0.w, r1.xyzx, r1.xyzx
    rsq r0.w, r0.w
    add r1.w, -r0.z, l(1.000000)
    mul r1.w, r1.w, r1.w
    max r1.w, r1.w, l(0.001000)
    add r5.xyz, r6.xyzx, -cb2[11].xyzx
    ubfe r2.z, l(2), l(1), vThreadIDInGroupFlattened.x
    ushr r2.w, r3.y, l(1)
    imad r2.z, r2.w, l(8), r2.z
    iadd r2.z, r2.z, l(18)
    sync_g_t
    ineg r2.w, cb0[0].y
    mul r3.y, r1.w, r1.w
    mad r1.w, r1.w, r1.w, l(-1.000000)
    mov r6.w, l(1.000000)
    mov r5.w, l(0)
    mov r7.xyzw, l(0,0,0,0)
    mov r8.x, l(1.000000012E-007)
    mov r8.y, r2.w
    loop
      ilt r8.z, cb0[0].y, r8.y
      breakc_nz r8.z
      ishl r8.z, r8.y, l(3)
      iadd r8.z, r2.z, r8.z
      imax r8.w, -r8.y, r8.y
      mov r9.xyz, r7.xyzx
      mov r9.w, r5.w
      mov r10.x, r7.w
      mov r10.y, r8.x
      mov r10.z, r2.w
      loop
        ilt r10.w, cb0[0].y, r10.z
        breakc_nz r10.w
        iadd r10.w, r8.z, r10.z
        ld_structured r11.xyzw, r10.w, l(0), g0.xyzw
        imax r12.x, -r10.z, r10.z
        mad r10.y, icb[r12.x + 0].x, icb[r8.w + 0].x, r10.y
        lt r12.y, l(0.000000), r11.w
        if_nz r12.y
          add r11.xyz, -r5.xyzx, r11.xyzx
          dp3 r12.y, r11.xyzx, r11.xyzx
          rsq r12.y, r12.y
          mul r11.xyz, r11.xyzx, r12.yyyy
          dp3_sat r12.y, r3.xzwx, r11.xyzx
          lt r12.z, l(0.000000), r12.y
          if_nz r12.z
            mad r11.xyz, r1.xyzx, r0.wwww, r11.xyzx
            dp3 r12.z, r11.xyzx, r11.xyzx
            rsq r12.z, r12.z
            mul r11.xyz, r11.xyzx, r12.zzzz
            dp3 r11.x, r3.xzwx, r11.xyzx
            mul r11.x, r11.x, r11.x
            mad r11.x, r11.x, r1.w, l(1.000000)
            mul r11.x, r11.x, r11.x
            div r11.x, r3.y, r11.x
            mul r11.x, r11.x, r12.y
            mul r11.x, r11.w, r11.x
            ld_structured r6.xyz, r10.w, l(0), g1.xyzx
            mad r9.xyzw, r6.xyzw, r11.xxxx, r9.xyzw
            mad r10.x, icb[r12.x + 0].x, icb[r8.w + 0].x, r10.x
          endif
        endif
        iadd r10.z, r10.z, l(1)
      endloop
      mov r7.xyz, r9.xyzx
      mov r5.w, r9.w
      mov r7.w, r10.x
      mov r8.x, r10.y
      iadd r8.y, r8.y, l(1)
    endloop
    lt r0.w, l(0.000000), r5.w
    div r1.xyz, r7.xyzx, r5.wwww
    movc r1.xyz, r0.wwww, r1.xyzx, r7.xyzx
    div r0.w, l(1.000000, 1.000000, 1.000000, 1.000000), r8.x
    dp2 r0.w, r7.wwww, r0.wwww
    add_sat r1.w, r0.w, l(-0.250000)
    mov r4.zw, l(0,0,0,0)
    ld_indexable(texture2d)(float,float,float,float) r2.zw, r4.xyzw, t2.zwxy
	
	//Disabled with new TAA fix.
	//mad r2.z, r40.x, l(0.5), r2.z
	
    mul r2.zw, r2.zzzw, cb0[1].xxxy
    mad r0.xy, r0.xyxx, cb2[9].xyxx, r2.zwzz
    sample_l_indexable(texture2d)(float,float,float,float) r3.xyzw, r0.xyxx, t3.xyzw, s0, l(0.000000)
    add r0.x, -r1.w, r3.w
    add r0.x, r0.x, l(1.000000)
    mul r0.x, r0.x, cb0[3].x
    mad_sat r0.x, cb0[2].w, r1.w, r0.x
    dp2 r0.y, r2.zwzz, r2.zwzz
    mul r0.y, r0.y, cb0[0].z
    mad_sat r0.y, -r0.y, cb0[3].y, l(1.000000)
    mul r0.x, r0.y, r0.x
    mul r0.x, r0.x, cb0[2].z
    add r3.xyzw, -r1.xyzw, r3.xyzw
    mad r1.xyzw, r0.xxxx, r3.xyzw, r1.xyzw
	
	//SSR border. Sides of screen.
	div r40.w, r40.y, r42.x
	add r40.w, r40.w, l(-1.0)
	mul r40.w, r40.w, l(0.5)
	mad r2.x, r40.x, r40.w, r2.x
	
    mad r0.xy, r2.xyxx, l(2.000000, 2.000000, 0.000000, 0.000000), l(-1.000000, -1.000000, 0.000000, 0.000000)
    max r0.x, |r0.y|, |r0.x|
    mad_sat r0.x, r0.x, cb0[2].x, cb0[2].y
    mul r0.y, r0.x, r0.x
    mad r0.x, -r0.x, l(2.000000), l(3.000000)
    mul r0.x, r0.x, r0.y
    mul r0.x, r0.x, r1.w
    mad_sat r0.y, r0.z, cb0[1].z, cb0[1].w
    mul r1.w, r0.y, r0.x
    max r0.xyzw, r1.xyzw, l(0.000000, 0.000000, 0.000000, 0.000000)
    store_uav_typed u8.xyzw, r4.xyyy, r0.xyzw
  endif
endif
ret
// Approximately 160 instruction slots used
