// hlsltool.py -I ../112 --auto-fix-vertex-halo --fix-unity-reflection --only-autofixed --no-validate --ignore-other-errors c586a34f727cef70-vs_replace.txt
// 3DMigoto: c586a34f727cef70 | Matched 3 variants of 2 shaders: TMPro/Distance Field (Surface), TMPro/Mobile/Distance Field (Surface)
//
// 1:    Unity headers extracted from TMPro_SDF-Surface-Mobile.shader
// 6:    Unity headers extracted from TMPro_SDF-Surface.shader
// 6:    Shader "TMPro/Distance Field (Surface)" {
// 1:    Shader "TMPro/Mobile/Distance Field (Surface)" {
//         Properties {
//          _FaceTex ("Fill Texture", 2D) = "white" { }
// 6:       _FaceUVSpeedX ("Face UV Speed X", Range(-5,5)) = 0
// 6:       _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" { }
// 6:       _OutlineUVSpeedX ("Outline UV Speed X", Range(-5,5)) = 0
// 6:       _OutlineUVSpeedY ("Outline UV Speed Y", Range(-5,5)) = 0
//          _OutlineWidth ("Outline Thickness", Range(0,1)) = 0
//          _OutlineSoftness ("Outline Softness", Range(0,1)) = 0
// 6:       _Bevel ("Bevel", Range(0,1)) = 0.5
// 6:       _BevelOffset ("Bevel Offset", Range(-0.5,0.5)) = 0
// 6:       _BevelWidth ("Bevel Width", Range(-0.5,0.5)) = 0
// 6:       _BevelClamp ("Bevel Clamp", Range(0,1)) = 0
// 6:       _BevelRoundness ("Bevel Roundness", Range(0,1)) = 0
// 6:       _BumpMap ("Normalmap", 2D) = "bump" { }
// 6:       _BumpOutline ("Bump Outline", Range(0,1)) = 0.5
// 6:       _BumpFace ("Bump Face", Range(0,1)) = 0.5
// 6:       _ReflectFaceColor ("Face Color", Color) = (0,0,0,1)
// 6:       _ReflectOutlineColor ("Outline Color", Color) = (0,0,0,1)
// 6:       _Cube ("Reflection Cubemap", CUBE) = "black" { }
// 6:       _EnvMatrixRotation ("Texture Rotation", Vector) = (0,0,0,0)
// 6:       _SpecColor ("Specular Color", Color) = (0,0,0,1)
// 6:       _FaceShininess ("Face Shininess", Range(0,1)) = 0
// 6:       _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" }
// 1:        Pass 1/2 {
// 6:        Pass 1/3 {
//             Name "FORWARD"
//             Tags { "LIGHTMODE"="ForwardBase" "QUEUE"="Transparent" "IGNOREPROJECTOR"="true" "RenderType"="Transparent" }
//             ZWrite Off
//             Cull [_CullMode]
//             Blend SrcAlpha OneMinusSrcAlpha
//             ColorMask RGB
// 1:          GpuProgramID 40431
// 6:          GpuProgramID 8010
//             Program "vp" {
//               SubProgram "d3d11 " {
// 3:              GpuProgramIndex 1
// 4:              GpuProgramIndex 5
//               }
//             }
//           }
//         }
//       }
//
// 1: Unity 5.3 headers extracted from TMPro_SDF-Surface-Mobile.shader.decompressed:
// 6: Unity 5.3 headers extracted from TMPro_SDF-Surface.shader.decompressed:
//      API d3d11
//      Shader model vs_4_0
//      undeciphered1: 201509030 80 0 0
// 4:   Keywords { "DIRECTIONAL" "LIGHTMAP_OFF" "DIRLIGHTMAP_OFF" "DYNAMICLIGHTMAP_OFF" "GLOW_ON" }
// 3:   Keywords { "DIRECTIONAL" "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" 608
//      Float 160 [_FaceDilate]
//      Float 452 [_WeightNormal]
//      Float 456 [_WeightBold]
//      Float 460 [_ScaleRatioA]
//      Float 472 [_VertexOffsetX]
//      Float 476 [_VertexOffsetY]
//      Float 544 [_GradientScale]
//      Float 548 [_ScaleX]
//      Float 552 [_ScaleY]
//      Float 556 [_PerspectiveFilter]
//      Vector 576 [_MainTex_ST]
//      Vector 592 [_FaceTex_ST]
//      Matrix 272 [_EnvMatrix]
//      ConstBuffer "UnityPerCamera" 144
//      Vector 64 [_WorldSpaceCameraPos] 3
//      Vector 96 [_ScreenParams]
//      ConstBuffer "UnityLighting" 720
//      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 "UnityPerFrame" 256
//      Matrix 0 [glstate_matrix_projection]
//      BindCB "$Globals" 0
//      BindCB "UnityPerCamera" 1
//      BindCB "UnityLighting" 2
//      BindCB "UnityPerDraw" 3
//      BindCB "UnityPerFrame" 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:33:04 2017
cbuffer cb4 : register(b4)
{
  float4 cb4[2];
}

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

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

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

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




