//Motion blur PS.
// ---- Created with 3Dmigoto v1.3.16 on Sat Jan 08 22:39:28 2022
//
//cbuffer SceneInfo : register(b0)
//{
//  row_major float4x4 viewProjMat : packoffset(c0);
//  row_major float3x4 transposeViewMat : packoffset(c4);
//  row_major float3x4 transposeViewInvMat : packoffset(c7);
//  float4 projElement[2] : packoffset(c10);
//  float4 projInvElements[2] : packoffset(c12);
//  row_major float4x4 viewProjInvMat : packoffset(c14);
//  row_major float4x4 prevViewProjMat : packoffset(c18);
//  float3 ZToLinear : packoffset(c22);
//  float subdivisionLevel : packoffset(c22.w);
//  float2 screenSize : packoffset(c23);
//  float2 screenInverseSize : packoffset(c23.z);
//  float2 cullingHelper : packoffset(c24);
//  float cameraNearPlane : packoffset(c24.z);
//  float cameraFarPlane : packoffset(c24.w);
//  float4 viewFrustum[6] : packoffset(c25);
//  float4 clipplane : packoffset(c31);
//}
//
//cbuffer MBSetting : register(b1)
//{
//  float MBInvertIntensity : packoffset(c0);
//  float MBIntensity : packoffset(c0.y);
//}
//
//SamplerState PointClamp_s : register(s0);
//Texture2D<float4> NeighborMax : register(t0);
//Texture2D<float4> PreComputedV : register(t1);
//Texture2D<float4> HDRImage : register(t2);
//
//
//// 3Dmigoto declarations
//#define cmp -
//Texture1D<float4> IniParams : register(t120);
//Texture2D<float4> StereoParams : register(t125);
//
//
//void main(
//  float4 v0 : SV_POSITION0,
//  out float4 o0 : SV_Target0)
//{
//  float4 r0,r1,r2,r3,r4,r5,r6,r7,r8,r9,r10,r11;
//  uint4 bitmask, uiDest;
//  float4 fDest;
//  
//  float4 stereo = StereoParams.Load(0);
//  
//  r0.xy = float2(0.03125,0.03125) * v0.xy;
//  r0.xy = (int2)r0.xy;
//  r0.zw = float2(0,0);
//  r0.xyzw = NeighborMax.Load(r0.xyz).xyzw;
//  
//  
//  
//  r1.xy = cmp(float2(0,0) < r0.xy);
//  r1.zw = cmp(r0.xy < float2(0,0));
//  r1.xy = (int2)-r1.xy + (int2)r1.zw;
//  r1.xy = (int2)r1.xy;
//  r0.xy = r0.xy * r0.xy;
//  r0.xy = r0.xy * r1.xy;
//  r0.xy = MBInvertIntensity * r0.xy;
//  r1.xy = (int2)v0.xy;
//  r1.zw = float2(0,0);
//  r2.xyzw = HDRImage.Load(r1.xyz).xyzw;
//  r1.z = max(abs(r0.x), abs(r0.y));
//  r1.w = 0.5 * screenInverseSize.x;
//  r1.z = cmp(r1.z < r1.w);
//  if (r1.z != 0) {
//    o0.xyzw = r2.xyzw;
//    return;
//  }
//  r1.zw = screenInverseSize.xy * v0.xy;
//  
//  
//  
//  r1.xy = (int2)r1.xy & int2(1,1);
//  r1.xy = (int2)r1.xy;
//  r1.x = r1.x * 0.5 + -0.25;
//  r1.y = r1.y * 2 + -1;
//  r3.xy = screenInverseSize.xy * float2(0.5,0.5) + r1.zw;
//  
//  
//  
//  r0.z = r0.z + -r0.w;
//  r0.z = cmp(abs(r0.z) < 0.00100000005);
//  if (r0.z != 0) {
//    r4.w = 1;
//    r5.xyzw = float4(0,0,0,0);
//    r0.z = 0;
//    while (true) {
//      r0.w = cmp((int)r0.z >= 8);
//      if (r0.w != 0) break;
//      r0.w = (int)r0.z;
//      r0.w = r1.x * r1.y + r0.w;
//      r0.w = r0.w * 0.25 + -1;
//      r3.zw = r0.xy * r0.ww + r3.xy;
//      r4.xyz = HDRImage.SampleLevel(PointClamp_s, r3.zw, 0).xyz;
//      r5.xyzw = r5.xyzw + r4.xyzw;
//      r0.z = (int)r0.z + 1;
//    }
//  } else {
//    
//	
//	
//    r4.xyzw = PreComputedV.SampleLevel(PointClamp_s, r1.zw, 0).xyzw;
//    r0.zw = cmp(float2(0,0) < r4.xy);
//    r1.zw = cmp(r4.xy < float2(0,0));
//    r0.zw = (int2)-r0.zw + (int2)r1.zw;
//    r0.zw = (int2)r0.zw;
//    r1.zw = r4.xy * r4.xy;
//    r0.zw = r1.zw * r0.zw;
//    r0.zw = MBInvertIntensity * r0.zw;
//    r1.zw = r4.zw * float2(0.5,0.5) + float2(0.5,0.5);
//    r1.zw = float2(0.996108949,0.00389105058) * r1.zw;
//    r1.z = r1.z + r1.w;
//    r1.z = 256 * r1.z;
//    r0.z = dot(r0.zw, r0.zw);
//    r0.z = (uint)r0.z >> 1;
//    r0.z = (int)r0.z + 0x1fbd1df5;
//    r4.x = screenSize.x * r0.z;
//    r0.z = dot(r0.xy, r0.xy);
//    r0.z = (uint)r0.z >> 1;
//    r0.z = (int)r0.z + 0x1fbd1df5;
//    r0.z = screenSize.x * r0.z;
//    r6.w = 1;
//    r7.w = 1;
//    r8.xyzw = float4(0,0,0,0);
//    r0.w = 0;
//    while (true) {
//      r1.w = cmp((int)r0.w >= 4);
//      if (r1.w != 0) break;
//      r1.w = (int)r0.w;
//      r1.w = r1.x * r1.y + r1.w;
//      r2.w = -r1.w * 0.125 + 1;
//      r1.w = r1.w * 0.25 + -1;
//      r2.w = r2.w * 2 + -1;
//      r3.zw = r0.xy * r1.ww + r3.xy;
//      r9.xy = r0.xy * r2.ww + r3.xy;
//      r10.xyzw = PreComputedV.SampleLevel(PointClamp_s, r3.zw, 0).xyzw;
//      r9.zw = cmp(float2(0,0) < r10.xy);
//      r11.xy = cmp(r10.xy < float2(0,0));
//      r9.zw = (int2)-r9.zw + (int2)r11.xy;
//      r9.zw = (int2)r9.zw;
//      r10.xy = r10.xy * r10.xy;
//      r9.zw = r10.xy * r9.zw;
//      r9.zw = MBInvertIntensity * r9.zw;
//      r10.xy = r10.zw * float2(0.5,0.5) + float2(0.5,0.5);
//      r10.xy = float2(0.996108949,0.00389105058) * r10.xy;
//      r2.w = r10.x + r10.y;
//      r4.w = 256 * r2.w;
//      r10.xyzw = PreComputedV.SampleLevel(PointClamp_s, r9.xy, 0).xyzw;
//      r11.xy = cmp(float2(0,0) < r10.xy);
//      r11.zw = cmp(r10.xy < float2(0,0));
//      r11.xy = (int2)-r11.xy + (int2)r11.zw;
//      r11.xy = (int2)r11.xy;
//      r10.xy = r10.xy * r10.xy;
//      r10.xy = r10.xy * r11.xy;
//      r10.xy = MBInvertIntensity * r10.xy;
//      r10.zw = r10.zw * float2(0.5,0.5) + float2(0.5,0.5);
//      r10.zw = float2(0.996108949,0.00389105058) * r10.zw;
//      r10.z = r10.z + r10.w;
//      r10.w = 256 * r10.z;
//      r9.z = dot(r9.zw, r9.zw);
//      r9.z = (uint)r9.z >> 1;
//      r9.z = (int)r9.z + 0x1fbd1df5;
//      r4.y = screenSize.x * r9.z;
//      r9.z = dot(r10.xy, r10.xy);
//      r9.z = (uint)r9.z >> 1;
//      r9.z = (int)r9.z + 0x1fbd1df5;
//      r4.z = screenSize.x * r9.z;
//      r2.w = r2.w * 256 + -r1.z;
//      r9.zw = saturate(r2.ww * float2(40,-40) + float2(0.5,0.5));
//      r11.xyzw = -r0.zzzz * abs(r1.wwww) + r4.xyxz;
//      r11.xyzw = saturate(float4(1,1,1,1) + r11.xyzw);
//      r1.w = dot(r9.zw, r11.xy);
//      r2.w = r10.z * 256 + -r1.z;
//      r9.zw = saturate(r2.ww * float2(40,-40) + float2(0.5,0.5));
//      r2.w = dot(r9.zw, r11.zw);
//      r4.w = cmp(r4.w < r10.w);
//      r4.y = cmp(r4.z < r4.y);
//      r4.z = r4.y ? r4.w : 0;
//      r4.z = r4.z ? r2.w : r1.w;
//      r9.z = (int)r4.y | (int)r4.w;
//      r4.yw = ~(int2)r4.yw;
//      r9.w = r4.y ? r4.w : 0;
//      r9.zw = r9.zw ? r2.ww : r1.ww;
//      r4.z = r9.w + r4.z;
//      r4.y = (int)r4.y | (int)r4.w;
//      r1.w = r4.y ? r2.w : r1.w;
//      r1.w = r9.z + r1.w;
//      r6.xyz = HDRImage.SampleLevel(PointClamp_s, r3.zw, 0).xyz;
//      r10.xyzw = r6.xyzw * r4.zzzz + r8.xyzw;
//      r7.xyz = HDRImage.SampleLevel(PointClamp_s, r9.xy, 0).xyz;
//      r8.xyzw = r7.xyzw * r1.wwww + r10.xyzw;
//      r0.w = (int)r0.w + 1;
//    }
//    r5.xyzw = float4(0.5,0.5,0.5,0.5) * r8.xyzw;
//  }
//  r0.xyzw = float4(0.125,0.125,0.125,0.125) * r5.xyzw;
//  r1.x = -r5.w * 0.125 + 1;
//  o0.xyz = r1.xxx * r2.xyz + r0.xyz;
//  o0.w = r0.w;
//  return;
//}
//
///*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
// Generated by Microsoft (R) HLSL Shader Compiler 10.1
//
//   using 3Dmigoto v1.3.16 on Sat Jan 08 22:39:28 2022
//
//
// Buffer Definitions:
//
// cbuffer SceneInfo
// {
//
//   row_major float4x4 viewProjMat;    // Offset:    0 Size:    64 [unused]
//   row_major float3x4 transposeViewMat;// Offset:   64 Size:    48 [unused]
//   row_major float3x4 transposeViewInvMat;// Offset:  112 Size:    48 [unused]
//   float4 projElement[2];             // Offset:  160 Size:    32 [unused]
//   float4 projInvElements[2];         // Offset:  192 Size:    32 [unused]
//   row_major float4x4 viewProjInvMat; // Offset:  224 Size:    64 [unused]
//   row_major float4x4 prevViewProjMat;// Offset:  288 Size:    64 [unused]
//   float3 ZToLinear;                  // Offset:  352 Size:    12 [unused]
//   float subdivisionLevel;            // Offset:  364 Size:     4 [unused]
//   float2 screenSize;                 // Offset:  368 Size:     8
//   float2 screenInverseSize;          // Offset:  376 Size:     8
//   float2 cullingHelper;              // Offset:  384 Size:     8 [unused]
//   float cameraNearPlane;             // Offset:  392 Size:     4 [unused]
//   float cameraFarPlane;              // Offset:  396 Size:     4 [unused]
//   float4 viewFrustum[6];             // Offset:  400 Size:    96 [unused]
//   float4 clipplane;                  // Offset:  496 Size:    16 [unused]
//
// }
//
// cbuffer MBSetting
// {
//
//   float MBInvertIntensity;           // Offset:    0 Size:     4
//   float MBIntensity;                 // Offset:    4 Size:     4 [unused]
//
// }
//
//
// Resource Bindings:
//
// Name                                 Type  Format         Dim Slot Elements
// ------------------------------ ---------- ------- ----------- ---- --------
// PointClamp                        sampler      NA          NA    0        1
// NeighborMax                       texture  float4          2d    0        1
// PreComputedV                      texture  float4          2d    1        1
// HDRImage                          texture  float4          2d    2        1
// SceneInfo                         cbuffer      NA          NA    0        1
// MBSetting                         cbuffer      NA          NA    1        1
//
//
//
// Input signature:
//
// Name                 Index   Mask Register SysValue  Format   Used
// -------------------- ----- ------ -------- -------- ------- ------
// SV_POSITION              0   xyzw        0      POS   float   xy
//
//
// Output signature:
//
// Name                 Index   Mask Register SysValue  Format   Used
// -------------------- ----- ------ -------- -------- ------- ------
// SV_Target                0   xyzw        0   TARGET   float   xyzw
//
ps_5_0
dcl_globalFlags refactoringAllowed
dcl_constantbuffer cb0[24], immediateIndexed
dcl_constantbuffer cb1[1], 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_input_ps_siv linear noperspective v0.xy, position
dcl_output o0.xyzw
dcl_temps 28
dcl_resource_texture2d (float,float,float,float) t125
ld_indexable(texture2d)(float,float,float,float) r25.xyzw, l(0, 0, 0, 0), t125.xyzw

