//TAA. Temporal anti-aliasing.
// ---- Created with 3Dmigoto v1.3.16 on Thu Jan 06 16:37:03 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 Tonemap : register(b1)
{
  float exposureAdjustment : packoffset(c0);
  float tonemapRange : packoffset(c0.y);
  float sharpness : packoffset(c0.z);
  float preTonemapRange : packoffset(c0.w);
  int useAutoExposure : packoffset(c1);
  float echoBlend : packoffset(c1.y);
  float AABlend : packoffset(c1.z);
  float AASubPixel : packoffset(c1.w);
  float ResponsiveAARate : packoffset(c2);
}

SamplerState PointClamp_s : register(s0);
SamplerState BilinearClamp_s : register(s1);
Texture2D<float> EffectMaskTex : register(t0);
Texture2D<float> ReadonlyDepth : register(t1);
Texture2D<float4> HDRImage : register(t2);
Texture2D<float4> PrevHDRImage : register(t3);
Texture2D<float4> Velocity : register(t4);


// 3Dmigoto declarations
#define cmp -
Texture1D<float4> IniParams : register(t120);
Texture2D<float4> StereoParams : register(t125);


void main(
  float4 v0 : SV_Position0,
  float4 v1 : Kerare0,
  float v2 : Exposure0,
  out float4 o0 : SV_Target0)
{
  float4 r0,r1,r2,r3,r4,r5,r6,r7,r8,r9;
  uint4 bitmask, uiDest;
  float4 fDest;
  
  float4 stereo = StereoParams.Load(0);
  
  r0.xy = screenInverseSize.xy * v0.xy;
  r0.zw = screenInverseSize.xy * projElement[0].zw;
  r0.zw = -r0.zw * float2(0.5,0.5) + r0.xy;
  r1.xyz = HDRImage.SampleLevel(PointClamp_s, r0.zw, 0).xyz;
  r1.xyz = v2.xxx * r1.xyz;
  r0.z = max(r1.x, r1.y);
  r0.z = max(r0.z, r1.z);
  r0.w = (int)r0.z & 0x7f800000;
  r0.w = cmp((int)r0.w == 0x7f800000);
  if (r0.w != 0) {
    r2.xyz = float3(1,1,1);
  }
  if (r0.w == 0) {
    r3.xy = (uint2)v0.xy;
    r4.xyzw = (int4)r3.xyxy + int4(-1,0,0,-1);
    r5.xy = r4.zw;
    r5.zw = float2(0,0);
    r0.w = ReadonlyDepth.Load(r5.xyz).x;
    r0.w = 1 + -r0.w;
    r4.zw = float2(0,0);
    r1.w = ReadonlyDepth.Load(r4.xyz).x;
    r1.w = 1 + -r1.w;
    r3.zw = float2(0,0);
    r2.w = ReadonlyDepth.Load(r3.xyw).x;
    r2.w = 1 + -r2.w;
    r4.xyzw = (int4)r3.xyxy + int4(0,1,1,0);
    r5.xy = r4.zw;
    r5.zw = float2(0,0);
    r5.x = ReadonlyDepth.Load(r5.xyz).x;
    r5.x = 1 + -r5.x;
    r4.zw = float2(0,0);
    r4.x = ReadonlyDepth.Load(r4.xyz).x;
    r4.x = 1 + -r4.x;
    r0.w = (int)r0.w & -16;
    r0.w = (int)r0.w + 4;
    bitmask.w = ((~(-1 << 4)) << 0) & 0xffffffff;  r1.w = (((uint)1 << 0) & bitmask.w) | ((uint)r1.w & ~bitmask.w);
    r2.w = (int)r2.w & -16;
    r2.w = (int)r2.w + 5;
    r4.y = (int)r5.x & -16;
    r4.x = (int)r4.x & -16;
    r4.xy = (int2)r4.xy + int2(6,9);
    r0.w = min(r1.w, r0.w);
    r0.w = min(r0.w, r2.w);
    r0.w = min(r0.w, r4.y);
    r0.w = min(r0.w, r4.x);
    r1.w = (int)r0.w & 3;
    if (2 == 0) r0.w = 0; else if (2+2 < 32) {     r0.w = (uint)r0.w << (32-(2 + 2)); r0.w = (uint)r0.w >> (32-2);    } else r0.w = (uint)r0.w >> 2;
    r0.w = (int)r0.w + (int)r3.x;
    r4.x = (int)r0.w + -1;
    r0.w = (int)r1.w + (int)r3.y;
    r4.y = (int)r0.w + -1;
    r4.zw = float2(0,0);
    r4.xy = Velocity.Load(r4.xyz).yz;
	
	r4.x+=stereo.x;
	
    r0.xy = r4.xy * float2(0.5,-0.5) + r0.xy;
    r0.xyw = PrevHDRImage.SampleLevel(BilinearClamp_s, r0.xy, 0).xyz;
    r0.xyw = v2.xxx * r0.xyw;
    r0.z = r0.z * preTonemapRange + 1;
    r1.xyz = r1.xyz / r0.zzz;
    r0.z = max(r0.x, r0.y);
    r0.z = max(r0.z, r0.w);
    r0.z = r0.z * preTonemapRange + 1;
    r0.xyz = r0.xyw / r0.zzz;
    r4.xw = float2(0,0);
    r4.yz = -screenInverseSize.yx;
    r4.xyzw = v0.xyxy * screenInverseSize.xyxy + r4.xyzw;
    r5.xyz = HDRImage.SampleLevel(BilinearClamp_s, r4.xy, 0).xyz;
    r4.xyz = HDRImage.SampleLevel(BilinearClamp_s, r4.zw, 0).xyz;
    r6.xw = screenInverseSize.xy;
    r6.yz = float2(0,0);
    r6.xyzw = v0.xyxy * screenInverseSize.xyxy + r6.xyzw;
    r7.xyz = HDRImage.SampleLevel(BilinearClamp_s, r6.xy, 0).xyz;
    r6.xyz = HDRImage.SampleLevel(BilinearClamp_s, r6.zw, 0).xyz;
    r5.xyz = v2.xxx * r5.xyz;
    r4.xyz = v2.xxx * r4.xyz;
    r7.xyz = v2.xxx * r7.xyz;
    r6.xyz = v2.xxx * r6.xyz;
    r0.w = max(r5.x, r5.y);
    r0.w = max(r0.w, r5.z);
    r0.w = r0.w * preTonemapRange + 1;
    r5.xyz = r5.xyz / r0.www;
    r0.w = max(r4.x, r4.y);
    r0.w = max(r0.w, r4.z);
    r0.w = r0.w * preTonemapRange + 1;
    r4.xyz = r4.xyz / r0.www;
    r0.w = max(r7.x, r7.y);
    r0.w = max(r0.w, r7.z);
    r0.w = r0.w * preTonemapRange + 1;
    r7.xyz = r7.xyz / r0.www;
    r0.w = max(r6.x, r6.y);
    r0.w = max(r0.w, r6.z);
    r0.w = r0.w * preTonemapRange + 1;
    r6.xyz = r6.xyz / r0.www;
    r8.xyz = max(r5.xyz, r1.xyz);
    r9.xyz = max(r7.xyz, r4.xyz);
    r9.xyz = max(r9.xyz, r6.xyz);
    r8.xyz = max(r9.xyz, r8.xyz);
    r5.xyz = min(r5.xyz, r1.xyz);
    r4.xyz = min(r7.xyz, r4.xyz);
    r4.xyz = min(r4.xyz, r6.xyz);
    r4.xyz = min(r5.xyz, r4.xyz);
    r5.xyz = r8.xyz + r4.xyz;
    r4.xyz = r8.xyz + -r4.xyz;
    r4.xyz = float3(0.5,0.5,0.5) * r4.xyz;
    r6.xyz = -r5.xyz * float3(0.5,0.5,0.5) + r0.xyz;
    r4.xyz = r6.xyz / r4.xyz;
    r0.w = max(abs(r4.x), abs(r4.y));
    r0.w = max(r0.w, abs(r4.z));
    r1.w = cmp(1 < r0.w);
    if (r1.w != 0) {
      r4.xyz = r6.xyz / r0.www;
      r0.xyz = r5.xyz * float3(0.5,0.5,0.5) + r4.xyz;
    }
    r0.w = EffectMaskTex.Load(r3.xyz).x;
    r0.w = -r0.w * ResponsiveAARate + AABlend;
    r0.w = max(0, r0.w);
    r0.xyz = r0.xyz + -r1.xyz;
    r2.xyz = r0.www * r0.xyz + r1.xyz;
  }
  r0.x = max(r2.x, r2.y);
  r0.x = max(r0.x, r2.z);
  r0.x = -r0.x * preTonemapRange + 1;
  r0.x = max(9.99999975e-005, r0.x);
  r0.xyz = r2.xyz / r0.xxx;
  r0.xyz = r0.xyz / v2.xxx;
  o0.xyz = max(float3(0,0,0), r0.xyz);
  o0.w = 1;
  return;
}

