// hlsltool.py -I ../112 --auto-fix-vertex-halo --fix-unity-reflection --only-autofixed --no-validate --ignore-other-errors 740f9cb3c6e825cd-vs_replace.txt
// 3DMigoto: 740f9cb3c6e825cd | Matched 2 variants of 1 shaders: Nature/SpeedTree Billboard
//
//       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 6/7 {
//             Name "SHADOWCASTER"
//             Tags { "LIGHTMODE"="SHADOWCASTER" "QUEUE"="AlphaTest" "IGNOREPROJECTOR"="true" "SHADOWSUPPORT"="true" "DisableBatching"="LodFading" "RenderType"="TransparentCutout" }
//             Cull Off
//             GpuProgramID 353647
//             Program "vp" {
//               SubProgram "d3d11 " {
// 1:              GpuProgramIndex 885
// 2:              GpuProgramIndex 893
//               }
//             }
//           }
//         }
//       }
//
//    Unity 5.3 headers extracted from SpeedTreeBillboard.shader.decompressed:
//      API d3d11
//      Shader model vs_4_0
//      undeciphered1: 201509030 133 0 0
// 2:   Keywords { "SHADOWS_DEPTH" "LOD_FADE_CROSSFADE" "BILLBOARD_FACE_CAMERA_POS" "EFFECT_BUMP" "EFFECT_HUE_VARIATION" }
// 1:   Keywords { "SHADOWS_DEPTH" "LOD_FADE_CROSSFADE" "BILLBOARD_FACE_CAMERA_POS" "EFFECT_HUE_VARIATION" }
//      undeciphered2: 1 0 9 0 0
//      undeciphered3: 29 4 0 0 2 1 3 4 4 5
//      ConstBuffer "$Globals" 192
//      Float 132 [_WindQuality]
//      Float 136 [_WindEnabled]
//      Vector 144 [_HueVariation]
//      Vector 160 [_Color]
//      ConstBuffer "UnityPerCamera" 144
//      Vector 80 [_ProjectionParams]
//      Vector 96 [_ScreenParams]
//      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 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 "UnityShadows" 3
//      BindCB "UnityPerDraw" 4
//      BindCB "UnityPerFrame" 5
//      BindCB "SpeedTreeWind" 6
//      BindCB "UnityBillboardPerCamera" 7
//      BindCB "UnityBillboardPerBatch" 8
//
// 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:29:19 2017
cbuffer cb8 : register(b8)
{
  float4 cb8[18];
}

cbuffer cb7 : register(b7)
{
  float4 cb7[3];
}