mov r20.xy, v0.xyxx
//mad r20.x, r25.x, l(1280.0), r20.x

mul r0.xy, v0.xyxx, l(0.031250, 0.031250, 0.000000, 0.000000)



ftoi r0.xy, r0.xyxx
mov r0.zw, l(0,0,0,0)
ld_indexable(texture2d)(float,float,float,float) r0.xyzw, r0.xyzw, t0.xyzw

//mad r0.x, r25.x, l(8.0), r0.x

lt r1.xy, l(0.000000, 0.000000, 0.000000, 0.000000), r0.xyxx
lt r1.zw, r0.xxxy, l(0.000000, 0.000000, 0.000000, 0.000000)
iadd r1.xy, -r1.xyxx, r1.zwzz
itof r1.xy, r1.xyxx
mul r0.xy, r0.xyxx, r0.xyxx
mul r0.xy, r1.xyxx, r0.xyxx
mul r0.xy, r0.xyxx, cb1[0].xxxx



ftoi r1.xy, v0.xyxx
mov r1.zw, l(0,0,0,0)
ld_indexable(texture2d)(float,float,float,float) r2.xyzw, r1.xyzw, t2.xyzw
max r1.z, |r0.y|, |r0.x|
mul r1.w, cb0[23].z, l(0.500000)
lt r1.z, r1.z, r1.w
if_nz r1.z
  mov o0.xyzw, r2.xyzw
  ret
