//manual correction - decal shadow - fix losti - working for convergence between 10 and 33
// ---- Created with 3Dmigoto v1.3.11 on Sat Jan 26 08:28:22 2019
cbuffer cb2 : register(b2)
{
  float4 cb2[21];
}

cbuffer cb1 : register(b1)
{
  float4 cb1[4];
}

cbuffer cb0 : register(b0)
{
  float4 cb0[5];
}




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


void main(
  float4 v0 : POSITION0,
  float3 v1 : NORMAL0,
  float4 v2 : TEXCOORD0,
  out float4 o0 : SV_POSITION0,
  out float4 o1 : TEXCOORD0,
  out float3 o2 : TEXCOORD1)
{
  float4 r0,r1,r50;
  uint4 bitmask, uiDest;
  float4 fDest;

float4 stereo = StereoParams.Load(0);
float SWITCH = IniParams.Load(int2(3,0)).x;
float separation = stereo.x, convergence = stereo.y, eye = stereo.z;
  float4 tex_filter = IniParams.Load(int2(2,0)).x;
  float4 tex_filterswitch = IniParams.Load(int2(20,0)).x;
  //float4 tex_filterCheck2 = IniParams.Load(int2(21,0)).x;
  float4 tex_filter2 = IniParams.Load(int2(50,0)).x;
  float4 tex_filter3 = IniParams.Load(int2(51,0)).x;


  r0.xyzw = cb1[1].xyzw * v0.yyyy;
  r0.xyzw = cb1[0].xyzw * v0.xxxx + r0.xyzw;
  r0.xyzw = cb1[2].xyzw * v0.zzzz + r0.xyzw;
  r1.xyzw = cb1[3].xyzw + r0.xyzw;
  r0.xyz = cb1[3].xyz * v0.www + r0.xyz;
  o2.xyz = -cb0[4].xyz + r0.xyz;
  r0.xyzw = cb2[18].xyzw * r1.yyyy;
  r0.xyzw = cb2[17].xyzw * r1.xxxx + r0.xyzw;
  r0.xyzw = cb2[19].xyzw * r1.zzzz + r0.xyzw;
  o0.xyzw = cb2[20].xyzw * r1.wwww + r0.xyzw;
 

//manual fix in dependency of convergence presets -- LOSTI --- HALO FIX and decal shadow things
//remove halo --- texture dependend hash b6e8cf9b -- LOSTI
if(tex_filter.x==2)
{
o0.x -= separation * (o0.w - convergence);
}
/////////////////skipped not needed anymore
//else if(tex_filterCheck2.x==1.0)
//{
//o0.x -= separation * (o0.w - convergence);
//}

//remove halo and fix decal / ambient shadow -- LOSTI --- scale corretion in dependency of the Y position of the screen
else if(tex_filter.x==0)
{

//calculation for the 1st correction value
r50.x=(-0.0192*(convergence*convergence))+(-8.1881*convergence)+808.82;

//calculation for the 2nd correction value
r50.y=(-0.0000115536*(r50.x*r50.x*r50.x))+(0.0203298669*(r50.x*r50.x))+(-10.6209994884*r50.x)+2071.4742042645;

//calculation for the 1st halo fix value
r50.z=(-0.0000014999*(convergence*convergence*convergence*convergence))+(0.0001151569*(convergence*convergence*convergence))+(-0.0031005477*(convergence*convergence))+(0.0231113459*convergence)+0.3881769350;

//calculation for the 2nd halo fix value
r50.w=(-0.0000001329*(convergence*convergence*convergence*convergence*convergence))+(0.0000162559*(convergence*convergence*convergence*convergence))+(-0.0007237979*(convergence*convergence*convergence))+(0.0143505380*(convergence*convergence))+(-0.1354406842*convergence)+0.8069801289;

if(convergence>=36.00)
{
if(o0.y<-100.0)
{
//depth for cover shadow/decal shadow --- convergence 36.00 - Part 1 --- LOSTI 
o0.x -= separation * (o0.w - convergence);
r50.x=490;
o0.x -= separation * (o0.w - r50.x);
//remove FUCKING HALO !!!! damn its working --- LOSTI --- convergence 36.00 - Part 1
v2.x += (separation*0.055)*v2.w;
}

else
{
//depth for cover shadow/decal shadow --- convergence 36.00 - Part 2 --- LOSTI 
o0.x -= separation * (o0.w - convergence);
r50.x=390;
o0.x -= separation * (o0.w - r50.x);
//remove FUCKING HALO !!!! damn its working --- LOSTI --- convergence 36.00 Part 2
v2.x += (separation*0.03)*v2.w;
}
}

if(convergence<36.0)
{
if(convergence>=8.58 && convergence<=33.00)
{
if(o0.y<-100.0)
{
//depth for cover shadow/decal shadow - Part 1 --- LOSTI 
o0.x -= separation * (o0.w - convergence);
o0.x -= separation * (o0.w - r50.x);
//remove FUCKING HALO !!!! damn its working - Part 2 --- LOSTI 
v2.x += (separation*r50.z)*v2.w;
}

else
{
//depth for cover shadow/decal shadow - Part 3 --- LOSTI  
o0.x -= separation * (o0.w - convergence);
o0.x -= separation * (o0.w - r50.y);
//remove FUCKING HALO !!!! damn its working - Part 4 --- LOSTI 
v2.x += (separation*r50.w)*v2.w;
}
}
else if(convergence<8.58)
{
if(o0.y<-100.0)
{
//depth for cover shadow/decal shadow - Part 1 --- LOSTI 
o0.x -= separation * (o0.w - convergence);
o0.x -= separation * (o0.w - r50.x*1.05);
//remove FUCKING HALO !!!! damn its working - Part 2 --- LOSTI 
if(convergence<8.58 && convergence>6.50)
{
v2.x += (separation*r50.z)*v2.w;
}
else if(convergence<6.50)
{
v2.x += (separation*0.474)*v2.w;
}
}

else
{
//depth for cover shadow/decal shadow - Part 3 --- LOSTI  
o0.x -= separation * (o0.w - convergence);
o0.x -= separation * (o0.w - r50.y);
//remove FUCKING HALO !!!! damn its working - Part 4 --- LOSTI 

if(convergence<8.58 && convergence>7.20)
{
v2.x += (separation*r50.w)*v2.w;
}

if(convergence<=7.20)
{
v2.x += (separation*0.347)*v2.w;
}
}
}

else if(convergence>33.0)
{
if(o0.y<-100.0)
{
//depth for cover shadow/decal shadow - Part 1 --- LOSTI 
o0.x -= separation * (o0.w - convergence);
o0.x -= separation * (o0.w - r50.x);
//remove FUCKING HALO !!!! damn its working - Part 2 --- LOSTI 
v2.x += (separation*0.16)*v2.w;
}

else
{
//depth for cover shadow/decal shadow - Part 3 --- LOSTI  
o0.x -= separation * (o0.w - convergence);
o0.x -= separation * (o0.w - r50.y);
//remove FUCKING HALO !!!! damn its working - Part 4 --- LOSTI 
if(convergence<=43.0)
{
v2.x += (separation*0.013)*v2.w;
}
else if(convergence>43.0)
{
v2.x += (separation*0.008)*v2.w;
}
}
}
}
}


if(SWITCH.x==1.0)
{o0=0;}


//v2 fixed in the upper part dependend on convergence -- LOSTI
  o1.xy = v2.xy;
  


  return;
}

