// hlsltool.py -I ../112 --auto-fix-vertex-halo --fix-unity-reflection --only-autofixed --no-validate --ignore-other-errors 21c7d02d82fe2699-vs_replace.txt
// 3DMigoto: 21c7d02d82fe2699 | Matched 8 variants of 1 shaders: TMPro/Distance Field (Surface)
//
//        Unity headers extracted from TMPro_SDF-Surface.shader
//        Shader "TMPro/Distance Field (Surface)" {
//          Properties {
//           _FaceTex ("Fill Texture", 2D) = "white" { }
//           _FaceUVSpeedX ("Face UV Speed X", Range(-5,5)) = 0
//           _FaceUVSpeedY ("Face UV Speed Y", Range(-5,5)) = 0
//           _FaceColor ("Fill Color", Color) = (1,1,1,1)
//           _FaceDilate ("Face Dilate", Range(-1,1)) = 0
//           _OutlineColor ("Outline Color", Color) = (0,0,0,1)
//           _OutlineTex ("Outline Texture", 2D) = "white" { }
//           _OutlineUVSpeedX ("Outline UV Speed X", Range(-5,5)) = 0
//           _OutlineUVSpeedY ("Outline UV Speed Y", Range(-5,5)) = 0
//           _OutlineWidth ("Outline Thickness", Range(0,1)) = 0
//           _OutlineSoftness ("Outline Softness", Range(0,1)) = 0
//           _Bevel ("Bevel", Range(0,1)) = 0.5
//           _BevelOffset ("Bevel Offset", Range(-0.5,0.5)) = 0
//           _BevelWidth ("Bevel Width", Range(-0.5,0.5)) = 0
//           _BevelClamp ("Bevel Clamp", Range(0,1)) = 0
//           _BevelRoundness ("Bevel Roundness", Range(0,1)) = 0
//           _BumpMap ("Normalmap", 2D) = "bump" { }
//           _BumpOutline ("Bump Outline", Range(0,1)) = 0.5
//           _BumpFace ("Bump Face", Range(0,1)) = 0.5
//           _ReflectFaceColor ("Face Color", Color) = (0,0,0,1)
//           _ReflectOutlineColor ("Outline Color", Color) = (0,0,0,1)
//           _Cube ("Reflection Cubemap", CUBE) = "black" { }
//           _EnvMatrixRotation ("Texture Rotation", Vector) = (0,0,0,0)
//           _SpecColor ("Specular Color", Color) = (0,0,0,1)
//           _FaceShininess ("Face Shininess", Range(0,1)) = 0
//           _OutlineShininess ("Outline Shininess", Range(0,1)) = 0
//           _GlowColor ("Color", Color) = (0,1,0,0.5)
//           _GlowOffset ("Offset", Range(-1,1)) = 0
//           _GlowInner ("Inner", Range(0,1)) = 0.05
//           _GlowOuter ("Outer", Range(0,1)) = 0.05
//           _GlowPower ("Falloff", Range(1,0)) = 0.75
//           _WeightNormal ("Weight Normal", Float) = 0
//           _WeightBold ("Weight Bold", Float) = 0.5
//           _ShaderFlags ("Flags", Float) = 0
//           _ScaleRatioA ("Scale RatioA", Float) = 1
//           _ScaleRatioB ("Scale RatioB", Float) = 1
//           _ScaleRatioC ("Scale RatioC", Float) = 1
//           _MainTex ("Font Atlas", 2D) = "white" { }
//           _TextureWidth ("Texture Width", Float) = 512
//           _TextureHeight ("Texture Height", Float) = 512
//           _GradientScale ("Gradient Scale", Float) = 5
//           _ScaleX ("Scale X", Float) = 1
//           _ScaleY ("Scale Y", Float) = 1
//           _PerspectiveFilter ("Perspective Correction", Range(0,1)) = 0.875
//           _VertexOffsetX ("Vertex OffsetX", Float) = 0
//           _VertexOffsetY ("Vertex OffsetY", Float) = 0
//          }
//          SubShader 1/1 {
//            LOD 300
//            Tags { "QUEUE"="Transparent" "IGNOREPROJECTOR"="true" "RenderType"="Transparent" }
//            Pass 2/3 {
//              Name "FORWARD"
//              Tags { "LIGHTMODE"="ForwardAdd" "QUEUE"="Transparent" "IGNOREPROJECTOR"="true" "RenderType"="Transparent" }
//              ZWrite Off
//              Cull [_CullMode]
//              Blend SrcAlpha One
//              ColorMask RGB
//              GpuProgramID 75179
//              Program "vp" {
//                SubProgram "d3d11 " {
// 01:              GpuProgramIndex 13
// 02:              GpuProgramIndex 17
// 04:              GpuProgramIndex 19
// 08:              GpuProgramIndex 21
// 10:              GpuProgramIndex 23
// 20:              GpuProgramIndex 27
// 40:              GpuProgramIndex 29
// 80:              GpuProgramIndex 31
//                }
//              }
//            }
//          }
//        }
//
//     Unity 5.3 headers extracted from TMPro_SDF-Surface.shader.decompressed:
//       API d3d11
//       Shader model vs_4_0
//       undeciphered1: 201509030 73 0 0
// 80:   Keywords { "DIRECTIONAL_COOKIE" "GLOW_ON" }
// 08:   Keywords { "DIRECTIONAL_COOKIE" }
// 10:   Keywords { "POINT" "GLOW_ON" }
// 01:   Keywords { "POINT" }
// 40:   Keywords { "POINT_COOKIE" "GLOW_ON" }
// 04:   Keywords { "POINT_COOKIE" }
// 20:   Keywords { "SPOT" "GLOW_ON" }
// 02:   Keywords { "SPOT" }
//       undeciphered2: 1 0 4 0 0
//       undeciphered3: 159 6 0 0 2 1 1 2 3 4 4 5 7 8
//       ConstBuffer "$Globals" 672
//       Float 224 [_FaceDilate]
//       Float 516 [_WeightNormal]
//       Float 520 [_WeightBold]
//       Float 524 [_ScaleRatioA]
//       Float 536 [_VertexOffsetX]
//       Float 540 [_VertexOffsetY]
//       Float 608 [_GradientScale]
//       Float 612 [_ScaleX]
//       Float 616 [_ScaleY]
//       Float 620 [_PerspectiveFilter]
//       Vector 640 [_MainTex_ST]
//       Vector 656 [_FaceTex_ST]
//       Matrix 336 [_EnvMatrix]
//       ConstBuffer "UnityPerCamera" 144
//       Vector 64 [_WorldSpaceCameraPos] 3
//       Vector 96 [_ScreenParams]
//       ConstBuffer "UnityPerDraw" 352
//       Vector 336 [unity_WorldTransformParams]
//       Matrix 0 [glstate_matrix_mvp]
//       Matrix 192 [_Object2World]
//       Matrix 256 [_World2Object]
//       ConstBuffer "UnityPerFrame" 256
//       Matrix 0 [glstate_matrix_projection]
//       BindCB "$Globals" 0
//       BindCB "UnityPerCamera" 1
//       BindCB "UnityPerDraw" 2
//       BindCB "UnityPerFrame" 3
//
// 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:25 2017
cbuffer cb3 : register(b3)
{
  float4 cb3[2];
}

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

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

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




