// hlsltool.py -I ../112 --auto-fix-vertex-halo --fix-unity-reflection --only-autofixed --no-validate --ignore-other-errors 8d642175e35bc88d-vs_replace.txt
// 3DMigoto: 8d642175e35bc88d |    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 31
//            }
//          }
//        }
//      }
//    }
//
// Unity 5.3 headers extracted from SpeedTreeBillboard.shader.decompressed:
//   API d3d11
//   Shader model vs_4_0
//   undeciphered1: 201509030 118 0 0
//   Keywords { "DIRECTIONAL" "SHADOWS_SCREEN" "LIGHTMAP_OFF" "DIRLIGHTMAP_OFF" "DYNAMICLIGHTMAP_OFF" "VERTEXLIGHT_ON" "EFFECT_BUMP" "EFFECT_HUE_VARIATION" }
//   undeciphered2: 1 0 7 0 0
//   undeciphered3: 29 4 0 0 2 1 3 4 4 5
//   ConstBuffer "$Globals" 192
//   Vector 48 [unity_ColorSpaceLuminance]
//   Float 132 [_WindQuality]
//   Float 136 [_WindEnabled]
//   Vector 144 [_HueVariation]
//   Vector 160 [_Color]
//   ConstBuffer "UnityPerCamera" 144
//   Vector 80 [_ProjectionParams]
//   ConstBuffer "UnityLighting" 720
//   Vector 32 [unity_4LightPosX0]
//   Vector 48 [unity_4LightPosY0]
//   Vector 64 [unity_4LightPosZ0]
//   Vector 80 [unity_4LightAtten0]
//   Vector 96 [unity_LightColor0]
//   Vector 112 [unity_LightColor1]
//   Vector 128 [unity_LightColor2]
//   Vector 144 [unity_LightColor3]
//   Vector 160 [unity_LightColor4]
//   Vector 176 [unity_LightColor5]
//   Vector 192 [unity_LightColor6]
//   Vector 208 [unity_LightColor7]
//   Vector 656 [unity_SHBr]
//   Vector 672 [unity_SHBg]
//   Vector 688 [unity_SHBb]
//   Vector 704 [unity_SHC]
//   ConstBuffer "UnityPerDraw" 352
//   Vector 336 [unity_WorldTransformParams]
//   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:30:28 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[22];
}

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 : 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,
  out float4 o7 : TEXCOORD6)
{
  float4 r0,r1,r2,r3,r4,r5;
  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;
  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;
  r1.z = -0.5 + v1.x;
  r1.z = cb6[1].x * r1.z;
  r1.z = v2.x * r1.z;
  r2.xyz = cb5[1].xyz * r1.zzz;
  r2.w = r1.y * v2.y + r2.y;
  r1.x = -r1.x * 0.25 + r2.w;
  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.xz = cb4[0].xz * r0.ww + r2.xz;
  r1.y = r2.w;
  r0.w = dot(r1.xyz, r1.xyz);
  r0.w = rsqrt(r0.w);
  r1.xyz = r1.xyz * r0.www;
  r0.w = dot(r2.xzw, r2.xzw);
  r0.w = sqrt(r0.w);
  r1.xyz = r1.xyz * r0.www;
  r0.w = cb0[8].y * cb0[8].z;
  r0.w = cmp(0 < r0.w);
  r1.xyz = r0.www ? r1.xyz : r2.xwz;
  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 8d642175e35bc88d-vs_replace.txt
if (r2.w != 1.0) { r2.x += separation * (r2.w - convergence); }

  r3.xyz = cb3[13].xyz * r1.yyy;
  r1.xyw = cb3[12].xyz * r1.xxx + r3.xyz;
  r1.xyz = cb3[14].xyz * r1.zzz + r1.xyw;
  r1.xyz = cb3[15].xyz + r1.xyz;
  o1.w = r1.x;
  r3.xyz = cb5[1].yyy * cb3[13].yzx;
  r3.xyz = cb3[12].yzx * cb5[1].xxx + r3.xyz;
  r3.xyz = cb3[14].yzx * cb5[1].zzz + r3.xyz;
  r0.w = dot(r3.xyz, r3.xyz);
  r0.w = rsqrt(r0.w);
  r3.xyz = r3.xyz * r0.www;
  r4.x = cb5[0].x * cb3[16].x;
  r4.y = cb5[0].x * cb3[17].x;
  r4.zw = cb5[0].xx * cb3[18].xx;
  r5.x = cb5[0].y * cb3[16].y;
  r5.y = cb5[0].y * cb3[17].y;
  r5.zw = cb5[0].yy * cb3[18].yy;
  r4.xyzw = r5.xyzw + r4.xyzw;
  r5.x = cb5[0].z * cb3[16].z;
  r5.y = cb5[0].z * cb3[17].z;
  r5.zw = cb5[0].zz * cb3[18].zz;
  r4.xyzw = r5.xyzw + r4.xyzw;
  r0.w = dot(r4.xyw, r4.xyw);
  r0.w = rsqrt(r0.w);
  r4.xyzw = r4.xyzw * r0.wwww;
  r5.xyz = r4.wxy * r3.xyz;
  r5.xyz = r4.ywx * r3.yzx + -r5.xyz;
  r5.xyz = -cb3[21].www * r5.xyz;
  o1.y = r5.x;
  o1.x = r3.z;
  o1.z = r4.x;
  o2.x = r3.x;
  o3.x = r3.y;
  o2.w = r1.y;
  o2.z = r4.y;
  o2.y = r5.y;
  o3.y = r5.z;
  o3.w = r1.z;
  o3.z = r4.w;
  o4.xyzw = cb0[10].xyzw;
  r0.x = r0.x + r0.y;
  r0.x = r0.x + r0.z;
  r0.x = frac(r0.x);
  o5.z = saturate(cb0[9].w * r0.x);
  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;
  o5.xy = r0.yy ? r0.zw : r3.xy;
  r0.xyzw = cb2[2].xyzw + -r1.xxxx;
  r3.xyzw = cb2[3].xyzw + -r1.yyyy;
  r1.xyzw = cb2[4].xyzw + -r1.zzzz;
  r5.xyzw = r3.xyzw * r4.yyyy;
  r3.xyzw = r3.xyzw * r3.xyzw;
  r3.xyzw = r0.xyzw * r0.xyzw + r3.xyzw;
  r0.xyzw = r0.xyzw * r4.xxxx + r5.xyzw;
  r0.xyzw = r1.xyzw * r4.wwzw + r0.xyzw;
  r1.xyzw = r1.xyzw * r1.xyzw + r3.xyzw;
  r3.xyzw = rsqrt(r1.xyzw);
  r1.xyzw = r1.xyzw * cb2[5].xyzw + float4(1,1,1,1);
  r1.xyzw = float4(1,1,1,1) / r1.xyzw;
  r0.xyzw = r3.xyzw * r0.xyzw;
  r0.xyzw = max(float4(0,0,0,0), r0.xyzw);
  r0.xyzw = r0.xyzw * r1.xyzw;
  r1.xyz = cb2[7].xyz * r0.yyy;
  r1.xyz = cb2[6].xyz * r0.xxx + r1.xyz;
  r0.xyz = cb2[8].xyz * r0.zzz + r1.xyz;
  r0.xyz = cb2[9].xyz * r0.www + r0.xyz;
  r1.xyz = r0.xyz * float3(0.305306017,0.305306017,0.305306017) + float3(0.682171106,0.682171106,0.682171106);
  r1.xyz = r0.xyz * r1.xyz + float3(0.0125228781,0.0125228781,0.0125228781);
  r1.xyz = r1.xyz * r0.xyz;
  r0.w = cmp(cb0[3].w == 0.000000);
  r0.xyz = r0.www ? r1.xyz : r0.xyz;
  r0.w = r4.y * r4.y;
  r0.w = r4.x * r4.x + -r0.w;
  r1.xyzw = r4.xyzw * r4.ywzx;
  r3.x = dot(cb2[41].xyzw, r1.xyzw);
  r3.y = dot(cb2[42].xyzw, r1.xyzw);
  r3.z = dot(cb2[43].xyzw, r1.xyzw);
  r1.xyz = cb2[44].xyz * r0.www + r3.xyz;
  o6.xyz = r1.xyz + r0.xyz;
  r0.x = cb1[5].x * r2.y;
  r0.w = 0.5 * r0.x;
  r0.xz = float2(0.5,0.5) * r2.xw;
  o7.zw = r2.zw;
  o7.xy = r0.xw + r0.zz;
  return;
}
