// ---- Created with 3Dmigoto v1.3.16 on Fri Sep 02 18:53:58 2022

cbuffer perMaterialBuffer : register(b0)
{
  row_major float4x4 transform : packoffset(c0);
  float2 textureSize : packoffset(c4);
  float4 color : packoffset(c5);
  float4 size : packoffset(c6);
  row_major float4x4 invViewProjMatrix : packoffset(c7);
  row_major float4x4 viewProjMatrixPrev : packoffset(c11);
  float4 viewport : packoffset(c15);
  float4 clip_PS3MERGEABLE : packoffset(c16);
}

SamplerState texZ_s : register(s0);
Texture2D<float4> texZ_tex : register(t0);


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


void main(
  float4 v0 : SV_POSITION0,
  float2 v1 : TEXCOORD0,
  out float4 o0 : SV_Target0)
{
  float4 r0,r1,r2;
  uint4 bitmask, uiDest;
  float4 fDest;
  
  float4 stereo = StereoParams.Load(0);
  
  r0.xy = v0.xy / viewport.xy;
  r0.xy = float2(-0.5,-0.5) + r0.xy;
  r0.xy = float2(1,-1) * r0.xy;
  r1.xyzw = texZ_tex.Sample(texZ_s, v1.xy).xyzw;
  r1.y = r1.x * clip_PS3MERGEABLE.y + -clip_PS3MERGEABLE.z;
  r0.z = r1.x;
  r1.x = clip_PS3MERGEABLE.x / r1.y;
  r0.w = 1;
  r0.xyzw = r1.xxxx * r0.xyzw;
  r1.xyzw = invViewProjMatrix._m10_m11_m12_m13 * r0.yyyy;
  r1.xyzw = r0.xxxx * invViewProjMatrix._m00_m01_m02_m03 + r1.xyzw;
  r1.xyzw = r0.zzzz * invViewProjMatrix._m20_m21_m22_m23 + r1.xyzw;
  r1.xyzw = r0.wwww * invViewProjMatrix._m30_m31_m32_m33 + r1.xyzw;
  
  r0.x+=stereo.x*(r0.w-stereo.y);
  
  r0.xy = r0.xy / r0.ww;
  r2.xyz = viewProjMatrixPrev._m10_m11_m13 * r1.yyy;
  r2.xyz = r1.xxx * viewProjMatrixPrev._m00_m01_m03 + r2.xyz;
  r1.xyz = r1.zzz * viewProjMatrixPrev._m20_m21_m23 + r2.xyz;
  r1.xyz = r1.www * viewProjMatrixPrev._m30_m31_m33 + r1.xyz;
  
  r1.x+=stereo.x*(r1.z-stereo.y);
  
  r0.zw = r1.xy / r1.zz;
  r0.xy = r0.xy + -r0.zw;
  r0.z = -r0.y;
  r1.xy = cmp(float2(0,0) < r0.xz);
  r0.zw = cmp(r0.xz < float2(0,0));
  r0.xy = float2(0.125,-0.125) * r0.xy;
  r0.xy = float2(-0.00039999999,-0.00039999999) + abs(r0.xy);
  r0.xy = max(float2(0,0), r0.xy);
  r0.zw = (int2)-r1.xy + (int2)r0.zw;
  r0.zw = (int2)r0.zw;
  r0.xy = r0.zw * r0.xy;
  o0.xy = saturate(r0.xy * float2(16,16) + float2(0.498039216,0.498039216));
  o0.zw = float2(1,1);
  return;
}

