// hlsltool.py -I ../112 --auto-fix-vertex-halo --fix-unity-reflection --only-autofixed --no-validate --ignore-other-errors ee26435712eb0fa4-vs_replace.txt
// 3DMigoto: ee26435712eb0fa4 | Matched 4 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 4/7 {
//             Name "PREPASS"
//             Tags { "LIGHTMODE"="PrePassFinal" "QUEUE"="Geometry" "IGNOREPROJECTOR"="true" "DisableBatching"="LodFading" "RenderType"="Opaque" }
//             ZWrite Off
//             Cull [_Cull]
//             GpuProgramID 261009
//             Program "vp" {
//               SubProgram "d3d11 " {
// 1:              GpuProgramIndex 1533
// 2:              GpuProgramIndex 1535
// 4:              GpuProgramIndex 1537
// 8:              GpuProgramIndex 1539
//               }
//             }
//           }
//         }
//       }
//
//    Unity 5.3 headers extracted from SpeedTree.shader.decompressed:
//      API d3d11
//      Shader model vs_4_0
//      undeciphered1: 201509030 173 0 4
// 4:   Keywords { "LIGHTMAP_OFF" "DIRLIGHTMAP_OFF" "DYNAMICLIGHTMAP_OFF" "HDR_LIGHT_PREPASS_OFF" "EFFECT_BUMP" "EFFECT_HUE_VARIATION" "GEOM_TYPE_BRANCH_DETAIL" }
// 1:   Keywords { "LIGHTMAP_OFF" "DIRLIGHTMAP_OFF" "DYNAMICLIGHTMAP_OFF" "HDR_LIGHT_PREPASS_OFF" "EFFECT_HUE_VARIATION" "GEOM_TYPE_BRANCH_DETAIL" }
// 8:   Keywords { "LIGHTMAP_OFF" "DIRLIGHTMAP_OFF" "DYNAMICLIGHTMAP_OFF" "UNITY_HDR_ON" "EFFECT_BUMP" "EFFECT_HUE_VARIATION" "GEOM_TYPE_BRANCH_DETAIL" }
// 2:   Keywords { "LIGHTMAP_OFF" "DIRLIGHTMAP_OFF" "DYNAMICLIGHTMAP_OFF" "UNITY_HDR_ON" "EFFECT_HUE_VARIATION" "GEOM_TYPE_BRANCH_DETAIL" }
//      undeciphered2: 1 0 5 0 0
//      undeciphered3: 47 5 0 0 2 1 1 2 3 4 5 6
//      ConstBuffer "$Globals" 208
//      Vector 48 [unity_ColorSpaceLuminance]
//      Float 128 [_WindQuality]
//      Float 132 [_WindEnabled]
//      Vector 144 [_HueVariation]
//      Vector 160 [_Color]
//      ConstBuffer "UnityPerCamera" 144
//      Vector 80 [_ProjectionParams]
//      ConstBuffer "UnityLighting" 720
//      Vector 608 [unity_SHAr]
//      Vector 624 [unity_SHAg]
//      Vector 640 [unity_SHAb]
//      Vector 656 [unity_SHBr]
//      Vector 672 [unity_SHBg]
//      Vector 688 [unity_SHBb]
//      Vector 704 [unity_SHC]
//      ConstBuffer "UnityPerDraw" 352
//      Matrix 0 [glstate_matrix_mvp]
//      Matrix 192 [_Object2World]
//      Matrix 256 [_World2Object]
//      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 "UnityPerCamera" 1
//      BindCB "UnityLighting" 2
//      BindCB "UnityPerDraw" 3
//      BindCB "SpeedTreeWind" 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.38 on Thu Feb 09 12:34:56 2017
cbuffer cb4 : register(b4)
{
  float4 cb4[16];
}

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

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

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

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




