// hlsltool.py -I ../112 --auto-fix-vertex-halo --fix-unity-reflection --only-autofixed --no-validate --ignore-other-errors 7a78321f01775879-vs_replace.txt
// 3DMigoto: 7a78321f01775879 | Matched 2 variants of 1 shaders: Nature/SpeedTree
//
//       Unity headers extracted from SpeedTree.shader
//       Shader "Nature/SpeedTree" {
//         Properties {
//          _Color ("Main Color", Color) = (1,1,1,1)
//          _SpecColor ("Specular Color", Color) = (0,0,0,0)
//          _HueVariation ("Hue Variation", Color) = (1,0.5,0,0.1)
//          _Shininess ("Shininess", Range(0.01,1)) = 0.1
//          _MainTex ("Base (RGB) Trans (A)", 2D) = "white" { }
//          _DetailTex ("Detail", 2D) = "black" { }
//          _BumpMap ("Normal Map", 2D) = "bump" { }
//          _Cutoff ("Alpha Cutoff", Range(0,1)) = 0.333
//         [MaterialEnum(Off,0,Front,1,Back,2)]  _Cull ("Cull", Float) = 2
//         [MaterialEnum(None,0,Fastest,1,Fast,2,Better,3,Best,4,Palm,5)]  _WindQuality ("Wind Quality", Range(0,5)) = 0
//         }
//         Fallback "Transparent/Cutout/VertexLit"
//         SubShader 2/2 {
//           LOD 400
//           Tags { "QUEUE"="Geometry" "IGNOREPROJECTOR"="true" "DisableBatching"="LodFading" "RenderType"="Opaque" }
//           Pass 6/7 {
//             Tags { "LIGHTMODE"="SHADOWCASTER" "QUEUE"="Geometry" "IGNOREPROJECTOR"="true" "SHADOWSUPPORT"="true" "DisableBatching"="LodFading" "RenderType"="Opaque" }
//             Cull [_Cull]
//             GpuProgramID 803874
//             Program "vp" {
//               SubProgram "d3d11 " {
// 1:              GpuProgramIndex 3017
// 2:              GpuProgramIndex 3023
//               }
//             }
//           }
//         }
//       }
//
//    Unity 5.3 headers extracted from SpeedTree.shader.decompressed:
//      API d3d11
//      Shader model vs_4_0
//      undeciphered1: 201509030 43 0 0
// 1:   Keywords { "SHADOWS_DEPTH" "LOD_FADE_PERCENTAGE" "GEOM_TYPE_BRANCH" }
// 2:   Keywords { "SHADOWS_DEPTH" "LOD_FADE_PERCENTAGE" "GEOM_TYPE_BRANCH_DETAIL" }
//      undeciphered2: 1 0 4 0 0
//      undeciphered3: 23 4 0 0 2 1 1 2 4 5
//      ConstBuffer "UnityLighting" 720
//      Vector 0 [_WorldSpaceLightPos0]
//      ConstBuffer "UnityShadows" 416
//      Vector 80 [unity_LightShadowBias]
//      ConstBuffer "UnityPerDraw" 352
//      Vector 320 [unity_LODFade]
//      Matrix 0 [glstate_matrix_mvp]
//      Matrix 192 [_Object2World]
//      Matrix 256 [_World2Object]
//      ConstBuffer "UnityPerFrame" 256
//      Matrix 144 [unity_MatrixVP]
//      BindCB "UnityLighting" 0
//      BindCB "UnityShadows" 1
//      BindCB "UnityPerDraw" 2
//      BindCB "UnityPerFrame" 3
//
// 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.38 on Thu Feb 09 12:29:36 2017
cbuffer cb3 : register(b3)
{
  float4 cb3[13];
}

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

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,
  float4 v1 : TANGENT0,
  float3 v2 : NORMAL0,
  float4 v3 : TEXCOORD0,
  float4 v4 : TEXCOORD1,
  float4 v5 : TEXCOORD2,
  float2 v6 : TEXCOORD3,
  float4 v7 : COLOR0,
  out float4 o0 : SV_POSITION0)
{
  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 * v2.x;
  r0.y = cb2[17].x * v2.x;
  r0.z = cb2[18].x * v2.x;
  r1.x = cb2[16].y * v2.y;
  r1.y = cb2[17].y * v2.y;
  r1.z = cb2[18].y * v2.y;
  r0.xyz = r1.xyz + r0.xyz;
  r1.x = cb2[16].z * v2.z;
  r1.y = cb2[17].z * v2.z;
  r1.z = cb2[18].z * v2.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 = v4.xyz + -v0.xyz;
  r1.xyz = cb2[20].xxx * r1.xyz + v0.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;
  r1.w = cmp(cb1[5].z != 0.000000);
  r2.xyzw = cb2[1].xyzw * r1.yyyy;
  r2.xyzw = cb2[0].xyzw * r1.xxxx + r2.xyzw;
  r2.xyzw = cb2[2].xyzw * r1.zzzz + r2.xyzw;
  r2.xyzw = cb2[3].xyzw + r2.xyzw;
  r0.xyzw = r1.wwww ? r0.xyzw : r2.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 ../112 --auto-fix-vertex-halo --fix-unity-reflection --only-autofixed --no-validate --ignore-other-errors 7a78321f01775879-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;
  return;
}
