// hlsltool.py -I ../112 --auto-fix-vertex-halo --fix-unity-reflection --only-autofixed --no-validate --ignore-other-errors 40c4114947811e37-vs_replace.txt
// 3DMigoto: 40c4114947811e37 |    Unity headers extracted from TMPro_SDF-Mobile Overlay.shader
//    Shader "TMPro/Mobile/Distance Field Overlay" {
//      Properties {
//       _FaceColor ("Face Color", Color) = (1,1,1,1)
//       _FaceDilate ("Face Dilate", Range(-1,1)) = 0
//       _OutlineColor ("Outline Color", Color) = (0,0,0,1)
//       _OutlineWidth ("Outline Thickness", Range(0,1)) = 0
//       _OutlineSoftness ("Outline Softness", Range(0,1)) = 0
//       _UnderlayColor ("Border Color", Color) = (0,0,0,0.5)
//       _UnderlayOffsetX ("Border OffsetX", Range(-1,1)) = 0
//       _UnderlayOffsetY ("Border OffsetY", Range(-1,1)) = 0
//       _UnderlayDilate ("Border Dilate", Range(-1,1)) = 0
//       _UnderlaySoftness ("Border Softness", Range(0,1)) = 0
//       _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
//       _MaskCoord ("Mask Coordinates", Vector) = (0,0,10000,10000)
//       _ClipRect ("Clip Rect", Vector) = (-10000,-10000,10000,10000)
//       _MaskSoftnessX ("Mask SoftnessX", Float) = 0
//       _MaskSoftnessY ("Mask SoftnessY", Float) = 0
//       _ColorMask ("Color Mask", Float) = 15
//      }
//      SubShader 1/1 {
//        Tags { "QUEUE"="Overlay" "IGNOREPROJECTOR"="true" "RenderType"="Transparent" }
//        Pass 1/1 {
//          Tags { "QUEUE"="Overlay" "IGNOREPROJECTOR"="true" "RenderType"="Transparent" }
//          ZTest Always
//          ZWrite Off
//          Cull [_CullMode]
//          Blend One OneMinusSrcAlpha
//          ColorMask [_ColorMask]
//          GpuProgramID 40460
//          Program "vp" {
//            SubProgram "d3d11_9x " {
//              GpuProgramIndex 2
//            }
//          }
//        }
//      }
//    }
//
// Unity 5.3 headers extracted from TMPro_SDF-Mobile Overlay.shader.decompressed:
//   API d3d11_9x
//   Shader model vs_4_0_level_9_1
//   undeciphered1: 201509030 68 0 0
//   undeciphered2: 1 0 4 0 0
//   undeciphered3: 31 5 0 0 2 1 1 2 3 4 4 5
//   ConstBuffer "$Globals" 528
//   Vector 112 [_FaceColor]
//   Float 128 [_FaceDilate]
//   Float 132 [_OutlineSoftness]
//   Vector 144 [_OutlineColor]
//   Float 160 [_OutlineWidth]
//   Float 420 [_WeightNormal]
//   Float 424 [_WeightBold]
//   Float 428 [_ScaleRatioA]
//   Float 440 [_VertexOffsetX]
//   Float 444 [_VertexOffsetY]
//   Float 512 [_GradientScale]
//   Float 516 [_ScaleX]
//   Float 520 [_ScaleY]
//   Float 524 [_PerspectiveFilter]
//   ConstBuffer "UnityPerCamera" 144
//   Vector 64 [_WorldSpaceCameraPos] 3
//   Vector 96 [_ScreenParams]
//   ConstBuffer "UnityPerDraw" 352
//   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:26:51 2017
cbuffer cb3 : register(b3)
{
  float4 cb3[4];
}

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

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

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




