// Unstretch and Flip Phone Bar Image (PTRSCLL)
// Bar Image Resolution Ratio = round(res_width*0.053125) x res_height
cbuffer cb1 : register(b1) {float4 cb1[6];}
cbuffer cb0 : register(b0) {float4 cb0[16];}

// 3Dmigoto declarations
#define cmp -
#define FLIP IniParams[101].x
#define PREVIEW IniParams[101].y
#define UNSTRETCH IniParams[101].z
#define HIDE_UID IniParams[101].w
Texture1D<float4> IniParams : register(t120);
Texture2D<float4> StereoParams : register(t125);

void main(
  float4 v0 : POSITION0,
  float4 v1 : COLOR0,
  float4 v2 : TEXCOORD0,
  float2 v3 : TEXCOORD7,
  out float4 o0 : SV_POSITION0,
  out float4 o1 : COLOR0,
  out float4 o2 : TEXCOORD0)
{
  float4 r0,r1;
  uint4 bitmask, uiDest;
  float4 fDest;

  r0.xyzw = cb0[13].xyzw * v0.yyyy;
  r0.xyzw = cb0[12].xyzw * v0.xxxx + r0.xyzw;
  r0.xyzw = cb0[14].xyzw * v0.zzzz + r0.xyzw;
  o0.xyzw = cb0[15].xyzw + r0.xyzw;
  
  o1.xyzw = cb1[0].xyzw * v1.xyzw;
  
  o2.zw = v3.xy;

  if (UNSTRETCH) {
    o2.x = v2.x * cb1[5].x + cb1[5].z;
    o2.y = 0.5 * (1 - (v0.y * abs(cb0[13].y)));

    if (FLIP) {
      o2.y = 1 - o2.y;
    }
    if (PREVIEW) {
      o2.y *= 1.2655;
      o2.y -= 0.16;
    }
  }

  else {
    // Use Default Texcoord
    o2.xy = float2(
      v2.x * cb1[5].x + cb1[5].z,
      v2.y * cb1[5].y + cb1[5].w
    );

    // Hide Phone UID
    if (HIDE_UID) {
      if (
        (0.9 < o0.y * sign(cb0[13].y))
        && (0 < o0.x && o0.x < 0.7)
      ) {
        o0.xyzw = float4(0, 0, 0, 0);
      }
    }
  }

  return;
}