//HUD.
// ---- Created with 3Dmigoto v1.3.11 on Sun Sep 02 19:50:53 2018

cbuffer ProjParameters : register(b2)
{
  row_major float4x4 _mxView : packoffset(c0);
  row_major float4x4 _mxProj : packoffset(c4);
}



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


void main(
  float4 v0 : COLOR0,
  float2 v1 : TEXCOORD0,
  float4 v2 : SV_Position0,
  out float4 o0 : COLOR0,
  out float2 o1 : TEXCOORD0,
  out float4 o2 : SV_Position0)
{
  float4 r0,r10;
  uint4 bitmask, uiDest;
  float4 fDest;

  float4 stereo = StereoParams.Load(0);
  float4 res = StereoParams.Load(int3(2,0,0));
  float4 iniparams = IniParams.Load(0);
  float4 iniparams1 = IniParams.Load(int2(1,0));
  float4 iniparams2 = IniParams.Load(int2(2,0));
  float4 iniparams3 = IniParams.Load(int2(3,0));
  float4 iniparams5 = IniParams.Load(int2(5,0));
  float4 iniparams7 = IniParams.Load(int2(7,0));
  
  if (res.x==0 && res.y==0)
  {
	res.x=iniparams7.x;
	res.y=iniparams7.y;
  }
  
  o0.xyzw = v0.xyzw;
  o1.xy = v1.xy;
  r0.xyzw = _mxProj._m10_m11_m12_m13 * v2.yyyy;
  r0.xyzw = v2.xxxx * _mxProj._m00_m01_m02_m03 + r0.xyzw;
  r0.xyzw = v2.zzzz * _mxProj._m20_m21_m22_m23 + r0.xyzw;
  o2.xyzw = v2.wwww * _mxProj._m30_m31_m32_m33 + r0.xyzw;
  
  float ar = (4.0/3.0)/(res.x/res.y);
  if (iniparams.w!=0)
  {
	ar = iniparams.w;
  }
  
  float2 mult;
  mult.x=iniparams.z*ar;
  mult.y=iniparams.z;
  if (iniparams3.w==20)
  {
	//Cutscenes that are 320x182. No zoom for them either.
	mult.x=ar/0.758333333;
	mult.y=1;
  }
  if (iniparams3.w==21)
  {
	//Cutscenes that are 320x192. No zoom for them either.
	mult.x=ar/0.80;
	mult.y=1;
  }
  if (iniparams3.w==22)
  {
	//Cutscenes that are 1352x1080. No zoom for them either.
	mult.x=ar/1.065088757;
	mult.y=1;
  }
  if (iniparams3.w==23)
  {
	//Cutscenes that are 320x186. No zoom for them either.
	mult.x=ar/0.775;
	mult.y=1;
  }
  else if (iniparams3.w==90 && ((v0.x==0 && v0.y==0 && v0.z==0) || (v0.x==1 && v0.y==1 && v0.z==1)))
  {
	mult.x=1;
	mult.y=1;
  }
  else if (iniparams1.x==1 && iniparams3.w!=1 && iniparams3.w!=4 && iniparams3.w!=5 && iniparams3.w!=6 && iniparams3.w!=0 && iniparams3.w!=90)
  {
    mult.x=ar;
	mult.y=1;
  }
  else if (iniparams1.x==2 && iniparams3.w!=1 && iniparams3.w!=4 && iniparams3.w!=5 && iniparams3.w!=6 && iniparams3.w!=0 && iniparams3.w!=90)
  {
    mult.x=1;
	mult.y=1;
  }
  else
  {
    o2.x+=iniparams5.x*o2.w*0.25;
    o2.y+=iniparams5.y*o2.w*0.25;
  }
  o2.x=o2.x*mult.x;
  o2.y=o2.y*mult.y;
  if (iniparams3.w==8 || (iniparams3.w==90 && v0.x==0 && v0.y==0 && v0.z==0))
  {
	//No extra depth applied.
  }
  if (iniparams3.w==20 || iniparams3.w==21 || iniparams3.w==22 || iniparams3.w==23)
  {
	o2.x+=stereo.x*iniparams.x*o2.w;
  }
  else if (iniparams3.w==90 && ((v0.x!=0 || v0.y!=0 || v0.z!=0) && (v0.x!=1 || v0.y!=1 || v0.z!=1)) && ((((o2.z*o2.w)<0.01 && (o2.z*o2.w)>-0.01) || ((o2.z*o2.w)<1.01 && (o2.z*o2.w)>0.99) || ((o2.z*o2.w)<-0.99 && (o2.z*o2.w)>-1.01)) || (o2.z<50 && o2.z>-50)))
  {
	o2.x=o2.x*iniparams.y;
    o2.x+=stereo.x*iniparams.x*o2.w;
  }
  else if (iniparams3.w==1)
  {
	//o2.x+=stereo.x*stereo.y;
	o2.x+=stereo.x;
  }
  else if (iniparams3.w==20)
  {
	o2.x=o2.x*iniparams.y;
    o2.x+=stereo.x*iniparams.x*o2.w;
  }
  else if (iniparams3.w==4)
  {
    r10.x=o0.z*10-9;
	o2.x+=stereo.x;
	o2.x-=stereo.x*stereo.y*r10.x*0.0016667;
  }
  else if (iniparams3.w==5)
  {
    r10.x=o0.z*10-9;
	o2.x+=stereo.x;
	o2.x-=stereo.x*stereo.y*r10.x*0.000225;
  }
  else if (iniparams3.w==6)
  {
    r10.x=o0.z*10-9;
	o2.x+=stereo.x;
	o2.x-=stereo.x*stereo.y*r10.x*0.000625;
  }
  else if (iniparams3.w==7)
  {
    r10.x=o0.z*10-9;
	o2.x+=stereo.x;
	o2.x-=stereo.x*stereo.y*r10.x*0.000125;
  }
  else if (iniparams3.w==2)
  {
    //Doubt.
	if ((o2.z*o2.w)>400 || (o2.z*o2.w)>0 && (o2.z*o2.w)<60)
	{
	  //o2.x-=stereo.x*(o2.w-stereo.y);
	}
	if (o2.z>-1 && o2.z<25 && o2.w>=10 && o2.w<22 && iniparams2.w==1)
	{
	  o2.x-=stereo.x*(o2.w-stereo.y);
	}
	//o2.x+=stereo.x;
	o2.x=o2.x*iniparams.y;
    o2.x+=stereo.x*iniparams.x*o2.w;
  }
  else if ((iniparams3.w==3 || iniparams3.w==33) && ((((o2.z*o2.w)<0.01 && (o2.z*o2.w)>-0.01) || ((o2.z*o2.w)<1.01 && (o2.z*o2.w)>0.99) || ((o2.z*o2.w)<-0.99 && (o2.z*o2.w)>-1.01)) || (o2.z<50 && o2.z>-50)))
  {
	o2.x=o2.x*iniparams.y;
    o2.x+=stereo.x*iniparams.x*o2.w;
  }
  else if (((o2.z*o2.w)<0.01 && (o2.z*o2.w)>-0.01) || ((o2.z*o2.w)<1.01 && (o2.z*o2.w)>0.99) || ((o2.z*o2.w)<-0.99 && (o2.z*o2.w)>-1.01))
  {
	//o2.x=o2.x*iniparams.y;
    //o2.x+=stereo.x*iniparams.x*o2.w;
  }
  return;
}

