// hlsltool.py -I ../.. --auto-fix-vertex-halo --fix-unity-reflection --fix-unity-frustum-world --only-autofixed --fxc /home/Ryan/fxc.exe 764047f805f0217f-vs_replace.txt
// 3DMigoto: 764047f805f0217f |    Unity headers extracted from Reflect-VertexLit.shader
//    Shader "Legacy Shaders/Reflective/VertexLit" {
//      Properties {
//       _Color ("Main Color", Color) = (1,1,1,1)
//       _ReflectColor ("Reflection Color", Color) = (1,1,1,0.5)
//       _MainTex ("Base (RGB) RefStrength (A)", 2D) = "white" { }
//       _Cube ("Reflection Cubemap", CUBE) = "_Skybox" { }
//      }
//      Fallback "Legacy Shaders/VertexLit"
//      SubShader 1/1 {
//        LOD 150
//        Tags { "RenderType"="Opaque" }
//        Pass 2/4 {
//          Tags { "LIGHTMODE"="Vertex" "RenderType"="Opaque" }
//          Lighting On
//          ZWrite Off
//          Blend One One
//          GpuProgramID 70332
//          Program "vp" {
//            SubProgram "d3d11 " {
//              GpuProgramIndex 16
//            }
//          }
//        }
//      }
//    }
//
// Unity 5.3 headers extracted from Reflect-VertexLit.shader.decompressed:
//   API d3d11
//   Shader model vs_4_0
//   undeciphered1: 36 0 1
//   Keywords { "FOG_LINEAR" }
//   undeciphered2: 1 0 5 0 0
//   undeciphered3: 11 3 0 0 1 2 3 4
//   ConstBuffer "$Globals" 144
//   Vector 96 [_MainTex_ST]
//   Vector 112 [_Color]
//   Vector 128 [_ReflectColor]
//   ConstBuffer "UnityLighting" 720
//   Vector 96 [unity_LightColor0]
//   Vector 112 [unity_LightColor1]
//   Vector 128 [unity_LightColor2]
//   Vector 144 [unity_LightColor3]
//   Vector 160 [unity_LightColor4]
//   Vector 176 [unity_LightColor5]
//   Vector 192 [unity_LightColor6]
//   Vector 208 [unity_LightColor7]
//   Vector 224 [unity_LightPosition0]
//   Vector 240 [unity_LightPosition1]
//   Vector 256 [unity_LightPosition2]
//   Vector 272 [unity_LightPosition3]
//   Vector 288 [unity_LightPosition4]
//   Vector 304 [unity_LightPosition5]
//   Vector 320 [unity_LightPosition6]
//   Vector 336 [unity_LightPosition7]
//   Vector 352 [unity_LightAtten0]
//   Vector 368 [unity_LightAtten1]
//   Vector 384 [unity_LightAtten2]
//   Vector 400 [unity_LightAtten3]
//   Vector 416 [unity_LightAtten4]
//   Vector 432 [unity_LightAtten5]
//   Vector 448 [unity_LightAtten6]
//   Vector 464 [unity_LightAtten7]
//   Vector 480 [unity_SpotDirection0]
//   Vector 496 [unity_SpotDirection1]
//   Vector 512 [unity_SpotDirection2]
//   Vector 528 [unity_SpotDirection3]
//   Vector 544 [unity_SpotDirection4]
//   Vector 560 [unity_SpotDirection5]
//   Vector 576 [unity_SpotDirection6]
//   Vector 592 [unity_SpotDirection7]
//   ConstBuffer "UnityPerDraw" 352
//   Matrix 0 [glstate_matrix_mvp]
//   Matrix 64 [glstate_matrix_modelview0]
//   Matrix 128 [glstate_matrix_invtrans_modelview0]
//   ConstBuffer "UnityPerFrame" 256
//   Vector 64 [glstate_lightmodel_ambient]
//   ConstBuffer "UnityFog" 32
//   Vector 16 [unity_FogParams]
//   BindCB "$Globals" 0
//   BindCB "UnityLighting" 1
//   BindCB "UnityPerDraw" 2
//   BindCB "UnityPerFrame" 3
//   BindCB "UnityFog" 4
//
// Headers extracted with DarkStarSword's extract_unity53_shaders.py
// https://raw.githubusercontent.com/DarkStarSword/3d-fixes/master/extract_unity53_shaders.py

