// Main Lights VS - Unity 5.5
// By DSS
cbuffer cb2 : register(b2)
{
  float4 cb2[8];
}

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

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




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

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

//Fix by DSS  
float4 stereo = StereoParams.Load(0);
float4 iniParams = IniParams.Load(0);
float separation = stereo.x; float convergence = stereo.y;
matrix mp = MATRIX(cb2, 0);
matrix MV = MATRIX(cb2, 4);

  r0.xyzw = cb2[1].xyzw * v0.yyyy;
  r0.xyzw = cb2[0].xyzw * v0.xxxx + r0.xyzw;
  r0.xyzw = cb2[2].xyzw * v0.zzzz + r0.xyzw;
  r0.xyzw = cb2[3].xyzw * v0.wwww + r0.xyzw;
  o0.xyzw = r0.xyzw;
  
  bool full_screen = (r0.w == 1);
float depth = r0.w;

if (!full_screen) {
	r0.x += separation * (depth - convergence);
}
  
  r0.y = cb1[5].x * r0.y;
  r1.xzw = float3(0.5,0.5,0.5) * r0.xwy;
  o1.zw = r0.zw;
  o1.xy = r1.xw + r1.zz;
  r0.xyz = cb2[5].xyz * v0.yyy;
  r0.xyz = cb2[4].xyz * v0.xxx + r0.xyz;
  r0.xyz = cb2[6].xyz * v0.zzz + r0.xyz;
  r0.xyz = cb2[7].xyz * v0.www + r0.xyz;
  
  if (!full_screen) {
float det = 1 / determinant(MV);

	float3 mi;
	mi.x = ((MV._m11 * MV._m22) - (MV._m21 * MV._m12)) * det;
	mi.y = ((MV._m21 * MV._m02) - (MV._m01 * MV._m22)) * det;
	mi.z = ((MV._m01 * MV._m12) - (MV._m11 * MV._m02)) * det;

	fov = 1 / dot(mi, mp._m00_m10_m20);
    r0.x += separation * (depth - convergence) * fov;

}
  
  r1.xyz = float3(-1,-1,1) * r0.xyz;
  r0.xyz = -r0.xyz * float3(-1,-1,1) + v1.xyz;
  o2.xyz = cb0[2].xxx * r0.xyz + r1.xyz;
  return;
}

/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
// Generated by Microsoft (R) D3D Shader Disassembler
//
//   using 3Dmigoto v1.3.11 on Sun Jun 03 17:54:02 2018
//
//
// Input signature:
//
// Name                 Index   Mask Register SysValue  Format   Used
// -------------------- ----- ------ -------- -------- ------- ------
// POSITION                 0   xyzw        0     NONE   float   xyzw
// NORMAL                   0   xyz         1     NONE   float   xyz
//
//
// Output signature:
//
// Name                 Index   Mask Register SysValue  Format   Used
// -------------------- ----- ------ -------- -------- ------- ------
// SV_POSITION              0   xyzw        0      POS   float   xyzw
// TEXCOORD                 0   xyzw        1     NONE   float   xyzw
// TEXCOORD                 1   xyz         2     NONE   float   xyz
//
vs_4_0
dcl_constantbuffer cb0[3], immediateIndexed
dcl_constantbuffer cb1[6], immediateIndexed
dcl_constantbuffer cb2[8], immediateIndexed
dcl_input v0.xyzw
dcl_input v1.xyz
dcl_output_siv o0.xyzw, position
dcl_output o1.xyzw
dcl_output o2.xyz
dcl_temps 2
mul r0.xyzw, v0.yyyy, cb2[1].xyzw
mad r0.xyzw, cb2[0].xyzw, v0.xxxx, r0.xyzw
mad r0.xyzw, cb2[2].xyzw, v0.zzzz, r0.xyzw
mad r0.xyzw, cb2[3].xyzw, v0.wwww, r0.xyzw
mov o0.xyzw, r0.xyzw
mul r0.y, r0.y, cb1[5].x
mul r1.xzw, r0.xxwy, l(0.500000, 0.000000, 0.500000, 0.500000)
mov o1.zw, r0.zzzw
add o1.xy, r1.zzzz, r1.xwxx
mul r0.xyz, v0.yyyy, cb2[5].xyzx
mad r0.xyz, cb2[4].xyzx, v0.xxxx, r0.xyzx
mad r0.xyz, cb2[6].xyzx, v0.zzzz, r0.xyzx
mad r0.xyz, cb2[7].xyzx, v0.wwww, r0.xyzx
mul r1.xyz, r0.xyzx, l(-1.000000, -1.000000, 1.000000, 0.000000)
mad r0.xyz, -r0.xyzx, l(-1.000000, -1.000000, 1.000000, 0.000000), v1.xyzx
mad o2.xyz, cb0[2].xxxx, r0.xyzx, r1.xyzx
ret
// Approximately 0 instruction slots used

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