// hlsltool.py -I ../.. --auto-fix-vertex-halo --fix-unity-reflection --fix-unity-frustum-world --only-autofixed --fxc /home/Ryan/fxc.exe feadbbd09315af86-vs_replace.txt
// 3DMigoto: feadbbd09315af86 |    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 2/2 {
//          Name "SHADOWCASTER"
//          Tags { "LIGHTMODE"="SHADOWCASTER" "QUEUE"="Transparent-99" "IGNOREPROJECTOR"="true" "SHADOWSUPPORT"="true" "DisableBatching"="true" "RenderType"="TreeTransparentCutout" }
//          Cull Off
//          ColorMask RGB
//          GpuProgramID 101566
//          Program "vp" {
//            SubProgram "d3d11_9x " {
//              GpuProgramIndex 14
//            }
//          }
//        }
//      }
//    }
//
// Unity 5.3 headers extracted from TreeSoftOcclusionLeaves.shader.decompressed:
//   API d3d11_9x
//   Shader model vs_4_0_level_9_1
//   undeciphered1: 52 0 0
//   Keywords { "SHADOWS_DEPTH" }
//   undeciphered2: 1 0 5 0 0
//   undeciphered3: 15 4 0 0 2 1 1 2 3 4
//   ConstBuffer "UnityLighting" 720
//   Vector 0 [_WorldSpaceLightPos0]
//   ConstBuffer "UnityShadows" 416
//   Vector 80 [unity_LightShadowBias]
//   ConstBuffer "UnityPerDraw" 352
//   Matrix 0 [glstate_matrix_mvp]
//   Matrix 192 [_Object2World]
//   Matrix 256 [_World2Object]
//   ConstBuffer "UnityPerFrame" 256
//   Matrix 144 [unity_MatrixVP]
//   ConstBuffer "UnityTerrain" 272
//   Vector 96 [_TreeInstanceScale]
//   Vector 176 [_SquashPlaneNormal]
//   Float 192 [_SquashAmount]
//   Matrix 112 [_TerrainEngineBendTree]
//   BindCB "UnityLighting" 0
//   BindCB "UnityShadows" 1
//   BindCB "UnityPerDraw" 2
//   BindCB "UnityPerFrame" 3
//   BindCB "UnityTerrain" 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:39:40 2016
cbuffer cb4 : register(b4)
{
  float4 cb4[13];
}

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

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

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

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




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


void main( 
  float4 v0 : POSITION0,
  float3 v1 : NORMAL0,
  float4 v2 : COLOR0,
  float4 v3 : TEXCOORD0,
  out float4 o0 : SV_POSITION0,
  out float2 o1 : TEXCOORD1)
{
  float4 r0,r1,r2,r3;
  uint4 bitmask, uiDest;
  float4 fDest;

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

  r0.x = cb2[16].x * v1.x;
  r0.y = cb2[17].x * v1.x;
  r0.z = cb2[18].x * v1.x;
  r1.x = cb2[16].y * v1.y;
  r1.y = cb2[17].y * v1.y;
  r1.z = cb2[18].y * v1.y;
  r0.xyz = r1.xyz + r0.xyz;
  r1.x = cb2[16].z * v1.z;
  r1.y = cb2[17].z * v1.z;
  r1.z = cb2[18].z * v1.z;
  r0.xyz = r1.xyz + r0.xyz;
  r0.w = dot(r0.xyz, r0.xyz);
  r0.w = rsqrt(r0.w);
  r0.xyz = r0.xyz * r0.www;
  r1.xyz = cb4[6].xyz * v0.xyz;
  r2.xyz = cb4[8].xyz * r1.yyy;
  r2.xyz = cb4[7].xyz * r1.xxx + r2.xyz;
  r2.xyz = cb4[9].xyz * r1.zzz + r2.xyz;
  r2.xyz = -v0.xyz * cb4[6].xyz + r2.xyz;
  r1.xyz = v2.www * r2.xyz + r1.xyz;
  r0.w = dot(cb4[11].xyz, r1.xyz);
  r0.w = cb4[11].w + r0.w;
  r2.xyz = -r0.www * cb4[11].xyz + r1.xyz;
  r1.xyz = -r2.xyz + r1.xyz;
  r1.xyz = cb4[12].xxx * r1.xyz + r2.xyz;
  r2.xyz = cb2[13].xyz * r1.yyy;
  r2.xyz = cb2[12].xyz * r1.xxx + r2.xyz;
  r2.xyz = cb2[14].xyz * r1.zzz + r2.xyz;
  r2.xyz = cb2[15].xyz + r2.xyz;
  r3.xyz = -r2.xyz * cb0[0].www + cb0[0].xyz;
  r0.w = dot(r3.xyz, r3.xyz);
  r0.w = rsqrt(r0.w);
  r3.xyz = r3.xyz * r0.www;
  r0.w = dot(r0.xyz, r3.xyz);
  r0.w = -r0.w * r0.w + 1;
  r0.w = sqrt(r0.w);
  r0.w = cb1[5].z * r0.w;
  r0.xyz = -r0.xyz * r0.www + r2.xyz;
  r2.xyzw = cb3[10].xyzw * r0.yyyy;
  r2.xyzw = cb3[9].xyzw * r0.xxxx + r2.xyzw;
  r0.xyzw = cb3[11].xyzw * r0.zzzz + r2.xyzw;
  r0.xyzw = cb3[12].xyzw + r0.xyzw;
  r2.xyzw = cb2[1].xyzw * r1.yyyy;
  r2.xyzw = cb2[0].xyzw * r1.xxxx + r2.xyzw;
  r1.xyzw = cb2[2].xyzw * r1.zzzz + r2.xyzw;
  r1.xyzw = cb2[3].xyzw + r1.xyzw;
  r2.x = cmp(cb1[5].z != 0.000000);
  r0.xyzw = r2.xxxx ? r0.xyzw : r1.xyzw;

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

  r1.x = saturate(cb1[5].x / r0.w);
  r0.z = r1.x + r0.z;

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

  r0.x = max(0, r0.z);
  r0.x = r0.x + -r0.z;
  o0.z = cb1[5].y * r0.x + r0.z;
  o1.xy = v3.xy;
  return;
}
