//TAA. Temporal antialiasing. Part 2.
// ---- Created with 3Dmigoto v1.3.16 on Thu Jan 06 13:13:06 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);
}

Texture2D<float> ReadonlyDepth : register(t0);


// 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;
  uint4 bitmask, uiDest;
  float4 fDest;
  
  float4 stereo = StereoParams.Load(0);
  
  r0.xy = (int2)v0.xy;
  r0.zw = float2(0,0);
  r0.x = ReadonlyDepth.Load(r0.xyz).x;
  r0.yz = screenInverseSize.xy * v0.xy;
  r0.yz = r0.yz * float2(2,-2) + float2(-1,1);
  r0.yz = screenInverseSize.xy * float2(0.5,0.5) + r0.yz;
  
  r1.xyzw = viewProjInvMat._m10_m11_m12_m13 * r0.zzzz;
  r1.xyzw = r0.yyyy * viewProjInvMat._m00_m01_m02_m03 + r1.xyzw;
  r1.xyzw = r0.xxxx * viewProjInvMat._m20_m21_m22_m23 + r1.xyzw;
  r1.xyzw = viewProjInvMat._m30_m31_m32_m33 + r1.xyzw;
  
  r0.y+=stereo.x*(r1.w*stereo.y-1);
  
  r1.xyzw = viewProjInvMat._m10_m11_m12_m13 * r0.zzzz;
  r1.xyzw = r0.yyyy * viewProjInvMat._m00_m01_m02_m03 + r1.xyzw;
  r1.xyzw = r0.xxxx * viewProjInvMat._m20_m21_m22_m23 + r1.xyzw;
  r1.xyzw = viewProjInvMat._m30_m31_m32_m33 + r1.xyzw;
  r2.xyz = prevViewProjMat._m10_m11_m13 * r1.yyy;
  r2.xyz = r1.xxx * prevViewProjMat._m00_m01_m03 + r2.xyz;
  r1.xyz = r1.zzz * prevViewProjMat._m20_m21_m23 + r2.xyz;
  r1.xyz = r1.www * prevViewProjMat._m30_m31_m33 + r1.xyz;
  
  r1.x-=stereo.x*r1.z;
  
  r0.xw = r1.xy / r1.zz;
  o0.yz = r0.xw + -r0.yz;
  o0.xw = float2(1,1);
  return;
}

/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
// Generated by Microsoft (R) HLSL Shader Compiler 10.1
//
//   using 3Dmigoto v1.3.16 on Thu Jan 06 13:13:06 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
//   row_major float4x4 prevViewProjMat;// Offset:  288 Size:    64
//   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]
//
// }
//
//
// Resource Bindings:
//
// Name                                 Type  Format         Dim Slot Elements
// ------------------------------ ---------- ------- ----------- ---- --------
// ReadonlyDepth                     texture   float          2d    0        1
// SceneInfo                         cbuffer      NA          NA    0        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_resource_texture2d (float,float,float,float) t0
dcl_input_ps_siv linear noperspective v0.xy, position
dcl_output o0.xyzw
dcl_temps 3
ftoi r0.xy, v0.xyxx
mov r0.zw, l(0,0,0,0)
ld_indexable(texture2d)(float,float,float,float) r0.x, r0.xyzw, t0.xyzw
mul r0.yz, v0.xxyx, cb0[23].zzwz
mad r0.yz, r0.yyzy, l(0.000000, 2.000000, -2.000000, 0.000000), l(0.000000, -1.000000, 1.000000, 0.000000)
mad r0.yz, cb0[23].zzwz, l(0.000000, 0.500000, 0.500000, 0.000000), r0.yyzy
mul r1.xyzw, r0.zzzz, cb0[15].xyzw
mad r1.xyzw, r0.yyyy, cb0[14].xyzw, r1.xyzw
mad r1.xyzw, r0.xxxx, cb0[16].xyzw, r1.xyzw
add r1.xyzw, r1.xyzw, cb0[17].xyzw
mul r2.xyz, r1.yyyy, cb0[19].xywx
mad r2.xyz, r1.xxxx, cb0[18].xywx, r2.xyzx
mad r1.xyz, r1.zzzz, cb0[20].xywx, r2.xyzx
mad r1.xyz, r1.wwww, cb0[21].xywx, r1.xyzx
div r0.xw, r1.xxxy, r1.zzzz
add o0.yz, -r0.yyzy, r0.xxwx
mov o0.xw, l(1.000000,0,0,1.000000)
ret
// Approximately 18 instruction slots used

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