// hlsltool.py -I ../112 --auto-fix-vertex-halo --fix-unity-reflection --only-autofixed --no-validate --ignore-other-errors e3ca094ede5e0c44-vs_replace.txt
// 3DMigoto: e3ca094ede5e0c44 |    Unity headers extracted from WavingGrassBillboard.shader
//    Shader "Hidden/TerrainEngine/Details/BillboardWavingDoublePass" {
//      Properties {
//       _WavingTint ("Fade Color", Color) = (0.7,0.6,0.5,0)
//       _MainTex ("Base (RGB) Alpha (A)", 2D) = "white" { }
//       _WaveAndDistance ("Wave and distance", Vector) = (12,3.6,1,1)
//       _Cutoff ("Cutoff", Float) = 0.5
//      }
//      Fallback Off
//      SubShader 1/1 {
//        LOD 200
//        Tags { "QUEUE"="Geometry+200" "IGNOREPROJECTOR"="true" "DisableBatching"="true" "RenderType"="GrassBillboard" }
//        Pass 5/5 {
//          Name "SHADOWCASTER"
//          Tags { "LIGHTMODE"="SHADOWCASTER" "QUEUE"="Geometry+200" "IGNOREPROJECTOR"="true" "SHADOWSUPPORT"="true" "DisableBatching"="true" "RenderType"="GrassBillboard" }
//          Cull Off
//          ColorMask RGB
//          GpuProgramID 268685
//          Program "vp" {
//            SubProgram "d3d11_9x " {
//              GpuProgramIndex 68
//            }
//          }
//        }
//      }
//    }
//
// Unity 5.3 headers extracted from WavingGrassBillboard.shader.decompressed:
//   API d3d11_9x
//   Shader model vs_4_0_level_9_1
//   undeciphered1: 201509030 78 0 0
//   Keywords { "SHADOWS_DEPTH" }
//   undeciphered2: 1 0 6 0 0
//   undeciphered3: 143 5 0 0 2 1 1 2 3 4 7 8
//   ConstBuffer "$Globals" 176
//   Vector 160 [_MainTex_ST]
//   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 0 [_WavingTint]
//   Vector 16 [_WaveAndDistance]
//   Vector 32 [_CameraPosition]
//   Vector 48 [_CameraRight] 3
//   Vector 64 [_CameraUp] 3
//   BindCB "$Globals" 0
//   BindCB "UnityLighting" 1
//   BindCB "UnityShadows" 2
//   BindCB "UnityPerDraw" 3
//   BindCB "UnityPerFrame" 4
//   BindCB "UnityTerrain" 5
//
// 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:34:28 2017
cbuffer cb5 : register(b5)
{
  float4 cb5[5];
}

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

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

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

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

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 : 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 : TEXCOORD1,
  out float3 o2 : TEXCOORD2,
  out float4 o3 : COLOR0)
{
  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 = cb3[16].x * v2.x;
  r0.y = cb3[17].x * v2.x;
  r0.z = cb3[18].x * v2.x;
  r1.x = cb3[16].y * v2.y;
  r1.y = cb3[17].y * v2.y;
  r1.z = cb3[18].y * v2.y;
  r0.xyz = r1.xyz + r0.xyz;
  r1.x = cb3[16].z * v2.z;
  r1.y = cb3[17].z * v2.z;
  r1.z = cb3[18].z * v2.z;
  r0.xyz = r1.xyz + r0.xyz;
  r0.w = dot(r0.xyz, r0.xyz);
  r0.w = rsqrt(r0.w);
  r0.xyz = r0.xyz * r0.www;
  r1.xyz = -cb5[2].xyz + v0.xyz;
  r0.w = dot(r1.xyz, r1.xyz);
  r0.w = cmp(cb5[1].w < r0.w);
  r1.xy = r0.ww ? float2(0,0) : v1.xy;
  r1.xzw = r1.xxx * cb5[3].xyz + v0.xyz;
  r1.xyz = r1.yyy * cb5[4].xyz + r1.xzw;
  r2.xy = cb5[1].yy * r1.xz;
  r3.xyzw = float4(0.00600000005,0.0199999996,0.0199999996,0.0500000007) * r2.yyyy;
  r2.xyzw = r2.xxxx * float4(0.0120000001,0.0199999996,0.0599999987,0.0240000002) + r3.xyzw;
  r2.xyzw = cb5[1].xxxx * float4(1.20000005,2,1.60000002,4.80000019) + r2.xyzw;
  r2.xyzw = frac(r2.xyzw);
  r2.xyzw = r2.xyzw * float4(6.40884876,6.40884876,6.40884876,6.40884876) + float4(-3.14159274,-3.14159274,-3.14159274,-3.14159274);
  r3.xyzw = r2.xyzw * r2.xyzw;
  r4.xyzw = r3.xyzw * r2.xyzw;
  r2.xyzw = r4.xyzw * float4(-0.161616161,-0.161616161,-0.161616161,-0.161616161) + r2.xyzw;
  r4.xyzw = r4.xyzw * r3.xyzw;
  r3.xyzw = r4.xyzw * r3.xyzw;
  r2.xyzw = r4.xyzw * float4(0.00833330024,0.00833330024,0.00833330024,0.00833330024) + r2.xyzw;
  r2.xyzw = r3.xyzw * float4(-0.000198409994,-0.000198409994,-0.000198409994,-0.000198409994) + r2.xyzw;
  r2.xyzw = r2.xyzw * r2.xyzw;
  r2.xyzw = r2.xyzw * r2.xyzw;
  r3.xyzw = v1.yyyy * r2.xyzw;
  r0.w = dot(r2.xyzw, float4(0.674199879,0.674199879,0.269679934,0.134839967));
  r0.w = 0.699999988 * r0.w;
  r2.x = dot(r3.xyzw, float4(0.0240000002,0.0399999991,-0.119999997,0.0960000008));
  r2.z = dot(r3.xyzw, float4(0.00600000005,0.0199999996,-0.0199999996,0.100000001));
  r1.xz = -r2.xz * cb5[1].zz + r1.xz;
  r2.xyz = cb3[13].xyz * r1.yyy;
  r2.xyz = cb3[12].xyz * r1.xxx + r2.xyz;
  r2.xyz = cb3[14].xyz * r1.zzz + r2.xyz;
  r3.xyz = cb3[15].xyz + r2.xyz;
  o2.xyz = cb3[15].xyz * v0.www + r2.xyz;
  r2.xyz = -r3.xyz * cb1[0].www + cb1[0].xyz;
  r1.w = dot(r2.xyz, r2.xyz);
  r1.w = rsqrt(r1.w);
  r2.xyz = r2.xyz * r1.www;
  r1.w = dot(r0.xyz, r2.xyz);
  r1.w = -r1.w * r1.w + 1;
  r1.w = sqrt(r1.w);
  r1.w = cb2[5].z * r1.w;
  r0.xyz = -r0.xyz * r1.www + r3.xyz;
  r2.xyzw = cb4[10].xyzw * r0.yyyy;
  r2.xyzw = cb4[9].xyzw * r0.xxxx + r2.xyzw;
  r2.xyzw = cb4[11].xyzw * r0.zzzz + r2.xyzw;
  r2.xyzw = cb4[12].xyzw + r2.xyzw;
  r3.xyzw = cb3[1].xyzw * r1.yyyy;
  r0.xyz = -cb5[2].xyz + r1.xyz;
  r0.x = dot(r0.xyz, r0.xyz);
  r0.x = cb5[1].w + -r0.x;
  r0.x = r0.x + r0.x;
  o3.w = saturate(cb5[2].w * r0.x);
  r3.xyzw = cb3[0].xyzw * r1.xxxx + r3.xyzw;
  r1.xyzw = cb3[2].xyzw * r1.zzzz + r3.xyzw;
  r1.xyzw = cb3[3].xyzw + r1.xyzw;
  r0.x = cmp(cb2[5].z != 0.000000);
  r1.xyzw = r0.xxxx ? r2.xyzw : r1.xyzw;

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

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

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

  r0.y = max(0, r0.x);
  r0.y = r0.y + -r0.x;
  o0.z = cb2[5].y * r0.y + r0.x;
  o1.xy = v3.xy * cb0[10].xy + cb0[10].zw;
  r0.xyz = float3(-0.5,-0.5,-0.5) + cb5[0].xyz;
  r0.xyz = r0.www * r0.xyz + float3(0.5,0.5,0.5);
  r0.xyz = v7.xyz * r0.xyz;
  o3.xyz = r0.xyz + r0.xyz;
  return;
}
