// hlsltool.py -I ../.. --auto-fix-vertex-halo --fix-unity-reflection --fix-unity-frustum-world --only-autofixed --fxc /home/Ryan/fxc.exe 03245d6977587b50-vs_replace.txt
// 3DMigoto: 03245d6977587b50 |    Unity headers extracted from TreeSoftOcclusionLeaves.shader
//    Shader "Nature/Tree Soft Occlusion Leaves" {
//      Properties {
//       _Color ("Main Color", Color) = (1,1,1,1)
//       _MainTex ("Main Texture", 2D) = "white" { }
//       _Cutoff ("Alpha cutoff", Range(0.25,0.9)) = 0.5
//       _BaseLight ("Base Light", Range(0,1)) = 0.35
//       _AO ("Amb. Occlusion", Range(0,10)) = 2.4
//       _Occlusion ("Dir Occlusion", Range(0,20)) = 7.5
//      [HideInInspector]  _TreeInstanceColor ("TreeInstanceColor", Vector) = (1,1,1,1)
//      [HideInInspector]  _TreeInstanceScale ("TreeInstanceScale", Vector) = (1,1,1,1)
//      [HideInInspector]  _SquashAmount ("Squash", Float) = 1
//      }
//      Dependency "BillboardShader" = "Hidden/Nature/Tree Soft Occlusion Leaves Rendertex"
//      Fallback Off
//      SubShader 1/2 {
//        Tags { "QUEUE"="Transparent-99" "IGNOREPROJECTOR"="true" "DisableBatching"="true" "RenderType"="TreeTransparentCutout" }
//        Pass 1/2 {
//          Tags { "QUEUE"="Transparent-99" "IGNOREPROJECTOR"="true" "DisableBatching"="true" "RenderType"="TreeTransparentCutout" }
//          Lighting On
//          Cull Off
//          ColorMask RGB
//          GpuProgramID 58747
//          Program "vp" {
//            SubProgram "d3d11_9x " {
//              GpuProgramIndex 5
//            }
//          }
//        }
//      }
//    }
//
// Unity 5.3 headers extracted from TreeSoftOcclusionLeaves.shader.decompressed:
//   API d3d11_9x
//   Shader model vs_4_0_level_9_1
//   undeciphered1: 42 0 1
//   Keywords { "FOG_LINEAR" }
//   undeciphered2: 1 0 7 0 0
//   undeciphered3: 141 4 0 0 2 1 3 4 7 8
//   ConstBuffer "$Globals" 160
//   Float 112 [_Occlusion]
//   Float 116 [_AO]
//   Float 120 [_BaseLight]
//   Vector 128 [_Color]
//   Float 144 [_HalfOverCutoff]
//   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]
//   ConstBuffer "UnityPerDraw" 352
//   Matrix 0 [glstate_matrix_mvp]
//   Matrix 64 [glstate_matrix_modelview0]
//   ConstBuffer "UnityPerFrame" 256
//   Vector 64 [glstate_lightmodel_ambient]
//   ConstBuffer "UnityFog" 32
//   Vector 16 [unity_FogParams]
//   ConstBuffer "UnityTerrain" 272
//   Vector 80 [_TreeInstanceColor]
//   Vector 96 [_TreeInstanceScale]
//   Vector 176 [_SquashPlaneNormal]
//   Float 192 [_SquashAmount]
//   Matrix 112 [_TerrainEngineBendTree]
//   ConstBuffer "UnityPerCamera2" 64
//   Matrix 0 [_CameraToWorld]
//   BindCB "$Globals" 0
//   BindCB "UnityLighting" 1
//   BindCB "UnityPerDraw" 2
//   BindCB "UnityPerFrame" 3
//   BindCB "UnityFog" 4
//   BindCB "UnityTerrain" 5
//   BindCB "UnityPerCamera2" 6
//
// 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:39:40 2016
cbuffer cb6 : register(b6)
{
  float4 cb6[3];
}

cbuffer cb5 : register(b5)
{
  float4 cb5[13];
}

cbuffer cb4 : register(b4)
{
  float4 cb4[2];
}

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

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

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

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




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


void main( 
  float4 v0 : POSITION0,
  float4 v1 : TANGENT0,
  float3 v2 : NORMAL0,
  float4 v3 : COLOR0,
  float4 v4 : TEXCOORD0,
  out float4 o0 : SV_POSITION0,
  out float4 o1 : TEXCOORD0,
  out float4 o2 : TEXCOORD1,
  out float o3 : TEXCOORD2)
{
  float4 r0,r1,r2,r3,r4,r5,r6;
  uint4 bitmask, uiDest;
  float4 fDest;

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

  r0.xyz = cb5[6].xyz * v0.xyz;
  r1.xyz = cb5[8].xyz * r0.yyy;
  r1.xyz = cb5[7].xyz * r0.xxx + r1.xyz;
  r1.xyz = cb5[9].xyz * r0.zzz + r1.xyz;
  r1.xyz = -v0.xyz * cb5[6].xyz + r1.xyz;
  r0.xyz = v3.www * r1.xyz + r0.xyz;
  r0.w = dot(cb5[11].xyz, r0.xyz);
  r0.w = cb5[11].w + r0.w;
  r1.xyz = -r0.www * cb5[11].xyz + r0.xyz;
  r0.xyz = -r1.xyz + r0.xyz;
  r0.xyz = cb5[12].xxx * r0.xyz + r1.xyz;
  r1.xyz = cb2[5].xyz * r0.yyy;
  r1.xyz = cb2[4].xyz * r0.xxx + r1.xyz;
  r1.xyz = cb2[6].xyz * r0.zzz + r1.xyz;
  r1.xyz = cb2[7].xyz + r1.xyz;
  r2.xyzw = cb2[1].xyzw * r0.yyyy;
  r2.xyzw = cb2[0].xyzw * r0.xxxx + r2.xyzw;
  r0.xyzw = cb2[2].xyzw * r0.zzzz + r2.xyzw;
  r0.xyzw = cb2[3].xyzw + r0.xyzw;
  r2.xyz = cb3[4].xyz + cb3[4].xyz;
  r3.w = cb0[7].y;
  r4.xyz = r2.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;
    r5.w = -r5.z;
    r2.w = dot(r5.xyw, r5.xyw);
    r4.w = rsqrt(r2.w);
    r5.xyz = r5.xyw * r4.www;
    r6.xyz = cb6[1].xyz * r5.yyy;
    r5.xyw = cb6[0].xyz * r5.xxx + r6.xyz;
    r5.xyz = cb6[2].xyz * r5.zzz + r5.xyw;
    r2.w = r2.w * cb1[r1.w+22].z + 1;
    r2.w = 1 / r2.w;
    r3.xyz = cb0[7].xxx * r5.xyz;
    r3.x = dot(v1.xyzw, r3.xyzw);
    r3.x = max(0, r3.x);
    r3.x = cb0[7].z + r3.x;
    r2.w = r3.x * r2.w;
    r4.xyz = cb1[r1.w+6].xyz * r2.www + r4.xyz;
    r1.w = (int)r1.w + 1;
  }
  r1.xyz = cb0[8].xyz * r4.xyz;
  o2.xyz = cb5[5].xyz * r1.xyz;
  o2.w = 0.5 * cb0[9].x;

o0.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 03245d6977587b50-vs_replace.txt
if (r0.w != 1.0) { r0.x += separation * (r0.w - convergence); }

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

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

  o1.xyzw = v4.xyzw;
  return;
}
