// hlsltool.py -I ../112 --auto-fix-vertex-halo --fix-unity-reflection --only-autofixed --no-validate --ignore-other-errors a564ca75a9113938-vs_replace.txt
// 3DMigoto: a564ca75a9113938 |    Unity headers extracted from SpeedTreeBillboard.shader
//    Shader "Nature/SpeedTree Billboard" {
//      Properties {
//       _Color ("Main Color", Color) = (1,1,1,1)
//       _SpecColor ("Specular Color", Color) = (0.5,0.5,0.5,0)
//       _HueVariation ("Hue Variation", Color) = (1,0.5,0,0.1)
//       _Shininess ("Shininess", Range(0.01,1)) = 0.078125
//       _MainTex ("Base (RGB)", 2D) = "white" { }
//       _BumpMap ("Normalmap", 2D) = "bump" { }
//       _Cutoff ("Alpha cutoff", Range(0,1)) = 0.5
//      [MaterialEnum(None,0,Fastest,1)]  _WindQuality ("Wind Quality", Range(0,1)) = 0
//      }
//      Fallback "Transparent/Cutout/VertexLit"
//      SubShader 1/2 {
//        LOD 400
//        Tags { "QUEUE"="AlphaTest" "IGNOREPROJECTOR"="true" "DisableBatching"="LodFading" "RenderType"="TransparentCutout" }
//        Pass 1/7 {
//          Name "FORWARD"
//          Tags { "LIGHTMODE"="ForwardBase" "QUEUE"="AlphaTest" "IGNOREPROJECTOR"="true" "SHADOWSUPPORT"="true" "DisableBatching"="LodFading" "RenderType"="TransparentCutout" }
//          Cull Off
//          GpuProgramID 19329
//          Program "vp" {
//            SubProgram "d3d11 " {
//              GpuProgramIndex 3
//            }
//          }
//        }
//      }
//    }
//
// Unity 5.3 headers extracted from SpeedTreeBillboard.shader.decompressed:
//   API d3d11
//   Shader model vs_4_0
//   undeciphered1: 201509030 81 0 0
//   Keywords { "DIRECTIONAL" "SHADOWS_SCREEN" "LIGHTMAP_OFF" "DIRLIGHTMAP_OFF" "DYNAMICLIGHTMAP_OFF" }
//   undeciphered2: 1 0 7 0 0
//   undeciphered3: 29 4 0 0 2 1 3 4 4 5
//   ConstBuffer "$Globals" 176
//   Float 132 [_WindQuality]
//   Float 136 [_WindEnabled]
//   Vector 144 [_Color]
//   ConstBuffer "UnityPerCamera" 144
//   Vector 80 [_ProjectionParams]
//   ConstBuffer "UnityLighting" 720
//   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 96 [_ST_WindBranchAdherences]
//   ConstBuffer "UnityBillboardPerCamera" 48
//   Vector 0 [unity_BillboardNormal] 3
//   Vector 16 [unity_BillboardTangent] 3
//   Vector 32 [unity_BillboardCameraParams]
//   ConstBuffer "UnityBillboardPerBatch" 288
//   Vector 0 [unity_BillboardInfo]
//   Vector 16 [unity_BillboardSize]
//   Vector 32 [unity_BillboardImageTexCoords0]
//   Vector 48 [unity_BillboardImageTexCoords1]
//   Vector 64 [unity_BillboardImageTexCoords2]
//   Vector 80 [unity_BillboardImageTexCoords3]
//   Vector 96 [unity_BillboardImageTexCoords4]
//   Vector 112 [unity_BillboardImageTexCoords5]
//   Vector 128 [unity_BillboardImageTexCoords6]
//   Vector 144 [unity_BillboardImageTexCoords7]
//   Vector 160 [unity_BillboardImageTexCoords8]
//   Vector 176 [unity_BillboardImageTexCoords9]
//   Vector 192 [unity_BillboardImageTexCoords10]
//   Vector 208 [unity_BillboardImageTexCoords11]
//   Vector 224 [unity_BillboardImageTexCoords12]
//   Vector 240 [unity_BillboardImageTexCoords13]
//   Vector 256 [unity_BillboardImageTexCoords14]
//   Vector 272 [unity_BillboardImageTexCoords15]
//   BindCB "$Globals" 0
//   BindCB "UnityPerCamera" 1
//   BindCB "UnityLighting" 2
//   BindCB "UnityPerDraw" 3
//   BindCB "SpeedTreeWind" 4
//   BindCB "UnityBillboardPerCamera" 5
//   BindCB "UnityBillboardPerBatch" 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.38 on Thu Feb 09 12:31:35 2017
cbuffer cb6 : register(b6)
{
  float4 cb6[18];
}

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

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

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[10];
}




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


