// hlsltool.py -I ../112 --auto-fix-vertex-halo --fix-unity-reflection --only-autofixed --no-validate --ignore-other-errors 030c9c38a941e478-vs_replace.txt
// 3DMigoto: 030c9c38a941e478 |    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 35
//            }
//          }
//        }
//      }
//    }
//
// Unity 5.3 headers extracted from SpeedTreeBillboard.shader.decompressed:
//   API d3d11
//   Shader model vs_4_0
//   undeciphered1: 201509030 111 0 0
//   Keywords { "DIRECTIONAL" "SHADOWS_SCREEN" "LIGHTMAP_OFF" "DIRLIGHTMAP_OFF" "DYNAMICLIGHTMAP_OFF" "BILLBOARD_FACE_CAMERA_POS" }
//   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 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:24:03 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,r4;
  uint4 bitmask, uiDest;
  float4 fDest;

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

  r0.xyz = cb3[15].xyz + v0.xyz;
  r1.x = v2.w + r0.x;
  r1.y = v2.w * 0.800000012 + r0.y;
  r0.xyz = cb5[2].xyz + -r0.xyz;
  r1.xy = float2(0.5,0.5) + r1.xy;
  r1.xy = frac(r1.xy);
  r1.xy = r1.xy * float2(2,2) + float2(-1,-1);
  r1.zw = abs(r1.xy) * abs(r1.xy);
  r1.xy = -abs(r1.xy) * float2(2,2) + float2(3,3);
  r1.xy = r1.zw * r1.xy + float2(-0.5,-0.5);
  r1.xy = r1.xy + r1.xy;
  r0.w = r1.y * r1.y + r1.x;
  r1.x = cb4[6].x / cb4[1].z;
  r0.w = cb4[1].y * r0.w + r1.x;
  r1.x = 1 / cb4[1].z;
  r1.y = v1.y * cb6[1].y + cb6[1].z;
  r2.y = v2.y * r1.y;
  r1.x = -r1.x * 0.25 + r2.y;
  r1.x = max(0, r1.x);
  r1.x = cb4[1].z * r1.x;
  r1.y = log2(r1.x);
  r1.y = cb4[1].w * r1.y;
  r1.y = exp2(r1.y);
  r1.z = cmp(r1.x != 0.000000);
  r1.x = r1.z ? r1.y : r1.x;
  r0.w = r1.x * r0.w;
  r1.x = -0.5 + v1.x;
  r1.x = cb6[1].x * r1.x;
  r1.x = v2.x * r1.x;
  r0.y = dot(r0.xyz, r0.xyz);
  r0.y = rsqrt(r0.y);
  r3.xy = r0.xz * r0.yy;
  r3.zw = -r3.yy;
  r0.x = dot(r3.xz, r3.xw);
  r0.yz = float2(-1,1) * r3.yx;
  r0.x = rsqrt(r0.x);
  r0.xy = r0.yz * r0.xx;
  r2.xz = r1.xx * r0.xy;
  r1.xz = cb4[0].xz * r0.ww + r2.xz;
  r1.y = r2.y;
  r0.z = dot(r1.xyz, r1.xyz);
  r0.z = rsqrt(r0.z);
  r1.xyz = r1.xyz * r0.zzz;
  r0.z = dot(r2.xyz, r2.xyz);
  r0.z = sqrt(r0.z);
  r1.xyz = r1.xyz * r0.zzz;
  r0.z = cb0[8].y * cb0[8].z;
  r0.z = cmp(0 < r0.z);
  r1.xyz = r0.zzz ? r1.xyz : r2.xyz;
  r1.xyz = v0.xyz + r1.xyz;
  r2.xyzw = cb3[1].xyzw * r1.yyyy;
  r2.xyzw = cb3[0].xyzw * r1.xxxx + r2.xyzw;
  r2.xyzw = cb3[2].xyzw * r1.zzzz + r2.xyzw;
  r2.xyzw = cb3[3].xyzw + r2.xyzw;
  o0.xyzw = r2.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 030c9c38a941e478-vs_replace.txt
if (r2.w != 1.0) { r2.x += separation * (r2.w - convergence); }

  r3.x = cb3[16].x * r0.y;
  r3.y = cb3[17].x * r0.y;
  r3.z = cb3[18].x * r0.y;
  r4.x = cb3[16].z * -r0.x;
  r4.y = cb3[17].z * -r0.x;
  r4.z = cb3[18].z * -r0.x;
  r3.xyz = r4.xyz + r3.xyz;
  r0.z = dot(r3.xyz, r3.xyz);
  r0.z = rsqrt(r0.z);
  r3.xyz = r3.xyz * r0.zzz;
  o1.xyz = r3.xyz;
  r4.xyz = cb3[13].xyz * r1.yyy;
  r1.xyw = cb3[12].xyz * r1.xxx + r4.xyz;
  r1.xyz = cb3[14].xyz * r1.zzz + r1.xyw;
  o2.xyz = cb3[15].xyz + r1.xyz;
  o3.xyzw = cb0[9].xyzw;
  r0.z = max(abs(r0.x), abs(r0.y));
  r0.z = 1 / r0.z;
  r0.w = min(abs(r0.x), abs(r0.y));
  r0.z = r0.w * r0.z;
  r0.w = r0.z * r0.z;
  r1.x = r0.w * 0.0208350997 + -0.0851330012;
  r1.x = r0.w * r1.x + 0.180141002;
  r1.x = r0.w * r1.x + -0.330299497;
  r0.w = r0.w * r1.x + 0.999866009;
  r1.x = r0.z * r0.w;
  r1.x = r1.x * -2 + 1.57079637;
  r1.y = cmp(abs(r0.y) < abs(r0.x));
  r1.x = r1.y ? r1.x : 0;
  r0.z = r0.z * r0.w + r1.x;
  r0.w = cmp(r0.y < -r0.y);
  r0.w = r0.w ? -3.141593 : 0;
  r0.z = r0.z + r0.w;
  r0.w = min(-r0.x, r0.y);
  r0.x = max(-r0.x, r0.y);
  r0.x = cmp(r0.x >= -r0.x);
  r0.y = cmp(r0.w < -r0.w);
  r0.x = r0.x ? r0.y : 0;
  r0.x = r0.x ? -r0.z : r0.z;
  r0.y = cmp(r0.x < 0);
  r0.y = r0.y ? 6.283185 : 0;
  r0.x = r0.x + r0.y;
  r0.x = v2.z + r0.x;
  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;
  r1.xy = cb6[r0.x+2].zw * v1.xy + cb6[r0.x+2].xy;
  o4.xy = r0.yy ? r0.zw : r1.xy;
  o4.z = 0;
  r0.x = r3.y * r3.y;
  r0.x = r3.x * r3.x + -r0.x;
  r1.xyzw = r3.xyzz * r3.yzzx;
  r3.x = dot(cb2[41].xyzw, r1.xyzw);
  r3.y = dot(cb2[42].xyzw, r1.xyzw);
  r3.z = dot(cb2[43].xyzw, r1.xyzw);
  o5.xyz = cb2[44].xyz * r0.xxx + r3.xyz;
  r0.x = cb1[5].x * r2.y;
  r0.w = 0.5 * r0.x;
  r0.xz = float2(0.5,0.5) * r2.xw;
  o6.zw = r2.zw;
  o6.xy = r0.xw + r0.zz;
  return;
}