// 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 float4 o1 : TEXCOORD0,
  out float4 o2 : TEXCOORD1,
  out float4 o3 : TEXCOORD2,
  out float4 o4 : TEXCOORD3,
  out float3 o5 : TEXCOORD4,
  out float4 o6 : COLOR0,
  out float4 o7 : TEXCOORD5,
  out float3 o8 : TEXCOORD6)
{
  float4 r0,r1,r2,r3;
  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 21c7d02d82fe2699-vs_replace.txt
float4 _WorldSpaceCameraPos = cb1[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.xy = cb0[33].zw + v0.xy;
  r1.xyzw = cb2[1].xyzw * r0.yyyy;
  r1.xyzw = cb2[0].xyzw * r0.xxxx + r1.xyzw;
  r1.xyzw = cb2[2].xyzw * v0.zzzz + r1.xyzw;
  o0.xyzw = cb2[3].xyzw * v0.wwww + r1.xyzw;
  r0.w = 0.000244140625 * v4.x;
  r1.z = floor(r0.w);
  r1.w = -r1.z * 4096 + v4.x;
  r1.xy = cb0[41].xy * r1.zw;
  o1.zw = r1.xy * float2(0.001953125,0.001953125) + cb0[41].zw;
  o1.xy = v3.xy * cb0[40].xy + cb0[40].zw;
  r1.xyz = cb2[17].xyz * _WorldSpaceCameraPos.yyy;
  r1.xyz = cb2[16].xyz * _WorldSpaceCameraPos.xxx + r1.xyz;
  r1.xyz = cb2[18].xyz * _WorldSpaceCameraPos.zzz + r1.xyz;
  r1.xyz = cb2[19].xyz + r1.xyz;
  r0.z = v0.z;
  r1.xyz = r1.xyz + -r0.xyz;
  r0.z = dot(v2.xyz, r1.xyz);
  r0.w = cmp(0 < r0.z);
  r0.z = cmp(r0.z < 0);
  r0.z = (int)-r0.w + (int)r0.z;
  r0.z = (int)r0.z;
  r1.xyz = v2.xyz * r0.zzz;
  r2.y = cb2[16].y;
  r2.z = cb2[17].y;
  r2.x = cb2[18].y;
  r2.xyz = r2.xyz * r1.yyy;
  r3.y = cb2[16].x;
  r3.z = cb2[17].x;
  r3.x = cb2[18].x;
  r1.xyw = r3.xyz * r1.xxx + r2.xyz;
  r2.y = cb2[16].z;
  r2.z = cb2[17].z;
  r2.x = cb2[18].z;
  r1.xyz = r2.xyz * r1.zzz + r1.xyw;
  r0.z = dot(r1.xyz, r1.xyz);
  r0.z = rsqrt(r0.z);
  r1.xyz = r1.xyz * r0.zzz;
  o2.z = r1.y;
  r2.xyz = cb2[13].yzx * v1.yyy;
  r2.xyz = cb2[12].yzx * v1.xxx + r2.xyz;
  r2.xyz = cb2[14].yzx * v1.zzz + r2.xyz;
  r0.z = dot(r2.xyz, r2.xyz);
  r0.z = rsqrt(r0.z);
  r2.xyz = r2.xyz * r0.zzz;
  r3.xyz = r2.xyz * r1.xyz;
  r3.xyz = r1.zxy * r2.yzx + -r3.xyz;
  r0.z = cb2[21].w * v1.w;
  r3.xyz = r3.xyz * r0.zzz;
  o2.y = r3.x;
  o2.x = r2.z;
  o3.x = r2.x;
  o4.x = r2.y;
  o3.z = r1.z;
  o3.y = r3.y;
  o4.y = r3.z;
  o4.z = r1.x;
  r2.xyz = cb2[13].xyz * r0.yyy;
  r2.xyz = cb2[12].xyz * r0.xxx + r2.xyz;
  r2.xyz = cb2[14].xyz * v0.zzz + r2.xyz;
  r2.xyz = cb2[15].xyz * v0.www + r2.xyz;
  o5.xyz = r2.xyz;
  r2.xyz = _WorldSpaceCameraPos.xyz + -r2.xyz;
  o6.xyzw = v7.xyzw;
  r0.y = cb2[1].w * r0.y;
  r0.x = cb2[0].w * r0.x + r0.y;
  r0.x = cb2[2].w * v0.z + r0.x;
  r0.x = cb2[3].w * v0.w + r0.x;
  r0.yz = cb3[1].xy * cb1[6].yy;
  r0.yz = cb3[0].xy * cb1[6].xx + r0.yz;
  r0.yz = cb0[38].yz * r0.yz;
  r0.xy = r0.xx / r0.yz;
  r0.x = dot(r0.xy, r0.xy);
  r0.x = rsqrt(r0.x);
  r0.y = cb0[38].x * abs(v4.y);
  r0.x = r0.y * r0.x;
  r0.y = 1.5 * r0.x;
  r0.z = 1 + -cb0[38].w;
  r0.y = r0.y * r0.z;
  r0.x = r0.x * 1.5 + -r0.y;
  r0.z = dot(r2.xyz, r2.xyz);
  r0.z = rsqrt(r0.z);
  r3.xyz = r2.xyz * r0.zzz;
  r0.z = dot(r1.yzx, r3.xyz);
  o7.y = abs(r0.z) * r0.x + r0.y;
  r0.x = cmp(0 >= v4.y);
  r0.x = r0.x ? 1.000000 : 0;
  r0.y = cb0[32].z + -cb0[32].y;
  r0.x = r0.x * r0.y + cb0[32].y;
  r0.x = r0.x / cb0[38].x;
  r0.y = cb0[32].w * cb0[14].x;
  o7.x = r0.y * 0.5 + r0.x;
  r0.xyz = cb0[22].xyz * r2.yyy;
  r0.xyz = cb0[21].xyz * r2.xxx + r0.xyz;
  o8.xyz = cb0[23].xyz * r2.zzz + r0.xyz;
  return;
}