// ---- Created with 3Dmigoto v1.2.30 on Thu Aug 18 03:38:55 2016
cbuffer cb4 : register(b4)
{
  float4 cb4[2];
}

cbuffer cb3 : register(b3)
{
  float4 cb3[5];
}

cbuffer cb2 : register(b2)
{
  float4 cb2[11];
}

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

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




// 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 float2 o0 : TEXCOORD0,
  out float p0 : TEXCOORD1,
  out float4 o1 : COLOR0,
  out float4 o2 : SV_POSITION0)
{
  float4 r0,r1,r2,r3,r4,r5;
  uint4 bitmask, uiDest;
  float4 fDest;

float4 stereo = StereoParams.Load(0);
float separation = stereo.x, convergence = stereo.y, eye = stereo.z;

  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.xy = v2.xy * cb0[6].xy + cb0[6].zw;
  r1.xyz = cb2[5].xyz * v0.yyy;
  r1.xyz = cb2[4].xyz * v0.xxx + r1.xyz;
  r1.xyz = cb2[6].xyz * v0.zzz + r1.xyz;
  r1.xyz = cb2[7].xyz * v0.www + r1.xyz;
  r2.xyz = cb2[9].xyz * v1.yyy;
  r2.xyz = cb2[8].xyz * v1.xxx + r2.xyz;
  r2.xyz = cb2[10].xyz * v1.zzz + r2.xyz;
  r1.w = dot(r2.xyz, r2.xyz);
  r1.w = rsqrt(r1.w);
  r2.xyz = r2.xyz * r1.www;
  r3.xyz = cb3[4].xyz + cb3[4].xyz;
  r4.xyz = r3.xyz;
  r1.w = 0;
  while (true) {
    r2.w = cmp((int)r1.w >= 4);
    if (r2.w != 0) break;
    r5.xyz = -r1.xyz * cb1[r1.w+14].www + cb1[r1.w+14].xyz;
    r2.w = dot(r5.xyz, r5.xyz);
    r3.w = rsqrt(r2.w);
    r5.xyz = r5.xyz * r3.www;
    r2.w = r2.w * cb1[r1.w+22].z + 1;
    r2.w = 1 / r2.w;
    r3.w = dot(r5.xyz, cb1[r1.w+30].xyz);
    r3.w = max(0, r3.w);
    r3.w = -cb1[r1.w+22].x + r3.w;
    r3.w = saturate(cb1[r1.w+22].y * r3.w);
    r2.w = r3.w * r2.w;
    r3.w = dot(r2.xyz, r5.xyz);
    r3.w = max(0, r3.w);
    r2.w = r3.w * r2.w;
    r4.xyz = cb1[r1.w+6].xyz * r2.www + r4.xyz;
    r1.w = (int)r1.w + 1;
  }
  o1.xyz = cb0[7].xyz * r4.xyz;
  o1.w = cb0[8].w * cb0[7].w;

o2.xyzw = r0.xyzw; // Relocated to here with hlsltool.py

// Automatic vertex shader halo fix inserted with DarkStarSword's hlsltool.py:
// hlsltool.py -I ../.. --auto-fix-vertex-halo --fix-unity-reflection --fix-unity-frustum-world --only-autofixed --fxc /home/Ryan/fxc.exe 764047f805f0217f-vs_replace.txt
if (r0.w != 1.0) { r0.x += separation * (r0.w - convergence); }

  p0.x = r0.z * cb4[1].z + cb4[1].w;

  // o2.xyzw = r0.xyzw; // Relocated from here with hlsltool.py

  return;
}