/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
// Generated by Microsoft (R) HLSL Shader Compiler 6.3.9600.16384
//
//   using 3Dmigoto v1.3.16 on Fri Sep 02 18:53:58 2022
//
//
// Buffer Definitions:
//
// cbuffer perMaterialBuffer
// {
//
//   row_major float4x4 transform;      // Offset:    0 Size:    64 [unused]
//   float2 textureSize;                // Offset:   64 Size:     8 [unused]
//   float4 color;                      // Offset:   80 Size:    16 [unused]
//   float4 size;                       // Offset:   96 Size:    16 [unused]
//   row_major float4x4 invViewProjMatrix;// Offset:  112 Size:    64
//   row_major float4x4 viewProjMatrixPrev;// Offset:  176 Size:    64
//   float4 viewport;                   // Offset:  240 Size:    16
//   float4 clip_PS3MERGEABLE;          // Offset:  256 Size:    16
//
// }
//
//
// Resource Bindings:
//
// Name                                 Type  Format         Dim Slot Elements
// ------------------------------ ---------- ------- ----------- ---- --------
// texZ                              sampler      NA          NA    0        1
// texZ_tex                          texture  float4          2d    0        1
// perMaterialBuffer                 cbuffer      NA          NA    0        1
//
//
//
// Input signature:
//
// Name                 Index   Mask Register SysValue  Format   Used
// -------------------- ----- ------ -------- -------- ------- ------
// SV_POSITION              0   xyzw        0      POS   float   xy
// TEXCOORD                 0   xy          1     NONE   float   xy
//
//
// Output signature:
//
// Name                 Index   Mask Register SysValue  Format   Used
// -------------------- ----- ------ -------- -------- ------- ------
// SV_Target                0   xyzw        0   TARGET   float   xyzw
//
ps_4_0
dcl_constantbuffer cb0[17], immediateIndexed
dcl_sampler s0, mode_default
dcl_resource_texture2d (float,float,float,float) t0
dcl_input_ps_siv linear noperspective v0.xy, position
dcl_input_ps linear v1.xy
dcl_output o0.xyzw
dcl_temps 3
div r0.xy, v0.xyxx, cb0[15].xyxx
add r0.xy, r0.xyxx, l(-0.500000, -0.500000, 0.000000, 0.000000)
mul r0.xy, r0.xyxx, l(1.000000, -1.000000, 0.000000, 0.000000)
sample r1.xyzw, v1.xyxx, t0.xyzw, s0
mad r1.y, r1.x, cb0[16].y, -cb0[16].z
mov r0.z, r1.x
div r1.x, cb0[16].x, r1.y
mov r0.w, l(1.000000)
mul r0.xyzw, r0.xyzw, r1.xxxx
mul r1.xyzw, r0.yyyy, cb0[8].xyzw
mad r1.xyzw, r0.xxxx, cb0[7].xyzw, r1.xyzw
mad r1.xyzw, r0.zzzz, cb0[9].xyzw, r1.xyzw
mad r1.xyzw, r0.wwww, cb0[10].xyzw, r1.xyzw
div r0.xy, r0.xyxx, r0.wwww
mul r2.xyz, r1.yyyy, cb0[12].xywx
mad r2.xyz, r1.xxxx, cb0[11].xywx, r2.xyzx
mad r1.xyz, r1.zzzz, cb0[13].xywx, r2.xyzx
mad r1.xyz, r1.wwww, cb0[14].xywx, r1.xyzx
div r0.zw, r1.xxxy, r1.zzzz
add r0.xy, -r0.zwzz, r0.xyxx
mov r0.z, -r0.y
lt r1.xy, l(0.000000, 0.000000, 0.000000, 0.000000), r0.xzxx
lt r0.zw, r0.xxxz, l(0.000000, 0.000000, 0.000000, 0.000000)
mul r0.xy, r0.xyxx, l(0.125000, -0.125000, 0.000000, 0.000000)
add r0.xy, |r0.xyxx|, l(-0.000400, -0.000400, 0.000000, 0.000000)
max r0.xy, r0.xyxx, l(0.000000, 0.000000, 0.000000, 0.000000)
iadd r0.zw, -r1.xxxy, r0.zzzw
itof r0.zw, r0.zzzw
mul r0.xy, r0.xyxx, r0.zwzz
mad_sat o0.xy, r0.xyxx, l(16.000000, 16.000000, 0.000000, 0.000000), l(0.498039216, 0.498039216, 0.000000, 0.000000)
mov o0.zw, l(0,0,1.000000,1.000000)
ret
// Approximately 32 instruction slots used

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