// 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,
  out float4 o1 : TEXCOORD0,
  out float4 o2 : TEXCOORD1,
  out float4 o3 : TEXCOORD2,
  out float4 o4 : TEXCOORD3,
  out float4 o5 : TEXCOORD4,
  out float4 o6 : TEXCOORD5,
  out float3 o7 : TEXCOORD6)
{
  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;

  o2.xyz = cb0[10].xyz * v7.xxx;
  r0.x = cb3[15].x + cb3[15].y;
  r0.y = cb3[15].z + r0.x;
  r0.z = v2.y + v0.x;
  r0.z = v2.x + r0.z;
  r0.yz = frac(r0.yz);
  r0.y = r0.z * 0.5 + r0.y;
  r0.y = -0.300000012 + r0.y;
  o3.z = saturate(cb0[9].w * r0.y);
  r0.y = cmp(v7.w == 0.000000);
  o4.z = r0.y ? v5.z : 2.5;
  r0.y = cb0[8].x * cb0[8].y;
  r0.z = cmp(0 >= r0.y);
  r1.xyz = cb4[0].yyy * cb3[17].xyz;
  r1.xyz = cb3[16].xyz * cb4[0].xxx + r1.xyz;
  r1.xyz = cb3[18].xyz * cb4[0].zzz + r1.xyz;
  r0.w = dot(r1.xyz, r1.xyz);
  r0.w = rsqrt(r0.w);
  r1.xy = r1.xz * r0.ww;
  r0.zw = r0.zz ? float2(0,0) : r1.xy;
  r1.x = cmp(r0.y >= 3);
  if (r1.x != 0) {
    r1.x = cmp(r0.y == 5.000000);
    if (r1.x != 0) {
      r1.xyz = cb4[5].yyy * cb3[17].xyz;
      r1.xyz = cb3[16].xyz * cb4[5].xxx + r1.xyz;
      r1.xyz = cb3[18].xyz * cb4[5].zzz + r1.xyz;
      r1.w = dot(r1.xyz, r1.xyz);
      r1.w = rsqrt(r1.w);
      r1.xyz = r1.xyz * r1.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;
      r1.w = cb4[2].x + r0.x;
      r3.x = v3.w + r1.w;
      r3.y = r1.w * cb4[3].y + v3.w;
      r2.w = cb4[3].y * r3.x;
      r3.z = 0.5 * r2.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;
      r2.w = cmp(r4.w < 0);
      r4.y = -r4.w;
      r4.xz = float2(-1,1);
      r4.xy = r2.ww ? r4.xy : r4.zw;
      r2.w = -r3.y * r3.z + r4.x;
      r2.w = r4.y * r2.w + r4.w;
      r3.y = r4.x + -r2.w;
      r2.w = r4.y * r3.y + r2.w;
      r2.w = cb4[3].x * r2.w;
      r3.y = 1 + -cb4[0].w;
      r3.z = 1 + -cb4[3].x;
      r3.x = r3.x * r3.z;
      r2.w = r2.w * r3.y + r3.x;
      r3.x = r3.w * cb4[4].x + 1;
      r2.w = r3.x * r2.w;
      r2.xyz = r2.xyz * r2.www;
      r2.xyz = r2.xyz * cb4[2].yyy + v0.xyz;
      r3.x = r1.w * 0.100000001 + v3.w;
      r1.w = cb4[15].x * cb4[7].x;
      r3.y = r1.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;
      r1.w = r3.y * r3.x;
      r1.w = -r1.w * cb4[7].x + 1;
      r2.w = cb4[0].w * r3.w;
      r1.w = r2.w * cb4[4].x + r1.w;
      r1.xyz = r1.xyz * cb4[5].www + -r2.xyz;
      r1.xyz = cb4[6].yyy * r1.xyz;
      r1.xyz = r1.xyz * r1.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.x = cb4[2].x + r0.x;
      r3.x = v3.w + r0.x;
      r3.y = r0.x * cb4[3].y + v3.w;
      r0.x = cb4[3].y * r3.x;
      r3.z = 0.5 * r0.x;
      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.x = cmp(r4.w < 0);
      r4.y = -r4.w;
      r4.xz = float2(-1,1);
      r4.xy = r0.xx ? r4.xy : r4.zw;
      r0.x = -r3.y * r3.z + r4.x;
      r0.x = r4.y * r0.x + r4.w;
      r1.w = r4.x + -r0.x;
      r0.x = r4.y * r1.w + r0.x;
      r0.x = cb4[3].x * r0.x;
      r1.w = 1 + -cb4[0].w;
      r2.w = 1 + -cb4[3].x;
      r2.w = r3.x * r2.w;
      r0.x = r0.x * r1.w + r2.w;
      r2.xyz = r2.xyz * r0.xxx;
      r1.xyz = r2.xyz * cb4[2].yyy + v0.xyz;
    }
  } else {
    r1.xyz = v0.xyz;
  }
  r0.x = cmp(0 < r0.y);
  r0.y = dot(r1.xyz, r1.xyz);
  r0.y = sqrt(r0.y);
  r1.w = 1 / cb4[1].z;
  r1.w = -r1.w * 0.25 + r1.y;
  r1.w = max(0, r1.w);
  r1.w = cb4[1].z * r1.w;
  r2.x = cmp(r1.w != 0.000000);
  r2.y = log2(r1.w);
  r2.y = cb4[1].w * r2.y;
  r2.y = exp2(r2.y);
  r1.w = r2.x ? r2.y : r1.w;
  r2.x = cb4[1].x + cb3[15].x;
  r2.y = cb4[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 = cb4[6].x / cb4[1].z;
  r2.x = cb4[1].y * r2.x + r2.y;
  r1.w = r2.x * r1.w;
  r2.xz = r0.zw * r1.ww + r1.xz;
  r2.y = r1.y;
  r0.z = dot(r2.xyz, r2.xyz);
  r0.z = rsqrt(r0.z);
  r2.xyz = r2.xyz * r0.zzz;
  r0.yzw = r2.xyz * r0.yyy;
  r0.xyz = r0.xxx ? r0.yzw : r1.xyz;
  r1.xyzw = cb3[1].xyzw * r0.yyyy;
  r1.xyzw = cb3[0].xyzw * r0.xxxx + r1.xyzw;
  r1.xyzw = cb3[2].xyzw * r0.zzzz + r1.xyzw;
  r1.xyzw = cb3[3].xyzw * v0.wwww + r1.xyzw;
  r2.xyz = cb3[13].xyz * r0.yyy;
  r0.xyw = cb3[12].xyz * r0.xxx + r2.xyz;
  r0.xyz = cb3[14].xyz * r0.zzz + r0.xyw;
  o1.xyz = cb3[15].xyz * v0.www + r0.xyz;

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

  r0.xz = float2(0.5,0.5) * r1.xw;
  r0.y = cb1[5].x * r1.y;
  r0.w = 0.5 * r0.y;
  o5.xy = r0.xw + r0.zz;
  r0.x = cb3[16].x;
  r0.y = cb3[17].x;
  r0.z = cb3[18].x;
  r2.x = cb3[16].y;
  r2.y = cb3[17].y;
  r2.z = cb3[18].y;
  r2.xyz = v2.yyy * r2.xyz;
  r0.xyz = r0.xyz * v2.xxx + r2.xyz;
  r2.x = cb3[16].z;
  r2.y = cb3[17].z;
  r2.z = cb3[18].z;
  r0.xyz = r2.xyz * v2.zzz + r0.xyz;
  r0.w = dot(r0.xyz, r0.xyz);
  r0.w = rsqrt(r0.w);
  r0.xyz = r0.xyz * r0.www;
  r0.w = 1;
  r2.x = dot(cb2[38].xyzw, r0.xyzw);
  r2.y = dot(cb2[39].xyzw, r0.xyzw);
  r2.z = dot(cb2[40].xyzw, r0.xyzw);
  r3.xyzw = r0.xyzz * r0.yzzx;
  r4.x = dot(cb2[41].xyzw, r3.xyzw);
  r4.y = dot(cb2[42].xyzw, r3.xyzw);
  r4.z = dot(cb2[43].xyzw, r3.xyzw);
  r0.y = r0.y * r0.y;
  r0.x = r0.x * r0.x + -r0.y;
  r0.xyz = cb2[44].xyz * r0.xxx + r4.xyz;
  r0.xyz = r2.xyz + r0.xyz;
  r0.w = cmp(cb0[3].w == 0.000000);
  r2.xyz = max(float3(0,0,0), r0.xyz);
  r2.xyz = log2(r2.xyz);
  r2.xyz = float3(0.416666657,0.416666657,0.416666657) * r2.xyz;
  r2.xyz = exp2(r2.xyz);
  r2.xyz = r2.xyz * float3(1.05499995,1.05499995,1.05499995) + float3(-0.0549999997,-0.0549999997,-0.0549999997);
  r2.xyz = max(float3(0,0,0), r2.xyz);
  o7.xyz = r0.www ? r2.xyz : r0.xyz;

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

  o2.w = cb0[10].w;
  o5.zw = r1.zw;
  o6.xyzw = float4(0,0,0,0);
  o3.xy = v3.xy;
  o4.xy = v5.xy;
  return;
}