endif
mul r1.zw, v0.xxxy, cb0[23].zzzw
and r1.xy, r1.xyxx, l(1, 1, 0, 0)
itof r1.xy, r1.xyxx
mad r1.x, r1.x, l(0.500000), l(-0.250000)
mad r1.y, r1.y, l(2.000000), l(-1.000000)
mad r3.xy, cb0[23].zwzz, l(0.500000, 0.500000, 0.000000, 0.000000), r1.zwzz

//mad r3.x, r25.x, l(1.0), r3.x

add r0.z, -r0.w, r0.z
lt r0.z, |r0.z|, l(0.001000)
if_nz r0.z
  mov r4.w, l(1.000000)
  mov r5.xyzw, l(0,0,0,0)
  mov r0.z, l(0)
  loop
    ige r0.w, r0.z, l(8)
    breakc_nz r0.w
    itof r0.w, r0.z
    mad r0.w, r1.x, r1.y, r0.w
    mad r0.w, r0.w, l(0.250000), l(-1.000000)
    mad r3.zw, r0.xxxy, r0.wwww, r3.xxxy
	
	//mad r3.z, r25.x, l(1.0), r3.z
	
    sample_l_indexable(texture2d)(float,float,float,float) r4.xyz, r3.zwzz, t2.xyzw, s0, l(0.000000)
    add r5.xyzw, r4.xyzw, r5.xyzw
    iadd r0.z, r0.z, l(1)
  endloop
