// hlsltool.py -I ../112 --auto-fix-vertex-halo --fix-unity-reflection --only-autofixed --no-validate --ignore-other-errors 4c9c408f41f37d7c-vs_replace.txt
// 3DMigoto: 4c9c408f41f37d7c |    Unity headers extracted from TreeCreatorBarkRendertex.shader
//    Shader "Hidden/Nature/Tree Creator Bark Rendertex" {
//      Properties {
//       _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)
//      }
//      Fallback Off
//      SubShader 1/1 {
//        Pass 1/1 {
//          GpuProgramID 21305
//          Program "vp" {
//            SubProgram "d3d11 " {
//              GpuProgramIndex 1
//            }
//          }
//        }
//      }
//    }
//
// Unity 5.3 headers extracted from TreeCreatorBarkRendertex.shader.decompressed:
//   API d3d11
//   Shader model vs_4_0
//   undeciphered1: 201509030 35 0 0
//   undeciphered2: 1 0 3 0 0
//   undeciphered3: 15 4 0 0 2 1 1 2 3 4
//   ConstBuffer "UnityPerCamera" 144
//   Vector 64 [_WorldSpaceCameraPos] 3
//   ConstBuffer "UnityPerDraw" 352
//   Matrix 0 [glstate_matrix_mvp]
//   Matrix 256 [_World2Object]
//   ConstBuffer "UnityTerrainImposter" 128
//   Vector 0 [_TerrainTreeLightDirections0] 3
//   Vector 16 [_TerrainTreeLightDirections1] 3
//   Vector 32 [_TerrainTreeLightDirections2] 3
//   Vector 48 [_TerrainTreeLightDirections3] 3
//   BindCB "UnityPerCamera" 0
//   BindCB "UnityPerDraw" 1
//   BindCB "UnityTerrainImposter" 2
//
// 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:27:29 2017
cbuffer cb2 : register(b2)
{
  float4 cb2[3];
}

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

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




// 3Dmigoto declarations
#define cmp -
Texture1D<float4> IniParams : register(t120);
Texture2D<float4> StereoParams : register(t125);



cbuffer UnityPerDraw : register(b11) {
	float4x4 glstate_matrix_mvp;
	float4x4 glstate_matrix_modelview0;
	float4x4 glstate_matrix_invtrans_modelview0;
	#define UNITY_MATRIX_MVP glstate_matrix_mvp
	#define UNITY_MATRIX_MV glstate_matrix_modelview0
	#define UNITY_MATRIX_IT_MV glstate_matrix_invtrans_modelview0

	uniform float4x4 _Object2World;
	uniform float4x4 _World2Object;
	uniform float4 unity_LODFade; // x is the fade value ranging within [0,1]. y is x quantized into 16 levels
	uniform float4 unity_WorldTransformParams; // w is usually 1.0, or -1.0 for odd-negative scale transforms
}


#include <matrix.hlsl>

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 float2 o1 : TEXCOORD0,
  out float2 p1 : TEXCOORD2,
  out float4 o2 : TEXCOORD1,
  out float2 o3 : TEXCOORD3,
  out float2 p3 : TEXCOORD4)
{
  float4 r0,r1;
  uint4 bitmask, uiDest;
  float4 fDest;

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

// Unity reflection/specular 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 4c9c408f41f37d7c-vs_replace.txt
float4 _WorldSpaceCameraPos = cb0[4];
float4 clip_space_adj = float4(-separation * convergence, 0, 0, 0);
float4 local_space_adj = mul(inverse(glstate_matrix_mvp), clip_space_adj);
float4 world_space_adj = mul(_Object2World, local_space_adj);
_WorldSpaceCameraPos.xyz -= world_space_adj.xyz;

  r0.xyzw = cb1[1].xyzw * v0.yyyy;
  r0.xyzw = cb1[0].xyzw * v0.xxxx + r0.xyzw;
  r0.xyzw = cb1[2].xyzw * v0.zzzz + r0.xyzw;
  o0.xyzw = cb1[3].xyzw * v0.wwww + r0.xyzw;
  r0.x = dot(v2.xyz, cb2[0].xyz);
  p1.x = max(0, r0.x);
  r0.xyz = cb1[17].xyz * _WorldSpaceCameraPos.yyy;
  r0.xyz = cb1[16].xyz * _WorldSpaceCameraPos.xxx + r0.xyz;
  r0.xyz = cb1[18].xyz * _WorldSpaceCameraPos.zzz + r0.xyz;
  r0.xyz = cb1[19].xyz + r0.xyz;
  r0.xyz = -v0.xyz + r0.xyz;
  r0.w = dot(r0.xyz, r0.xyz);
  r0.w = rsqrt(r0.w);
  r1.xyz = r0.xyz * r0.www + cb2[0].xyz;
  r1.w = dot(r1.xyz, r1.xyz);
  r1.w = rsqrt(r1.w);
  r1.xyz = r1.xyz * r1.www;
  r1.x = dot(v2.xyz, r1.xyz);
  p1.y = max(0, r1.x);
  o1.xy = v3.xy;
  o2.xyz = v7.www;
  r1.xyz = r0.xyz * r0.www + cb2[1].xyz;
  r0.xyz = r0.xyz * r0.www + cb2[2].xyz;
  r0.w = dot(r1.xyz, r1.xyz);
  r0.w = rsqrt(r0.w);
  r1.xyz = r1.xyz * r0.www;
  r0.w = dot(v2.xyz, r1.xyz);
  o3.y = max(0, r0.w);
  r0.w = dot(r0.xyz, r0.xyz);
  r0.w = rsqrt(r0.w);
  r0.xyz = r0.xyz * r0.www;
  r0.x = dot(v2.xyz, r0.xyz);
  p3.y = max(0, r0.x);
  r0.x = dot(v2.xyz, cb2[1].xyz);
  o3.x = max(0, r0.x);
  r0.x = dot(v2.xyz, cb2[2].xyz);
  p3.x = max(0, r0.x);
  return;
}