cbuffer cb6 : register(b6)
{
  float4 cb6[7];
}

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

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

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

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

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

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 : TEXCOORD1,
  out float4 o2 : TEXCOORD2,
  out float4 o3 : TEXCOORD3,
  out float3 o4 : TEXCOORD4)
{
  float4 r0,r1,r2,r3,r4,r5,r6;
  uint4 bitmask, uiDest;
  float4 fDest;

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

  r0.x = cb0[8].y * cb0[8].z;
  r0.x = cmp(0 < r0.x);
  r0.yzw = cb4[15].xyz + v0.xyz;
  r1.x = v2.w + r0.y;
  r1.y = v2.w * 0.800000012 + r0.z;
  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;
  r1.x = r1.y * r1.y + r1.x;
  r1.y = cb6[6].x / cb6[1].z;
  r1.x = cb6[1].y * r1.x + r1.y;
  r1.y = 1 / cb6[1].z;
  r1.z = v1.y * cb8[1].y + cb8[1].z;
  r2.y = v2.y * r1.z;
  r1.y = -r1.y * 0.25 + r2.y;
  r1.y = max(0, r1.y);
  r1.y = cb6[1].z * r1.y;
  r1.z = log2(r1.y);
  r1.z = cb6[1].w * r1.z;
  r1.z = exp2(r1.z);
  r1.w = cmp(r1.y != 0.000000);
  r1.y = r1.w ? r1.z : r1.y;
  r1.x = r1.x * r1.y;
  r1.y = -0.5 + v1.x;
  r1.y = cb8[1].x * r1.y;
  r1.y = v2.x * r1.y;
  r3.xyz = cb7[2].xyz + -r0.yzw;
  r1.z = dot(r3.xyz, r3.xyz);
  r1.z = rsqrt(r1.z);
  r3.xy = r3.xz * r1.zz;
  r3.zw = -r3.yy;
  r1.z = dot(r3.xz, r3.xw);
  r3.xy = float2(-1,1) * r3.yx;
  r1.z = rsqrt(r1.z);
  r1.zw = r3.xy * r1.zz;
  r2.xz = r1.yy * r1.zw;
  r3.xz = cb6[0].xz * r1.xx + r2.xz;
  r3.y = r2.y;
  r1.x = dot(r3.xyz, r3.xyz);
  r1.x = rsqrt(r1.x);
  r3.xyz = r3.xyz * r1.xxx;
  r1.x = dot(r2.xyz, r2.xyz);
  r1.x = sqrt(r1.x);
  r3.xyz = r3.xyz * r1.xxx;
  r2.xyz = r0.xxx ? r3.xyz : r2.xyz;
  r2.xyz = v0.xyz + r2.xyz;
  r3.xyz = cb4[13].xyz * r2.yyy;
  r3.xyz = cb4[12].xyz * r2.xxx + r3.xyz;
  r3.xyz = cb4[14].xyz * r2.zzz + r3.xyz;
  r3.xyz = cb4[15].xyz + r3.xyz;
  r4.xyz = -r3.xyz * cb2[0].www + cb2[0].xyz;
  r0.x = dot(r4.xyz, r4.xyz);
  r0.x = rsqrt(r0.x);
  r4.xyz = r4.xyz * r0.xxx;
  r5.x = cb4[16].x * r1.w;
  r5.y = cb4[17].x * r1.w;
  r5.z = cb4[18].x * r1.w;
  r6.x = cb4[16].z * -r1.z;
  r6.y = cb4[17].z * -r1.z;
  r6.z = cb4[18].z * -r1.z;
  r5.xyz = r6.xyz + r5.xyz;
  r0.x = dot(r5.xyz, r5.xyz);
  r0.x = rsqrt(r0.x);
  r5.xyz = r5.xyz * r0.xxx;
  r0.x = dot(r5.xyz, r4.xyz);
  r0.x = -r0.x * r0.x + 1;
  r0.x = sqrt(r0.x);
  r0.x = cb3[5].z * r0.x;
  r4.xyz = -r5.xyz * r0.xxx + r3.xyz;
  o1.xyz = r3.xyz;
  r3.xyzw = cb5[10].xyzw * r4.yyyy;
  r3.xyzw = cb5[9].xyzw * r4.xxxx + r3.xyzw;
  r3.xyzw = cb5[11].xyzw * r4.zzzz + r3.xyzw;
  r3.xyzw = cb5[12].xyzw + r3.xyzw;
  r4.xyzw = cb4[1].xyzw * r2.yyyy;
  r4.xyzw = cb4[0].xyzw * r2.xxxx + r4.xyzw;
  r4.xyzw = cb4[2].xyzw * r2.zzzz + r4.xyzw;
  r4.xyzw = cb4[3].xyzw + r4.xyzw;
  r0.x = cmp(cb3[5].z != 0.000000);
  r3.xyzw = r0.xxxx ? r3.xyzw : r4.xyzw;

o0.xyw = r3.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 740f9cb3c6e825cd-vs_replace.txt
if (r3.w != 1.0) { r3.x += separation * (r3.w - convergence); }

  r0.x = saturate(cb3[5].x / r3.w);
  r0.x = r3.z + r0.x;

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

  r1.x = max(0, r0.x);
  r1.x = r1.x + -r0.x;
  o0.z = cb3[5].y * r1.x + r0.x;
  o2.xyzw = cb0[10].xyzw;
  r0.x = r0.y + r0.z;
  r0.x = r0.x + r0.w;
  r0.x = frac(r0.x);
  o3.z = saturate(cb0[9].w * r0.x);
  r0.x = max(abs(r1.z), abs(r1.w));
  r0.x = 1 / r0.x;
  r0.y = min(abs(r1.z), abs(r1.w));
  r0.x = r0.y * r0.x;
  r0.y = r0.x * r0.x;
  r0.z = r0.y * 0.0208350997 + -0.0851330012;
  r0.z = r0.y * r0.z + 0.180141002;
  r0.z = r0.y * r0.z + -0.330299497;
  r0.y = r0.y * r0.z + 0.999866009;
  r0.z = r0.x * r0.y;
  r0.z = r0.z * -2 + 1.57079637;
  r0.w = cmp(abs(r1.w) < abs(r1.z));
  r0.z = r0.w ? r0.z : 0;
  r0.x = r0.x * r0.y + r0.z;
  r0.y = cmp(r1.w < -r1.w);
  r0.y = r0.y ? -3.141593 : 0;
  r0.x = r0.x + r0.y;
  r0.y = min(-r1.z, r1.w);
  r0.z = max(-r1.z, r1.w);
  r0.z = cmp(r0.z >= -r0.z);
  r0.y = cmp(r0.y < -r0.y);
  r0.y = r0.z ? r0.y : 0;
  r0.x = r0.y ? -r0.x : r0.x;
  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 * cb8[0].y + 0.5;
  r0.x = floor(r0.x);
  r0.x = r0.x / cb8[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 = cb8[0].x * r0.x;
  r0.x = (uint)r0.x;
  r0.y = cmp(cb8[r0.x+2].w < 0);
  r0.zw = -cb8[r0.x+2].zw * v1.yx + cb8[r0.x+2].xy;
  r1.xy = cb8[r0.x+2].zw * v1.xy + cb8[r0.x+2].xy;
  o3.xy = r0.yy ? r0.zw : r1.xy;
  r0.xyz = cb4[1].xyw * r2.yyy;
  r0.xyz = cb4[0].xyw * r2.xxx + r0.xyz;
  r0.xyz = cb4[2].xyw * r2.zzz + r0.xyz;
  r0.xyz = cb4[3].xyw + r0.xyz;
  r1.xz = float2(0.5,0.5) * r0.xz;
  r0.x = cb1[5].x * r0.y;
  o4.z = r0.z;
  r1.w = 0.5 * r0.x;
  r0.xy = r1.xw + r1.zz;
  r0.zw = float2(0.25,0.25) * cb1[6].xy;
  o4.xy = r0.xy * r0.zw;
  return;
}