// 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,
  float3 v1 : NORMAL0,
  float4 v2 : COLOR0,
  float4 v3 : TEXCOORD0,
  float2 v4 : TEXCOORD1,
  out float4 o0 : SV_POSITION0,
  out float4 o1 : COLOR0,
  out float4 o2 : COLOR1,
  out float4 o3 : TEXCOORD0,
  out float4 o4 : TEXCOORD1,
  out float4 o5 : TEXCOORD2)
{
  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 40c4114947811e37-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[27].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;
  r1.xyzw = cb2[3].xyzw * v0.wwww + r1.xyzw;
  o0.xyzw = r1.xyzw;
  r2.xyzw = cb0[7].xyzw * v2.xyzw;
  r2.xyz = r2.xyz * r2.www;
  o1.xyzw = r2.xyzw;
  r1.xyz = cb2[13].xyz * r0.yyy;
  r1.xyz = cb2[12].xyz * r0.xxx + r1.xyz;
  o5.xy = r0.xy;
  r0.xyz = cb2[14].xyz * v0.zzz + r1.xyz;
  r0.xyz = cb2[15].xyz * v0.www + r0.xyz;
  r0.xyz = _WorldSpaceCameraPos.xyz + -r0.xyz;
  r0.w = dot(r0.xyz, r0.xyz);
  r0.w = rsqrt(r0.w);
  r0.xyz = r0.xyz * r0.www;
  r1.x = cb2[16].x * v1.x;
  r1.y = cb2[17].x * v1.x;
  r1.z = cb2[18].x * v1.x;
  r3.x = cb2[16].y * v1.y;
  r3.y = cb2[17].y * v1.y;
  r3.z = cb2[18].y * v1.y;
  r1.xyz = r3.xyz + r1.xyz;
  r3.x = cb2[16].z * v1.z;
  r3.y = cb2[17].z * v1.z;
  r3.z = cb2[18].z * v1.z;
  r1.xyz = r3.xyz + r1.xyz;
  r0.w = dot(r1.xyz, r1.xyz);
  r0.w = rsqrt(r0.w);
  r1.xyz = r1.xyz * r0.www;
  r0.x = dot(r1.xyz, r0.xyz);
  r0.yz = cb3[1].xy * cb1[6].yy;
  r0.yz = cb3[0].xy * cb1[6].xx + r0.yz;
  r0.yz = cb0[32].yz * abs(r0.yz);
  r0.yz = r1.ww / r0.yz;
  r0.w = dot(r0.yz, r0.yz);
  o5.zw = float2(0.5,0.5) / r0.yz;
  r0.y = rsqrt(r0.w);
  r0.z = cb0[32].x * abs(v4.y);
  r0.y = r0.z * r0.y;
  r0.z = 1.5 * r0.y;
  r0.w = 1 + -cb0[32].w;
  r0.w = abs(r0.z) * r0.w;
  r0.y = r0.y * 1.5 + -r0.w;
  r0.x = abs(r0.x) * r0.y + r0.w;
  r0.y = cmp(cb3[3].w == 0.000000);
  r0.x = r0.y ? r0.x : r0.z;
  r0.yz = cb0[26].ww * cb0[8].xy;
  r0.z = r0.z * r0.x + 1;
  r0.x = r0.x / r0.z;
  r0.z = cb0[26].w * cb0[10].x;
  r0.z = 0.5 * r0.z;
  r1.x = r0.z * r0.x;
  r1.x = r1.x + r1.x;
  r1.x = min(1, r1.x);
  r1.x = sqrt(r1.x);
  r3.w = cb0[9].w * v2.w;
  r3.xyz = cb0[9].xyz * r3.www;
  r3.xyzw = r3.xyzw + -r2.xyzw;
  o2.xyzw = r1.xxxx * r3.xyzw + r2.xyzw;
  o3.xy = v3.xy;
  r1.x = cmp(0 >= v4.y);
  r1.x = r1.x ? 1.000000 : 0;
  r1.y = cb0[26].z + -cb0[26].y;
  r1.x = r1.x * r1.y + cb0[26].y;
  r1.x = r1.x / cb0[32].x;
  r0.y = r0.y * 0.5 + r1.x;
  r0.y = 0.5 + -r0.y;
  r0.w = r0.y * r0.x + -0.5;
  o4.y = -r0.z * r0.x + r0.w;
  o4.z = r0.z * r0.x + r0.w;
  o4.xw = r0.xw;
  return;
}