void main( 
  float4 v0 : POSITION0,
  float4 v1 : TEXCOORD0,
  float4 v2 : TEXCOORD1,
  float3 v3 : NORMAL0,
  float4 v4 : TANGENT0,
  float4 v5 : 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)
{
  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.xy = cb3[15].xy + v0.xy;
  r1.x = v2.w + r0.x;
  r1.y = v2.w * 0.800000012 + r0.y;
  r0.xy = float2(0.5,0.5) + r1.xy;
  r0.xy = frac(r0.xy);
  r0.xy = r0.xy * float2(2,2) + float2(-1,-1);
  r0.zw = abs(r0.xy) * abs(r0.xy);
  r0.xy = -abs(r0.xy) * float2(2,2) + float2(3,3);
  r0.xy = r0.zw * r0.xy + float2(-0.5,-0.5);
  r0.xy = r0.xy + r0.xy;
  r0.x = r0.y * r0.y + r0.x;
  r0.y = cb4[6].x / cb4[1].z;
  r0.x = cb4[1].y * r0.x + r0.y;
  r0.y = 1 / cb4[1].z;
  r0.z = v1.y * cb6[1].y + cb6[1].z;
  r0.w = -0.5 + v1.x;
  r0.w = cb6[1].x * r0.w;
  r0.w = v2.x * r0.w;
  r1.xyz = cb5[1].xyz * r0.www;
  r1.w = r0.z * v2.y + r1.y;
  r0.y = -r0.y * 0.25 + r1.w;
  r0.y = max(0, r0.y);
  r0.y = cb4[1].z * r0.y;
  r0.z = log2(r0.y);
  r0.z = cb4[1].w * r0.z;
  r0.z = exp2(r0.z);
  r0.w = cmp(r0.y != 0.000000);
  r0.y = r0.w ? r0.z : r0.y;
  r0.x = r0.x * r0.y;
  r0.xz = cb4[0].xz * r0.xx + r1.xz;
  r0.y = r1.w;
  r0.w = dot(r0.xyz, r0.xyz);
  r0.w = rsqrt(r0.w);
  r0.xyz = r0.xyz * r0.www;
  r0.w = dot(r1.xzw, r1.xzw);
  r0.w = sqrt(r0.w);
  r0.xyz = r0.xyz * r0.www;
  r0.w = cb0[8].y * cb0[8].z;
  r0.w = cmp(0 < r0.w);
  r0.xyz = r0.www ? r0.xyz : r1.xwz;
  r0.xyz = v0.xyz + r0.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 + r1.xyzw;
  o0.xyzw = r1.xyzw;

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

  r2.x = cb5[0].x * cb3[16].x;
  r2.y = cb5[0].x * cb3[17].x;
  r2.z = cb5[0].x * cb3[18].x;
  r3.x = cb5[0].y * cb3[16].y;
  r3.y = cb5[0].y * cb3[17].y;
  r3.z = cb5[0].y * cb3[18].y;
  r2.xyz = r3.xyz + r2.xyz;
  r3.x = cb5[0].z * cb3[16].z;
  r3.y = cb5[0].z * cb3[17].z;
  r3.z = cb5[0].z * cb3[18].z;
  r2.xyz = r3.xyz + r2.xyz;
  r0.w = dot(r2.xyz, r2.xyz);
  r0.w = rsqrt(r0.w);
  r2.xyz = r2.xyz * r0.www;
  o1.xyz = r2.xyz;
  r3.xyz = cb3[13].xyz * r0.yyy;
  r0.xyw = cb3[12].xyz * r0.xxx + r3.xyz;
  r0.xyz = cb3[14].xyz * r0.zzz + r0.xyw;
  o2.xyz = cb3[15].xyz + r0.xyz;
  o3.xyzw = cb0[9].xyzw;
  r0.x = cb5[2].w + v2.z;
  r0.x = r0.x * cb6[0].y + 0.5;
  r0.x = floor(r0.x);
  r0.x = r0.x / cb6[0].x;
  r0.y = cmp(r0.x >= -r0.x);
  r0.x = frac(abs(r0.x));
  r0.x = r0.y ? r0.x : -r0.x;
  r0.x = cb6[0].x * r0.x;
  r0.x = (uint)r0.x;
  r0.y = cmp(cb6[r0.x+2].w < 0);
  r0.zw = -cb6[r0.x+2].zw * v1.yx + cb6[r0.x+2].xy;
  r3.xy = cb6[r0.x+2].zw * v1.xy + cb6[r0.x+2].xy;
  o4.xy = r0.yy ? r0.zw : r3.xy;
  o4.z = 0;
  r0.x = r2.y * r2.y;
  r0.x = r2.x * r2.x + -r0.x;
  r2.xyzw = r2.xyzz * r2.yzzx;
  r3.x = dot(cb2[41].xyzw, r2.xyzw);
  r3.y = dot(cb2[42].xyzw, r2.xyzw);
  r3.z = dot(cb2[43].xyzw, r2.xyzw);
  o5.xyz = cb2[44].xyz * r0.xxx + r3.xyz;
  r0.x = cb1[5].x * r1.y;
  r0.w = 0.5 * r0.x;
  r0.xz = float2(0.5,0.5) * r1.xw;
  o6.zw = r1.zw;
  o6.xy = r0.xw + r0.zz;
  return;
}