/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
// Generated by Microsoft (R) HLSL Shader Compiler 10.1
//
//   using 3Dmigoto v1.3.16 on Thu Jan 06 16:37:03 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
//   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 [unused]
//   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 Tonemap
// {
//
//   float exposureAdjustment;          // Offset:    0 Size:     4 [unused]
//   float tonemapRange;                // Offset:    4 Size:     4 [unused]
//   float sharpness;                   // Offset:    8 Size:     4 [unused]
//   float preTonemapRange;             // Offset:   12 Size:     4
//   int useAutoExposure;               // Offset:   16 Size:     4 [unused]
//   float echoBlend;                   // Offset:   20 Size:     4 [unused]
//   float AABlend;                     // Offset:   24 Size:     4
//   float AASubPixel;                  // Offset:   28 Size:     4 [unused]
//   float ResponsiveAARate;            // Offset:   32 Size:     4
//
// }
//
//
// Resource Bindings:
//
// Name                                 Type  Format         Dim Slot Elements
// ------------------------------ ---------- ------- ----------- ---- --------
// PointClamp                        sampler      NA          NA    0        1
// BilinearClamp                     sampler      NA          NA    1        1
// EffectMaskTex                     texture   float          2d    0        1
// ReadonlyDepth                     texture   float          2d    1        1
// HDRImage                          texture  float4          2d    2        1
// PrevHDRImage                      texture  float4          2d    3        1
// Velocity                          texture  float4          2d    4        1
// SceneInfo                         cbuffer      NA          NA    0        1
// Tonemap                           cbuffer      NA          NA    1        1
//
//
//
// Input signature:
//
// Name                 Index   Mask Register SysValue  Format   Used
// -------------------- ----- ------ -------- -------- ------- ------
// SV_Position              0   xyzw        0      POS   float   xy
// Kerare                   0   xyzw        1     NONE   float
// Exposure                 0   x           2     NONE   float   x
//
//
// 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[3], immediateIndexed
dcl_sampler s0, mode_default
dcl_sampler s1, 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_texture2d (float,float,float,float) t4
dcl_input_ps_siv linear noperspective v0.xy, position
dcl_input_ps linear v2.x
dcl_output o0.xyzw
dcl_temps 10
mul r0.xy, v0.xyxx, cb0[23].zwzz
mul r0.zw, cb0[10].zzzw, cb0[23].zzzw
mad r0.zw, -r0.zzzw, l(0.000000, 0.000000, 0.500000, 0.500000), r0.xxxy
sample_l_indexable(texture2d)(float,float,float,float) r1.xyz, r0.zwzz, t2.xyzw, s0, l(0.000000)
mul r1.xyz, r1.xyzx, v2.xxxx
max r0.z, r1.y, r1.x
max r0.z, r1.z, r0.z
and r0.w, r0.z, l(0x7f800000)
ieq r0.w, r0.w, l(0x7f800000)
if_nz r0.w
  mov r2.xyz, l(1.000000,1.000000,1.000000,0)
