// hlsltool.py -I ../112 --auto-fix-vertex-halo --fix-unity-reflection --only-autofixed --no-validate --ignore-other-errors 219f5cef623b6012-vs_replace.txt
// 3DMigoto: 219f5cef623b6012 |    Unity headers extracted from TreeCreatorBarkOptimized.shader
//    Shader "Hidden/Nature/Tree Creator Bark Optimized" {
//      Properties {
//       _Color ("Main Color", Color) = (1,1,1,1)
//       _MainTex ("Base (RGB) Alpha (A)", 2D) = "white" { }
//       _BumpSpecMap ("Normalmap (GA) Spec (R)", 2D) = "bump" { }
//       _TranslucencyMap ("Trans (RGB) Gloss(A)", 2D) = "white" { }
//       _SpecColor ("Specular Color", Color) = (0.5,0.5,0.5,1)
//      [HideInInspector]  _TreeInstanceColor ("TreeInstanceColor", Vector) = (1,1,1,1)
//      [HideInInspector]  _TreeInstanceScale ("TreeInstanceScale", Vector) = (1,1,1,1)
//      [HideInInspector]  _SquashAmount ("Squash", Float) = 1
//      }
//      Dependency "BillboardShader" = "Hidden/Nature/Tree Creator Bark Rendertex"
//      SubShader 1/1 {
//        LOD 200
//        Tags { "IGNOREPROJECTOR"="true" "RenderType"="TreeBark" }
//        Pass 1/6 {
//          Name "FORWARD"
//          Tags { "LIGHTMODE"="ForwardBase" "IGNOREPROJECTOR"="true" "SHADOWSUPPORT"="true" "RenderType"="TreeBark" }
//          GpuProgramID 44852
//          Program "vp" {
//            SubProgram "d3d11_9x " {
//              GpuProgramIndex 5
//            }
//          }
//        }
//      }
//    }
//
// Unity 5.3 headers extracted from TreeCreatorBarkOptimized.shader.decompressed:
//   API d3d11_9x
//   Shader model vs_4_0_level_9_1
//   undeciphered1: 201509030 89 0 0
//   Keywords { "DIRECTIONAL" "SHADOWS_SCREEN" "LIGHTMAP_OFF" "DIRLIGHTMAP_OFF" "DYNAMICLIGHTMAP_OFF" }
//   undeciphered2: 1 0 5 0 0
//   undeciphered3: 159 6 0 0 2 1 1 2 3 4 4 5 7 8
//   ConstBuffer "$Globals" 208
//   Vector 128 [_Wind]
//   Vector 144 [_Color]
//   Vector 192 [_MainTex_ST]
//   ConstBuffer "UnityPerCamera" 144
//   Vector 0 [_Time]
//   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
//   Vector 336 [unity_WorldTransformParams]
//   Matrix 0 [glstate_matrix_mvp]
//   Matrix 192 [_Object2World]
//   Matrix 256 [_World2Object]
//   ConstBuffer "UnityTerrain" 272
//   Vector 80 [_TreeInstanceColor]
//   Vector 96 [_TreeInstanceScale]
//   Vector 176 [_SquashPlaneNormal]
//   Float 192 [_SquashAmount]
//   BindCB "$Globals" 0
//   BindCB "UnityPerCamera" 1
//   BindCB "UnityLighting" 2
//   BindCB "UnityPerDraw" 3
//   BindCB "UnityTerrain" 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:25:24 2017
cbuffer cb4 : register(b4)
{
  float4 cb4[13];
}

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




