// Icon Name
cbuffer _Globals : register(b0)
{
  float4 g_vStringPos : packoffset(c0);
  float4 cv1 : packoffset(c1);
  float4 g_vCellSize : packoffset(c2);
  float4 g_vRotation : packoffset(c3);
  float4 g_avChars[64] : packoffset(c4);
  float4 g_avOffsets[64] : packoffset(c68);
  float4 g_vColor : packoffset(c132) = {1,1,1,1};
  float4 g_avMask[4] : packoffset(c133) = {
    {1,0,0,0},
	{0,1,0,0},
	{0,0,1,0},
	{0,0,0,1}};

}

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


void main( 
  float3 v0 : POSITION0,
  out float4 o0 : SV_Position0,
  out float2 o1 : TEXCOORD0)
{
  float4 r0,r1,r2,r3,r4;
  uint4 bitmask, uiDest;
  float4 fDest;
  
  float4 stereo = StereoParams.Load(0);
  float sep = IniParams.Load(0).x;
  
  r0.x = (int)v0.z;
  r0.y = (uint)r0.x >> 2;
  r0.z = (int)r0.x & 3;
  r0.w = dot(g_avMask[r0.z].xyzw, g_avOffsets[r0.y].xyzw);
  r1.x = cmp((int)r0.x < 255);
  if (r1.x != 0) {
    r1.x = (int)r0.x + 1;
    r1.y = (int)r1.x & 3;
    r1.x = (uint)r1.x >> 2;
    r1.x = dot(g_avMask[r1.y].xyzw, g_avOffsets[r1.x].xyzw);
    r1.x = r1.x + -r0.w;
  } else {
    r0.x = (int)r0.x + -1;
    r1.y = (int)r0.x & 3;
    r0.x = (uint)r0.x >> 2;
    r0.x = dot(g_avMask[r1.y].xyzw, g_avOffsets[r0.x].xyzw);
    r1.x = r0.w + -r0.x;
  }
  r0.x = cv1.w * r1.x;
  r0.w = cv1.w * r0.w;
  r0.x = v0.x * r0.x + r0.w;
  r0.w = g_vStringPos.z * -v0.y;
  r0.w = g_vRotation.y * r0.w;
  sincos(g_vRotation.x, r2.x, r3.x);
  r1.y = r2.x * r0.w;
  r4.x = r0.x * r3.x + -r1.y;
  r0.w = r3.x * r0.w;
  r0.x = r0.x * r2.x + r0.w;
  r4.y = r0.x / g_vRotation.y;
  o0.xy = (g_vStringPos.xy + r4.xy);
  // o0.xy = (g_vStringPos.xy + r4.xy);
  r0.x = dot(g_avMask[r0.z].xyzw, g_avChars[r0.y].xyzw);
  r0.x = -cv1.x + r0.x;
  r0.x = 0.00100000005 + r0.x;
  r0.x = (int)r0.x;
  r0.y = (int)g_vCellSize.z;
  r0.z = (int)r0.y ^ (int)r0.x;
  r0.w = max((int)-r0.x, (int)r0.x);
  r1.y = max((int)-r0.y, (int)r0.y);
  uiDest.w = (uint)r0.w / (uint)r1.y;
  r0.w = uiDest.w;
  r1.y = -(int)r0.w;
  r0.z = (int)r0.z & 0x80000000;
  r0.z = r0.z ? r1.y : r0.w;
  r0.x = mad((int)-r0.z, (int)r0.y, (int)r0.x);
  r0.y = v0.x * r1.x;
  r0.x = (int)r0.x;
  r0.x = g_vCellSize.x * r0.x;
  o1.x = r0.y * cv1.z + r0.x;
  r0.x = (int)r0.z;
  r0.x = v0.y + r0.x;
  o1.y = g_vCellSize.y * r0.x;
  o0.zw = float2(0,1);
  
  o0.x += (stereo.x * (1 + sep - stereo.y));
  return;
}
