// hlsltool.py -I ../112 --auto-fix-vertex-halo --fix-unity-reflection --only-autofixed --no-validate --ignore-other-errors 6c85ef8f60b4b422-vs_replace.txt
// 3DMigoto: 6c85ef8f60b4b422 | 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 1/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 336943
//             Program "vp" {
//               SubProgram "d3d11 " {
// 1:              GpuProgramIndex 2185
// 2:              GpuProgramIndex 2189
//               }
//             }
//           }
//         }
//       }
//
//    Unity 5.3 headers extracted from SpeedTree.shader.decompressed:
//      API d3d11
//      Shader model vs_4_0
//      undeciphered1: 201509030 162 0 4
// 1:   Keywords { "SHADOWS_DEPTH" "GEOM_TYPE_BRANCH" }
// 2:   Keywords { "SHADOWS_DEPTH" "GEOM_TYPE_BRANCH_DETAIL" }
//      undeciphered2: 1 0 6 0 0
//      undeciphered3: 15 4 0 0 2 1 1 2 3 4
//      ConstBuffer "$Globals" 144
//      Float 96 [_WindQuality]
//      Float 100 [_WindEnabled]
//      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 "SpeedTreeWind" 256
//      Vector 0 [_ST_WindVector]
//      Vector 16 [_ST_WindGlobal]
//      Vector 32 [_ST_WindBranch]
//      Vector 48 [_ST_WindBranchTwitch]
//      Vector 64 [_ST_WindBranchWhip]
//      Vector 80 [_ST_WindBranchAnchor]
//      Vector 96 [_ST_WindBranchAdherences]
//      Vector 112 [_ST_WindTurbulences]
//      Vector 240 [_ST_WindAnimation]
//      BindCB "$Globals" 0
//      BindCB "UnityLighting" 1
//      BindCB "UnityShadows" 2
//      BindCB "UnityPerDraw" 3
//      BindCB "UnityPerFrame" 4
//      BindCB "SpeedTreeWind" 5
//
// 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:28:55 2017
cbuffer cb5 : register(b5)
{
  float4 cb5[16];
}

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

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

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

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

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