/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
// Generated by Microsoft (R) HLSL Shader Compiler 6.3.9600.16384
//
//   using 3Dmigoto v1.3.11 on Sun Sep 02 19:50:53 2018
//
//
// Buffer Definitions:
//
// cbuffer ProjParameters
// {
//
//   row_major float4x4 _mxView;        // Offset:    0 Size:    64 [unused]
//   row_major float4x4 _mxProj;        // Offset:   64 Size:    64
//
// }
//
//
// Resource Bindings:
//
// Name                                 Type  Format         Dim Slot Elements
// ------------------------------ ---------- ------- ----------- ---- --------
// ProjParameters                    cbuffer      NA          NA    2        1
//
//
//
// Input signature:
//
// Name                 Index   Mask Register SysValue  Format   Used
// -------------------- ----- ------ -------- -------- ------- ------
// COLOR                    0   xyzw        0     NONE   float   xyzw
// TEXCOORD                 0   xy          1     NONE   float   xy
// SV_Position              0   xyzw        2     NONE   float   xyzw
//
//
// Output signature:
//
// Name                 Index   Mask Register SysValue  Format   Used
// -------------------- ----- ------ -------- -------- ------- ------
// COLOR                    0   xyzw        0     NONE   float   xyzw
// TEXCOORD                 0   xy          1     NONE   float   xy
// SV_Position              0   xyzw        2      POS   float   xyzw
//
vs_4_0
dcl_constantbuffer cb2[8], immediateIndexed
dcl_input v0.xyzw
dcl_input v1.xy
dcl_input v2.xyzw
dcl_output o0.xyzw
dcl_output o1.xy
dcl_output_siv o2.xyzw, position
dcl_temps 1
mov o0.xyzw, v0.xyzw
mov o1.xy, v1.xyxx
mul r0.xyzw, v2.yyyy, cb2[5].xyzw
mad r0.xyzw, v2.xxxx, cb2[4].xyzw, r0.xyzw
mad r0.xyzw, v2.zzzz, cb2[6].xyzw, r0.xyzw
mad o2.xyzw, v2.wwww, cb2[7].xyzw, r0.xyzw
ret
// Approximately 7 instruction slots used

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