endif
if_z r0.w
  ftou r3.xy, v0.xyxx
  iadd r4.xyzw, r3.xyxy, l(-1, 0, 0, -1)
  mov r5.xy, r4.zwzz
  mov r5.zw, l(0,0,0,0)
  ld_indexable(texture2d)(float,float,float,float) r0.w, r5.xyzw, t1.yzwx
  add r0.w, -r0.w, l(1.000000)
  mov r4.zw, l(0,0,0,0)
  ld_indexable(texture2d)(float,float,float,float) r1.w, r4.xyzw, t1.yzwx
  add r1.w, -r1.w, l(1.000000)
  mov r3.zw, l(0,0,0,0)
  ld_indexable(texture2d)(float,float,float,float) r2.w, r3.xyww, t1.yzwx
  add r2.w, -r2.w, l(1.000000)
  iadd r4.xyzw, r3.xyxy, l(0, 1, 1, 0)
  mov r5.xy, r4.zwzz
  mov r5.zw, l(0,0,0,0)
  ld_indexable(texture2d)(float,float,float,float) r5.x, r5.xyzw, t1.xyzw
  add r5.x, -r5.x, l(1.000000)
  mov r4.zw, l(0,0,0,0)
  ld_indexable(texture2d)(float,float,float,float) r4.x, r4.xyzw, t1.xyzw
  add r4.x, -r4.x, l(1.000000)
  and r0.w, r0.w, l(-16)
  iadd r0.w, r0.w, l(4)
  bfi r1.w, l(4), l(0), l(1), r1.w
  and r2.w, r2.w, l(-16)
  iadd r2.w, r2.w, l(5)
  and r4.y, r5.x, l(-16)
  and r4.x, r4.x, l(-16)
  iadd r4.xy, r4.xyxx, l(6, 9, 0, 0)
  min r0.w, r0.w, r1.w
  min r0.w, r2.w, r0.w
  min r0.w, r4.y, r0.w
  min r0.w, r4.x, r0.w
  and r1.w, r0.w, l(3)
  ubfe r0.w, l(2), l(2), r0.w
  iadd r0.w, r0.w, r3.x
  iadd r4.x, r0.w, l(-1)
  iadd r0.w, r1.w, r3.y
  iadd r4.y, r0.w, l(-1)
  mov r4.zw, l(0,0,0,0)
  ld_indexable(texture2d)(float,float,float,float) r4.xy, r4.xyzw, t4.yzxw
  mad r0.xy, r4.xyxx, l(0.500000, -0.500000, 0.000000, 0.000000), r0.xyxx
  sample_l_indexable(texture2d)(float,float,float,float) r0.xyw, r0.xyxx, t3.xywz, s1, l(0.000000)
  mul r0.xyw, r0.xyxw, v2.xxxx
  mad r0.z, r0.z, cb1[0].w, l(1.000000)
  div r1.xyz, r1.xyzx, r0.zzzz
  max r0.z, r0.y, r0.x
  max r0.z, r0.w, r0.z
  mad r0.z, r0.z, cb1[0].w, l(1.000000)
  div r0.xyz, r0.xywx, r0.zzzz
  mov r4.xw, l(0,0,0,0)
  mov r4.yz, -cb0[23].wwzw
  mad r4.xyzw, v0.xyxy, cb0[23].zwzw, r4.xyzw
  sample_l_indexable(texture2d)(float,float,float,float) r5.xyz, r4.xyxx, t2.xyzw, s1, l(0.000000)
  sample_l_indexable(texture2d)(float,float,float,float) r4.xyz, r4.zwzz, t2.xyzw, s1, l(0.000000)
  mov r6.xw, cb0[23].zzzw
  mov r6.yz, l(0,0,0,0)
  mad r6.xyzw, v0.xyxy, cb0[23].zwzw, r6.xyzw
  sample_l_indexable(texture2d)(float,float,float,float) r7.xyz, r6.xyxx, t2.xyzw, s1, l(0.000000)
  sample_l_indexable(texture2d)(float,float,float,float) r6.xyz, r6.zwzz, t2.xyzw, s1, l(0.000000)
  mul r5.xyz, r5.xyzx, v2.xxxx
  mul r4.xyz, r4.xyzx, v2.xxxx
  mul r7.xyz, r7.xyzx, v2.xxxx
  mul r6.xyz, r6.xyzx, v2.xxxx
  max r0.w, r5.y, r5.x
  max r0.w, r5.z, r0.w
  mad r0.w, r0.w, cb1[0].w, l(1.000000)
  div r5.xyz, r5.xyzx, r0.wwww
  max r0.w, r4.y, r4.x
  max r0.w, r4.z, r0.w
  mad r0.w, r0.w, cb1[0].w, l(1.000000)
  div r4.xyz, r4.xyzx, r0.wwww
  max r0.w, r7.y, r7.x
  max r0.w, r7.z, r0.w
  mad r0.w, r0.w, cb1[0].w, l(1.000000)
  div r7.xyz, r7.xyzx, r0.wwww
  max r0.w, r6.y, r6.x
  max r0.w, r6.z, r0.w
  mad r0.w, r0.w, cb1[0].w, l(1.000000)
  div r6.xyz, r6.xyzx, r0.wwww
  max r8.xyz, r1.xyzx, r5.xyzx
  max r9.xyz, r4.xyzx, r7.xyzx
  max r9.xyz, r6.xyzx, r9.xyzx
  max r8.xyz, r8.xyzx, r9.xyzx
  min r5.xyz, r1.xyzx, r5.xyzx
  min r4.xyz, r4.xyzx, r7.xyzx
  min r4.xyz, r6.xyzx, r4.xyzx
  min r4.xyz, r4.xyzx, r5.xyzx
  add r5.xyz, r4.xyzx, r8.xyzx
  add r4.xyz, -r4.xyzx, r8.xyzx
  mul r4.xyz, r4.xyzx, l(0.500000, 0.500000, 0.500000, 0.000000)
  mad r6.xyz, -r5.xyzx, l(0.500000, 0.500000, 0.500000, 0.000000), r0.xyzx
  div r4.xyz, r6.xyzx, r4.xyzx
  max r0.w, |r4.y|, |r4.x|
  max r0.w, |r4.z|, r0.w
  lt r1.w, l(1.000000), r0.w
  if_nz r1.w
    div r4.xyz, r6.xyzx, r0.wwww
    mad r0.xyz, r5.xyzx, l(0.500000, 0.500000, 0.500000, 0.000000), r4.xyzx
  endif
  ld_indexable(texture2d)(float,float,float,float) r0.w, r3.xyzw, t0.yzwx
  mad r0.w, -r0.w, cb1[2].x, cb1[1].z
  max r0.w, r0.w, l(0.000000)
  add r0.xyz, -r1.xyzx, r0.xyzx
  mad r2.xyz, r0.wwww, r0.xyzx, r1.xyzx
endif
max r0.x, r2.y, r2.x
max r0.x, r2.z, r0.x
mad r0.x, -r0.x, cb1[0].w, l(1.000000)
max r0.x, r0.x, l(0.000100)
div r0.xyz, r2.xyzx, r0.xxxx
div r0.xyz, r0.xyzx, v2.xxxx
max o0.xyz, r0.xyzx, l(0.000000, 0.000000, 0.000000, 0.000000)
mov o0.w, l(1.000000)
ret
// Approximately 127 instruction slots used

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