// 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,
  float4 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 : COLOR0,
  out float4 o6 : TEXCOORD4,
  out float4 o7 : TEXCOORD5)
{
  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.x = cb3[12].w;
  r0.y = cb3[13].w;
  r0.z = cb3[14].w;
  r0.x = dot(r0.xyz, float3(1,1,1));
  r0.y = v7.x + r0.x;
  r0.z = v7.y + r0.y;
  r1.xyz = cb4[6].xyz * v0.xyz;
  r0.x = dot(r1.xyz, r0.zzz);
  r0.xyzw = cb1[0].yyyy + r0.xxyy;
  r0.xyzw = float4(1.97500002,0.792999983,0.375,0.193000004) * r0.xyzw;
  r0.xyzw = frac(r0.xyzw);
  r0.xyzw = r0.xyzw * float4(2,2,2,2) + float4(-0.5,-0.5,-0.5,-0.5);
  r0.xyzw = frac(r0.xyzw);
  r0.xyzw = r0.xyzw * float4(2,2,2,2) + float4(-1,-1,-1,-1);
  r2.xyzw = abs(r0.xyzw) * abs(r0.xyzw);
  r0.xyzw = -abs(r0.xyzw) * float4(2,2,2,2) + float4(3,3,3,3);
  r0.xyzw = r2.xyzw * r0.xyzw;
  r0.xy = r0.xz + r0.yw;
  r2.xyz = cb0[8].xyz * r0.yyy;
  r2.xyz = v4.yyy * r2.xyz;
  r3.y = v4.y * r0.y;
  r0.y = 0.100000001 * v7.y;
  r3.xz = v2.xz * r0.yy;
  r0.z = 0.300000012;
  r0.xyz = r0.xzx * r3.xyz + r2.xyz;
  r0.xyz = r0.xyz * cb0[8].www + r1.xyz;
  r0.xyz = v4.xxx * cb0[8].xyz + r0.xyz;
  r0.w = dot(cb4[11].xyz, r0.xyz);
  r0.w = cb4[11].w + r0.w;
  r1.xyz = -r0.www * cb4[11].xyz + r0.xyz;
  r0.xyz = -r1.xyz + r0.xyz;
  r0.xyz = cb4[12].xxx * r0.xyz + 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 + 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 219f5cef623b6012-vs_replace.txt
if (r1.w != 1.0) { r1.x += separation * (r1.w - convergence); }

  o1.xy = v3.xy * cb0[12].xy + cb0[12].zw;
  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;
  r0.xyz = cb3[15].xyz + r0.xyz;
  o2.w = r0.x;
  r0.x = dot(v1.xyz, v1.xyz);
  r0.x = rsqrt(r0.x);
  r2.xyz = v1.xyz * r0.xxx;
  r3.xyz = cb3[13].yzx * r2.yyy;
  r2.xyw = cb3[12].yzx * r2.xxx + r3.xyz;
  r2.xyz = cb3[14].yzx * r2.zzz + r2.xyw;
  r0.x = dot(r2.xyz, r2.xyz);
  r0.x = rsqrt(r0.x);
  r2.xyz = r2.xyz * r0.xxx;
  o2.x = r2.z;
  r0.x = dot(v2.xyz, v2.xyz);
  r0.x = rsqrt(r0.x);
  r3.xyz = v2.xyz * r0.xxx;
  r4.x = cb3[16].x * r3.x;
  r4.y = cb3[17].x * r3.x;
  r4.z = cb3[18].x * r3.x;
  r5.x = cb3[16].y * r3.y;
  r5.y = cb3[17].y * r3.y;
  r5.z = cb3[18].y * r3.y;
  r3.xyw = r5.xyz + r4.xyz;
  r4.x = cb3[16].z * r3.z;
  r4.y = cb3[17].z * r3.z;
  r4.z = cb3[18].z * r3.z;
  r3.xyz = r4.xyz + r3.xyw;
  r0.x = dot(r3.xyz, r3.xyz);
  r0.x = rsqrt(r0.x);
  r3.xyz = r3.xyz * r0.xxx;
  r4.xyz = r3.zxy * r2.xyz;
  r4.xyz = r3.yzx * r2.yzx + -r4.xyz;
  r0.x = cb3[21].w * v1.w;
  r4.xyz = r4.xyz * r0.xxx;
  o2.y = r4.x;
  o2.z = r3.x;
  o3.w = r0.y;
  o4.w = r0.z;
  o3.x = r2.x;
  o4.x = r2.y;
  o3.y = r4.y;
  o4.y = r4.z;
  o3.z = r3.y;
  o4.z = r3.z;
  o5.xyz = cb4[5].xyz * cb0[9].xyz;
  o5.w = v7.w;
  r0.x = r3.y * r3.y;
  r0.x = r3.x * r3.x + -r0.x;
  r2.xyzw = r3.xyzz * r3.yzzx;
  r4.x = dot(cb2[41].xyzw, r2.xyzw);
  r4.y = dot(cb2[42].xyzw, r2.xyzw);
  r4.z = dot(cb2[43].xyzw, r2.xyzw);
  r0.xyz = cb2[44].xyz * r0.xxx + r4.xyz;
  r3.w = 1;
  r2.x = dot(cb2[38].xyzw, r3.xyzw);
  r2.y = dot(cb2[39].xyzw, r3.xyzw);
  r2.z = dot(cb2[40].xyzw, r3.xyzw);
  r0.xyz = r2.xyz + r0.xyz;
  r0.xyz = max(float3(0,0,0), r0.xyz);
  r0.xyz = log2(r0.xyz);
  r0.xyz = float3(0.416666657,0.416666657,0.416666657) * r0.xyz;
  r0.xyz = exp2(r0.xyz);
  r0.xyz = r0.xyz * float3(1.05499995,1.05499995,1.05499995) + float3(-0.0549999997,-0.0549999997,-0.0549999997);
  o6.xyz = max(float3(0,0,0), r0.xyz);
  r0.x = cb1[5].x * r1.y;
  r0.w = 0.5 * r0.x;
  r0.xz = float2(0.5,0.5) * r1.xw;
  o7.zw = r1.zw;
  o7.xy = r0.xw + r0.zz;
  return;
}