// 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,r4;
  uint4 bitmask, uiDest;
  float4 fDest;

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

  r0.x = cb0[6].x * cb0[6].y;
  r0.y = cmp(0 >= r0.x);
  r1.xyz = cb5[0].yyy * cb3[17].xyz;
  r1.xyz = cb3[16].xyz * cb5[0].xxx + r1.xyz;
  r1.xyz = cb3[18].xyz * cb5[0].zzz + r1.xyz;
  r0.z = dot(r1.xyz, r1.xyz);
  r0.z = rsqrt(r0.z);
  r0.zw = r1.xz * r0.zz;
  r0.yz = r0.yy ? float2(0,0) : r0.zw;
  r0.w = cmp(r0.x >= 3);
  if (r0.w != 0) {
    r0.w = cmp(r0.x == 5.000000);
    if (r0.w != 0) {
      r1.xyz = cb5[5].yyy * cb3[17].xyz;
      r1.xyz = cb3[16].xyz * cb5[5].xxx + r1.xyz;
      r1.xyz = cb3[18].xyz * cb5[5].zzz + r1.xyz;
      r0.w = dot(r1.xyz, r1.xyz);
      r0.w = rsqrt(r0.w);
      r1.xyz = r1.xyz * r0.www;
      r2.xyz = float3(0.0625,1,16) * v3.www;
      r2.xyz = frac(r2.xyz);
      r2.xyz = r2.xyz * float3(2,2,2) + float3(-1,-1,-1);
      r2.xyz = v3.zzz * r2.xyz;
      r0.w = cb3[15].x + cb3[15].y;
      r0.w = cb5[2].x + r0.w;
      r3.x = v3.w + r0.w;
      r3.y = r0.w * cb5[3].y + v3.w;
      r1.w = cb5[3].y * r3.x;
      r3.z = 0.5 * r1.w;
      r3.w = -v3.z + r3.x;
      r3.xyzw = float4(0.5,0.5,0.5,1.5) + r3.xyzw;
      r3.xyzw = frac(r3.xyzw);
      r3.xyzw = r3.xyzw * float4(2,2,2,2) + float4(-1,-1,-1,-1);
      r4.xyzw = abs(r3.xyzw) * abs(r3.xyzw);
      r3.xyzw = -abs(r3.xyzw) * float4(2,2,2,2) + float4(3,3,3,3);
      r3.xyzw = r4.xyzw * r3.xyzw + float4(-0.5,-0.5,-0.5,-0.5);
      r3.xyzw = r3.xyzw + r3.xyzw;
      r4.w = r3.y * r3.z;
      r1.w = cmp(r4.w < 0);
      r4.y = -r4.w;
      r4.xz = float2(-1,1);
      r4.xy = r1.ww ? r4.xy : r4.zw;
      r1.w = -r3.y * r3.z + r4.x;
      r1.w = r4.y * r1.w + r4.w;
      r2.w = r4.x + -r1.w;
      r1.w = r4.y * r2.w + r1.w;
      r1.w = cb5[3].x * r1.w;
      r2.w = 1 + -cb5[0].w;
      r3.y = 1 + -cb5[3].x;
      r3.x = r3.x * r3.y;
      r1.w = r1.w * r2.w + r3.x;
      r2.w = r3.w * cb5[4].x + 1;
      r1.w = r2.w * r1.w;
      r2.xyz = r2.xyz * r1.www;
      r2.xyz = r2.xyz * cb5[2].yyy + v0.xyz;
      r3.x = r0.w * 0.100000001 + v3.w;
      r0.w = cb5[15].x * cb5[7].x;
      r3.y = r0.w * 0.100000001 + v3.w;
      r3.xy = float2(0.5,0.5) + r3.xy;
      r3.xy = frac(r3.xy);
      r3.xy = r3.xy * float2(2,2) + float2(-1,-1);
      r4.xy = abs(r3.xy) * abs(r3.xy);
      r3.xy = -abs(r3.xy) * float2(2,2) + float2(3,3);
      r3.xy = r4.xy * r3.xy + float2(-0.5,-0.5);
      r3.xy = r3.xy + r3.xy;
      r3.xy = r3.xy * r3.xy;
      r0.w = r3.y * r3.x;
      r0.w = -r0.w * cb5[7].x + 1;
      r1.w = cb5[0].w * r3.w;
      r0.w = r1.w * cb5[4].x + r0.w;
      r1.xyz = r1.xyz * cb5[5].www + -r2.xyz;
      r1.xyz = cb5[6].yyy * r1.xyz;
      r1.xyz = r1.xyz * r0.www;
      r1.xyz = r1.xyz * v3.zzz + r2.xyz;
    } else {
      r2.xyz = float3(0.0625,1,16) * v3.www;
      r2.xyz = frac(r2.xyz);
      r2.xyz = r2.xyz * float3(2,2,2) + float3(-1,-1,-1);
      r2.xyz = v3.zzz * r2.xyz;
      r0.w = cb3[15].x + cb3[15].y;
      r0.w = cb5[2].x + r0.w;
      r3.x = v3.w + r0.w;
      r3.y = r0.w * cb5[3].y + v3.w;
      r0.w = cb5[3].y * r3.x;
      r3.z = 0.5 * r0.w;
      r3.xyz = float3(0.5,0.5,0.5) + r3.xyz;
      r3.xyz = frac(r3.xyz);
      r3.xyz = r3.xyz * float3(2,2,2) + float3(-1,-1,-1);
      r4.xyz = abs(r3.xyz) * abs(r3.xyz);
      r3.xyz = -abs(r3.xyz) * float3(2,2,2) + float3(3,3,3);
      r3.xyz = r4.xyz * r3.xyz + float3(-0.5,-0.5,-0.5);
      r3.xyz = r3.xyz + r3.xyz;
      r4.w = r3.y * r3.z;
      r0.w = cmp(r4.w < 0);
      r4.y = -r4.w;
      r4.xz = float2(-1,1);
      r4.xy = r0.ww ? r4.xy : r4.zw;
      r0.w = -r3.y * r3.z + r4.x;
      r0.w = r4.y * r0.w + r4.w;
      r1.w = r4.x + -r0.w;
      r0.w = r4.y * r1.w + r0.w;
      r0.w = cb5[3].x * r0.w;
      r1.w = 1 + -cb5[0].w;
      r2.w = 1 + -cb5[3].x;
      r2.w = r3.x * r2.w;
      r0.w = r0.w * r1.w + r2.w;
      r2.xyz = r2.xyz * r0.www;
      r1.xyz = r2.xyz * cb5[2].yyy + v0.xyz;
    }
  } else {
    r1.xyz = v0.xyz;
  }
  r0.x = cmp(0 < r0.x);
  r0.w = dot(r1.xyz, r1.xyz);
  r0.w = sqrt(r0.w);
  r1.w = 1 / cb5[1].z;
  r1.w = -r1.w * 0.25 + r1.y;
  r1.w = max(0, r1.w);
  r1.w = cb5[1].z * r1.w;
  r2.x = cmp(r1.w != 0.000000);
  r2.y = log2(r1.w);
  r2.y = cb5[1].w * r2.y;
  r2.y = exp2(r2.y);
  r1.w = r2.x ? r2.y : r1.w;
  r2.x = cb5[1].x + cb3[15].x;
  r2.y = cb5[1].x * 0.800000012 + cb3[15].y;
  r2.xy = float2(0.5,0.5) + r2.xy;
  r2.xy = frac(r2.xy);
  r2.xy = r2.xy * float2(2,2) + float2(-1,-1);
  r2.zw = abs(r2.xy) * abs(r2.xy);
  r2.xy = -abs(r2.xy) * float2(2,2) + float2(3,3);
  r2.xy = r2.zw * r2.xy + float2(-0.5,-0.5);
  r2.xy = r2.xy + r2.xy;
  r2.x = r2.y * r2.y + r2.x;
  r2.y = cb5[6].x / cb5[1].z;
  r2.x = cb5[1].y * r2.x + r2.y;
  r1.w = r2.x * r1.w;
  r2.xz = r0.yz * r1.ww + r1.xz;
  r2.y = r1.y;
  r0.y = dot(r2.xyz, r2.xyz);
  r0.y = rsqrt(r0.y);
  r2.xyz = r2.xyz * r0.yyy;
  r0.yzw = r2.xyz * r0.www;
  r0.xyz = r0.xxx ? r0.yzw : r1.xyz;
  r0.w = cmp(cb2[5].z != 0.000000);
  r1.xyz = cb3[13].xyz * r0.yyy;
  r1.xyz = cb3[12].xyz * r0.xxx + r1.xyz;
  r1.xyz = cb3[14].xyz * r0.zzz + r1.xyz;
  r1.xyz = cb3[15].xyz + r1.xyz;
  r2.x = cb3[16].x;
  r2.y = cb3[17].x;
  r2.z = cb3[18].x;
  r3.x = cb3[16].y;
  r3.y = cb3[17].y;
  r3.z = cb3[18].y;
  r3.xyz = v2.yyy * r3.xyz;
  r2.xyz = r2.xyz * v2.xxx + r3.xyz;
  r3.x = cb3[16].z;
  r3.y = cb3[17].z;
  r3.z = cb3[18].z;
  r2.xyz = r3.xyz * v2.zzz + r2.xyz;
  r1.w = dot(r2.xyz, r2.xyz);
  r1.w = rsqrt(r1.w);
  r2.xyz = r2.xyz * r1.www;
  r3.xyz = -r1.xyz * cb1[0].www + cb1[0].xyz;
  r1.w = dot(r3.xyz, r3.xyz);
  r1.w = rsqrt(r1.w);
  r3.xyz = r3.xyz * r1.www;
  r1.w = dot(r2.xyz, r3.xyz);
  r1.w = -r1.w * r1.w + 1;
  r1.w = sqrt(r1.w);
  r1.w = cb2[5].z * r1.w;
  r1.xyz = -r2.xyz * r1.www + r1.xyz;
  r2.xyzw = cb4[10].xyzw * r1.yyyy;
  r2.xyzw = cb4[9].xyzw * r1.xxxx + r2.xyzw;
  r1.xyzw = cb4[11].xyzw * r1.zzzz + r2.xyzw;
  r1.xyzw = cb4[12].xyzw + r1.xyzw;
  r2.xyzw = cb3[1].xyzw * r0.yyyy;
  r2.xyzw = cb3[0].xyzw * r0.xxxx + r2.xyzw;
  r2.xyzw = cb3[2].xyzw * r0.zzzz + r2.xyzw;
  r2.xyzw = cb3[3].xyzw + r2.xyzw;
  r0.xyzw = r0.wwww ? r1.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 6c85ef8f60b4b422-vs_replace.txt
if (r0.w != 1.0) { r0.x += separation * (r0.w - convergence); }

  r1.x = saturate(cb2[5].x / r0.w);
  r0.z = r1.x + r0.z;
  r1.x = max(0, r0.z);
  r1.x = r1.x + -r0.z;
  o0.z = cb2[5].y * r1.x + r0.z;

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

  return;
}
 