else
  
  sample_l_indexable(texture2d)(float,float,float,float) r4.xyzw, r1.zwzz, t1.xyzw, s0, l(0.000000)
  
  //mad r4.x, r25.x, l(64.0), r4.x
  
  lt r0.zw, l(0.000000, 0.000000, 0.000000, 0.000000), r4.xxxy
  lt r1.zw, r4.xxxy, l(0.000000, 0.000000, 0.000000, 0.000000)
  iadd r0.zw, -r0.zzzw, r1.zzzw
  itof r0.zw, r0.zzzw
  
  
  
  mul r1.zw, r4.xxxy, r4.xxxy
  mul r0.zw, r0.zzzw, r1.zzzw
  mul r0.zw, r0.zzzw, cb1[0].xxxx
  mad r1.zw, r4.zzzw, l(0.000000, 0.000000, 0.500000, 0.500000), l(0.000000, 0.000000, 0.500000, 0.500000)
  mul r1.zw, r1.zzzw, l(0.000000, 0.000000, 0.996108949, 0.00389105058)
  add r1.z, r1.w, r1.z
  mul r1.z, r1.z, l(256.000000)
  dp2 r0.z, r0.zwzz, r0.zwzz
  ishr r0.z, r0.z, l(1)
  iadd r0.z, r0.z, l(0x1fbd1df5)
  mul r4.x, r0.z, cb0[23].x
  dp2 r0.z, r0.xyxx, r0.xyxx
  ishr r0.z, r0.z, l(1)
  iadd r0.z, r0.z, l(0x1fbd1df5)
  mul r0.z, r0.z, cb0[23].x
  mov r6.w, l(1.000000)
  mov r7.w, l(1.000000)
  mov r8.xyzw, l(0,0,0,0)
  mov r0.w, l(0)
  loop
    ige r1.w, r0.w, l(4)
    breakc_nz r1.w
    itof r1.w, r0.w
    mad r1.w, r1.x, r1.y, r1.w
    mad r2.w, -r1.w, l(0.125000), l(1.000000)
    mad r1.w, r1.w, l(0.250000), l(-1.000000)
    mad r2.w, r2.w, l(2.000000), l(-1.000000)
    mad r3.zw, r0.xxxy, r1.wwww, r3.xxxy
    mad r9.xy, r0.xyxx, r2.wwww, r3.xyxx
	
	//mad r3.z, r25.x, l(1.0), r3.z
	
    sample_l_indexable(texture2d)(float,float,float,float) r10.xyzw, r3.zwzz, t1.xyzw, s0, l(0.000000)
    lt r9.zw, l(0.000000, 0.000000, 0.000000, 0.000000), r10.xxxy
    lt r11.xy, r10.xyxx, l(0.000000, 0.000000, 0.000000, 0.000000)
    iadd r9.zw, -r9.zzzw, r11.xxxy
    itof r9.zw, r9.zzzw
    mul r10.xy, r10.xyxx, r10.xyxx
    mul r9.zw, r9.zzzw, r10.xxxy
    mul r9.zw, r9.zzzw, cb1[0].xxxx
    mad r10.xy, r10.zwzz, l(0.500000, 0.500000, 0.000000, 0.000000), l(0.500000, 0.500000, 0.000000, 0.000000)
    mul r10.xy, r10.xyxx, l(0.996108949, 0.00389105058, 0.000000, 0.000000)
    add r2.w, r10.y, r10.x
    mul r4.w, r2.w, l(256.000000)
    sample_l_indexable(texture2d)(float,float,float,float) r10.xyzw, r9.xyxx, t1.xyzw, s0, l(0.000000)
    lt r11.xy, l(0.000000, 0.000000, 0.000000, 0.000000), r10.xyxx
    lt r11.zw, r10.xxxy, l(0.000000, 0.000000, 0.000000, 0.000000)
    iadd r11.xy, -r11.xyxx, r11.zwzz
    itof r11.xy, r11.xyxx
    mul r10.xy, r10.xyxx, r10.xyxx
    mul r10.xy, r11.xyxx, r10.xyxx
    mul r10.xy, r10.xyxx, cb1[0].xxxx
    mad r10.zw, r10.zzzw, l(0.000000, 0.000000, 0.500000, 0.500000), l(0.000000, 0.000000, 0.500000, 0.500000)
    mul r10.zw, r10.zzzw, l(0.000000, 0.000000, 0.996108949, 0.00389105058)
    add r10.z, r10.w, r10.z
    mul r10.w, r10.z, l(256.000000)
    dp2 r9.z, r9.zwzz, r9.zwzz
    ishr r9.z, r9.z, l(1)
    iadd r9.z, r9.z, l(0x1fbd1df5)
    mul r4.y, r9.z, cb0[23].x
    dp2 r9.z, r10.xyxx, r10.xyxx
    ishr r9.z, r9.z, l(1)
    iadd r9.z, r9.z, l(0x1fbd1df5)
    mul r4.z, r9.z, cb0[23].x
    mad r2.w, r2.w, l(256.000000), -r1.z
    mad_sat r9.zw, r2.wwww, l(0.000000, 0.000000, 40.000000, -40.000000), l(0.000000, 0.000000, 0.500000, 0.500000)
    mad r11.xyzw, -r0.zzzz, |r1.wwww|, r4.xyxz
    add_sat r11.xyzw, r11.xyzw, l(1.000000, 1.000000, 1.000000, 1.000000)
    dp2 r1.w, r9.zwzz, r11.xyxx
    mad r2.w, r10.z, l(256.000000), -r1.z
    mad_sat r9.zw, r2.wwww, l(0.000000, 0.000000, 40.000000, -40.000000), l(0.000000, 0.000000, 0.500000, 0.500000)
    dp2 r2.w, r9.zwzz, r11.zwzz
    lt r4.w, r4.w, r10.w
    lt r4.y, r4.z, r4.y
    and r4.z, r4.y, r4.w
    movc r4.z, r4.z, r2.w, r1.w
    or r9.z, r4.y, r4.w
    not r4.yw, r4.yyyw
    and r9.w, r4.y, r4.w
    movc r9.zw, r9.zzzw, r2.wwww, r1.wwww
    add r4.z, r4.z, r9.w
    or r4.y, r4.y, r4.w
    movc r1.w, r4.y, r2.w, r1.w
    add r1.w, r1.w, r9.z
    sample_l_indexable(texture2d)(float,float,float,float) r6.xyz, r3.zwzz, t2.xyzw, s0, l(0.000000)
    mad r10.xyzw, r6.xyzw, r4.zzzz, r8.xyzw
    sample_l_indexable(texture2d)(float,float,float,float) r7.xyz, r9.xyxx, t2.xyzw, s0, l(0.000000)
    mad r8.xyzw, r7.xyzw, r1.wwww, r10.xyzw
    iadd r0.w, r0.w, l(1)
  endloop
  mul r5.xyzw, r8.xyzw, l(0.500000, 0.500000, 0.500000, 0.500000)
endif
mul r0.xyzw, r5.xyzw, l(0.125000, 0.125000, 0.125000, 0.125000)
mad r1.x, -r5.w, l(0.125000), l(1.000000)
mad o0.xyz, r1.xxxx, r2.xyzx, r0.xyzx
mov o0.w, r0.w
ret
// Approximately 144 instruction slots used