// 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 float4 o5 : COLOR0,
  out float4 o6 : TEXCOORD4,
  out float4 o7 : TEXCOORD5,
  out float3 o8 : TEXCOORD6)
{
  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;

// 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 c586a34f727cef70-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[29].zw + v0.xy;
  r1.xyzw = cb3[1].xyzw * r0.yyyy;
  r1.xyzw = cb3[0].xyzw * r0.xxxx + r1.xyzw;
  r1.xyzw = cb3[2].xyzw * v0.zzzz + r1.xyzw;
  o0.xyzw = cb3[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[37].xy * r1.zw;
  o1.zw = r1.xy * float2(0.001953125,0.001953125) + cb0[37].zw;
  o1.xy = v3.xy * cb0[36].xy + cb0[36].zw;
  r1.xyz = cb3[17].xyz * _WorldSpaceCameraPos.yyy;
  r1.xyz = cb3[16].xyz * _WorldSpaceCameraPos.xxx + r1.xyz;
  r1.xyz = cb3[18].xyz * _WorldSpaceCameraPos.zzz + r1.xyz;
  r1.xyz = cb3[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.x = cb3[16].y;
  r2.y = cb3[17].y;
  r2.zw = cb3[18].yy;
  r2.xyzw = r2.xyzw * r1.yyyy;
  r3.x = cb3[16].x;
  r3.y = cb3[17].x;
  r3.zw = cb3[18].xx;
  r2.xyzw = r3.xyzw * r1.xxxx + r2.xyzw;
  r3.x = cb3[16].z;
  r3.y = cb3[17].z;
  r3.zw = cb3[18].zz;
  r1.xyzw = r3.xyzw * r1.zzzz + r2.xyzw;
  r0.z = dot(r1.xyw, r1.xyw);
  r0.z = rsqrt(r0.z);
  r1.xyzw = r1.xyzw * r0.zzzz;
  r2.xyz = cb3[13].yzx * v1.yyy;
  r2.xyz = cb3[12].yzx * v1.xxx + r2.xyz;
  r2.xyz = cb3[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.wxy;
  r3.xyz = r1.ywx * r2.yzx + -r3.xyz;
  r0.z = cb3[21].w * v1.w;
  r3.xyz = r3.xyz * r0.zzz;
  o2.y = r3.x;
  o2.z = r1.x;
  o2.x = r2.z;
  r4.xyz = cb3[13].xyz * r0.yyy;
  r4.xyz = cb3[12].xyz * r0.xxx + r4.xyz;
  r4.xyz = cb3[14].xyz * v0.zzz + r4.xyz;
  r4.xyz = cb3[15].xyz * v0.www + r4.xyz;
  o2.w = r4.x;
  o3.x = r2.x;
  o4.x = r2.y;
  o3.z = r1.y;
  o3.y = r3.y;
  o4.y = r3.z;
  o3.w = r4.y;
  o4.z = r1.w;
  o4.w = r4.z;
  r2.xyz = _WorldSpaceCameraPos.xyz + -r4.xyz;
  o5.xyzw = v7.xyzw;
  r0.y = cb3[1].w * r0.y;
  r0.x = cb3[0].w * r0.x + r0.y;
  r0.x = cb3[2].w * v0.z + r0.x;
  r0.x = cb3[3].w * v0.w + r0.x;
  r0.yz = cb4[1].xy * cb1[6].yy;
  r0.yz = cb4[0].xy * cb1[6].xx + r0.yz;
  r0.yz = cb0[34].yz * r0.yz;
  r0.xy = r0.xx / r0.yz;
  r0.x = dot(r0.xy, r0.xy);
  r0.x = rsqrt(r0.x);
  r0.y = cb0[34].x * abs(v4.y);
  r0.x = r0.y * r0.x;
  r0.y = 1.5 * r0.x;
  r0.z = 1 + -cb0[34].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.xyw, r3.xyz);
  o6.y = abs(r0.z) * r0.x + r0.y;
  r0.x = cmp(0 >= v4.y);
  r0.x = r0.x ? 1.000000 : 0;
  r0.y = cb0[28].z + -cb0[28].y;
  r0.x = r0.x * r0.y + cb0[28].y;
  r0.x = r0.x / cb0[34].x;
  r0.y = cb0[28].w * cb0[10].x;
  o6.x = r0.y * 0.5 + r0.x;
  r0.xyz = cb0[18].xyz * r2.yyy;
  r0.xyz = cb0[17].xyz * r2.xxx + r0.xyz;
  o7.xyz = cb0[19].xyz * r2.zzz + r0.xyz;
  r0.x = r1.y * r1.y;
  r0.x = r1.x * r1.x + -r0.x;
  r1.xyzw = r1.xyzw * r1.ywzx;
  r2.x = dot(cb2[41].xyzw, r1.xyzw);
  r2.y = dot(cb2[42].xyzw, r1.xyzw);
  r2.z = dot(cb2[43].xyzw, r1.xyzw);
  o8.xyz = cb2[44].xyz * r0.xxx + r2.xyz;
  return;
}
