// hlsltool.py -I ../112 --auto-fix-vertex-halo --fix-unity-reflection --only-autofixed --no-validate --ignore-other-errors 42b6dd7b93a530ae-vs_replace.txt
// 3DMigoto: 42b6dd7b93a530ae |    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 6/6 {
//          Name "SHADOWCASTER"
//          Tags { "LIGHTMODE"="SHADOWCASTER" "IGNOREPROJECTOR"="true" "SHADOWSUPPORT"="true" "RenderType"="TreeBark" }
//          GpuProgramID 385050
//          Program "vp" {
//            SubProgram "d3d11_9x " {
//              GpuProgramIndex 80
//            }
//          }
//        }
//      }
//    }
//
// Unity 5.3 headers extracted from TreeCreatorBarkOptimized.shader.decompressed:
//   API d3d11_9x
//   Shader model vs_4_0_level_9_1
//   undeciphered1: 201509030 72 0 0
//   Keywords { "SHADOWS_DEPTH" }
//   undeciphered2: 1 0 7 0 0
//   undeciphered3: 23 4 0 0 2 1 1 2 4 5
//   ConstBuffer "$Globals" 192
//   Vector 128 [_Wind]
//   ConstBuffer "UnityPerCamera" 144
//   Vector 0 [_Time]
//   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 "UnityTerrain" 272
//   Vector 96 [_TreeInstanceScale]
//   Vector 176 [_SquashPlaneNormal]
//   Float 192 [_SquashAmount]
//   BindCB "$Globals" 0
//   BindCB "UnityPerCamera" 1
//   BindCB "UnityLighting" 2
//   BindCB "UnityShadows" 3
//   BindCB "UnityPerDraw" 4
//   BindCB "UnityPerFrame" 5
//   BindCB "UnityTerrain" 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:26:56 2017
cbuffer cb6 : register(b6)
{
  float4 cb6[13];
}

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

cbuffer cb0 : register(b0)
{
  float4 cb0[9];
}




// 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 float3 o1 : TEXCOORD1)
{
  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.x = dot(v2.xyz, v2.xyz);
  r0.x = rsqrt(r0.x);
  r0.xyz = v2.xyz * r0.xxx;
  r1.x = cb4[16].x * r0.x;
  r1.y = cb4[17].x * r0.x;
  r1.z = cb4[18].x * r0.x;
  r2.x = cb4[16].y * r0.y;
  r2.y = cb4[17].y * r0.y;
  r2.z = cb4[18].y * r0.y;
  r0.xyw = r2.xyz + r1.xyz;
  r1.x = cb4[16].z * r0.z;
  r1.y = cb4[17].z * r0.z;
  r1.z = cb4[18].z * r0.z;
  r0.xyz = r1.xyz + r0.xyw;
  r0.w = dot(r0.xyz, r0.xyz);
  r0.w = rsqrt(r0.w);
  r0.xyz = r0.xyz * r0.www;
  r1.x = cb4[12].w;
  r1.y = cb4[13].w;
  r1.z = cb4[14].w;
  r0.w = dot(r1.xyz, float3(1,1,1));
  r1.y = v7.x + r0.w;
  r0.w = v7.y + r1.y;
  r2.xyz = cb6[6].xyz * v0.xyz;
  r1.x = dot(r2.xyz, r0.www);
  r1.xyzw = cb1[0].yyyy + r1.xxyy;
  r1.xyzw = float4(1.97500002,0.792999983,0.375,0.193000004) * r1.xyzw;
  r1.xyzw = frac(r1.xyzw);
  r1.xyzw = r1.xyzw * float4(2,2,2,2) + float4(-0.5,-0.5,-0.5,-0.5);
  r1.xyzw = frac(r1.xyzw);
  r1.xyzw = r1.xyzw * float4(2,2,2,2) + float4(-1,-1,-1,-1);
  r3.xyzw = abs(r1.xyzw) * abs(r1.xyzw);
  r1.xyzw = -abs(r1.xyzw) * float4(2,2,2,2) + float4(3,3,3,3);
  r1.xyzw = r3.xyzw * r1.xyzw;
  r1.xy = r1.xz + r1.yw;
  r3.xyz = cb0[8].xyz * r1.yyy;
  r3.xyz = v4.yyy * r3.xyz;
  r4.y = v4.y * r1.y;
  r0.w = 0.100000001 * v7.y;
  r4.xz = v2.xz * r0.ww;
  r1.z = 0.300000012;
  r1.xyz = r1.xzx * r4.xyz + r3.xyz;
  r1.xyz = r1.xyz * cb0[8].www + r2.xyz;
  r1.xyz = v4.xxx * cb0[8].xyz + r1.xyz;
  r0.w = dot(cb6[11].xyz, r1.xyz);
  r0.w = cb6[11].w + r0.w;
  r2.xyz = -r0.www * cb6[11].xyz + r1.xyz;
  r1.xyz = -r2.xyz + r1.xyz;
  r1.xyz = cb6[12].xxx * r1.xyz + r2.xyz;
  r2.xyz = cb4[13].xyz * r1.yyy;
  r2.xyz = cb4[12].xyz * r1.xxx + r2.xyz;
  r2.xyz = cb4[14].xyz * r1.zzz + r2.xyz;
  r2.xyz = cb4[15].xyz + r2.xyz;
  r3.xyz = -r2.xyz * cb2[0].www + cb2[0].xyz;
  r0.w = dot(r3.xyz, r3.xyz);
  r0.w = rsqrt(r0.w);
  r3.xyz = r3.xyz * r0.www;
  r0.w = dot(r0.xyz, r3.xyz);
  r0.w = -r0.w * r0.w + 1;
  r0.w = sqrt(r0.w);
  r0.w = cb3[5].z * r0.w;
  r0.xyz = -r0.xyz * r0.www + r2.xyz;
  o1.xyz = r2.xyz;
  r2.xyzw = cb5[10].xyzw * r0.yyyy;
  r2.xyzw = cb5[9].xyzw * r0.xxxx + r2.xyzw;
  r0.xyzw = cb5[11].xyzw * r0.zzzz + r2.xyzw;
  r0.xyzw = cb5[12].xyzw + r0.xyzw;
  r2.xyzw = cb4[1].xyzw * r1.yyyy;
  r2.xyzw = cb4[0].xyzw * r1.xxxx + r2.xyzw;
  r1.xyzw = cb4[2].xyzw * r1.zzzz + r2.xyzw;
  r1.xyzw = cb4[3].xyzw + r1.xyzw;
  r2.x = cmp(cb3[5].z != 0.000000);
  r0.xyzw = r2.xxxx ? r0.xyzw : r1.xyzw;

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

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

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

  r0.x = max(0, r0.z);
  r0.x = r0.x + -r0.z;
  o0.z = cb3[5].y * r0.x + r0.z;
  return;
}