/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
// Generated by Microsoft (R) D3D Shader Disassembler
//
//   using 3Dmigoto v1.3.11 on Sat Jan 26 08:28:22 2019
//
//
// Input signature:
//
// Name                 Index   Mask Register SysValue  Format   Used
// -------------------- ----- ------ -------- -------- ------- ------
// POSITION                 0   xyzw        0     NONE   float   xyzw
// NORMAL                   0   xyz         1     NONE   float
// TEXCOORD                 0   xyzw        2     NONE   float   xy
//
//
// Output signature:
//
// Name                 Index   Mask Register SysValue  Format   Used
// -------------------- ----- ------ -------- -------- ------- ------
// SV_POSITION              0   xyzw        0      POS   float   xyzw
// TEXCOORD                 0   xy          1     NONE   float   xy
// TEXCOORD                 1   xyz         2     NONE   float   xyz
//
vs_4_0
dcl_constantbuffer cb0[5], immediateIndexed
dcl_constantbuffer cb1[4], immediateIndexed
dcl_constantbuffer cb2[21], immediateIndexed
dcl_input v0.xyzw
dcl_input v2.xy
dcl_output_siv o0.xyzw, position
dcl_output o1.xy
dcl_output o2.xyz
dcl_temps 2
mul r0.xyzw, v0.yyyy, cb1[1].xyzw
mad r0.xyzw, cb1[0].xyzw, v0.xxxx, r0.xyzw
mad r0.xyzw, cb1[2].xyzw, v0.zzzz, r0.xyzw
add r1.xyzw, r0.xyzw, cb1[3].xyzw
mad r0.xyz, cb1[3].xyzx, v0.wwww, r0.xyzx
add o2.xyz, r0.xyzx, -cb0[4].xyzx
mul r0.xyzw, r1.yyyy, cb2[18].xyzw
mad r0.xyzw, cb2[17].xyzw, r1.xxxx, r0.xyzw
mad r0.xyzw, cb2[19].xyzw, r1.zzzz, r0.xyzw
mad o0.xyzw, cb2[20].xyzw, r1.wwww, r0.xyzw
mov o1.xy, v2.xyxx
ret
// Approximately 0 instruction slots used

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