// hlsltool.py -I ../112 --auto-fix-vertex-halo --fix-unity-reflection --only-autofixed --no-validate --ignore-other-errors 6f19cbe0c3f0d451-vs_replace.txt
// 3DMigoto: 6f19cbe0c3f0d451 | Matched 2 variants of 1 shaders: Custom/LightningBoltShaderMesh
//
//       Unity headers extracted from LightningBoltShaderMesh.shader
//       Shader "Custom/LightningBoltShaderMesh" {
//         Properties {
//          _MainTex ("Color (RGB) Alpha (A)", 2D) = "white" { }
//          _GlowTex ("Glow Color (RGB) Alpha (A)", 2D) = "white" { }
//          _TintColor ("Tint Color (RGB)", Color) = (1,1,1,1)
//          _GlowTintColor ("Glow Tint Color (RGB)", Color) = (1,1,1,1)
//          _InvFade ("Soft Particles Factor", Range(0.01,3)) = 1
//          _JitterMultiplier ("Jitter Multiplier (Float)", Float) = 0
//          _Turbulence ("Turbulence (Float)", Float) = 0
//          _TurbulenceVelocity ("Turbulence Velocity (Vector)", Vector) = (0,0,0,0)
//          _SrcBlendMode ("SrcBlendMode (Source Blend Mode)", Float) = 5
//          _DstBlendMode ("DstBlendMode (Destination Blend Mode)", Float) = 1
//         }
//         Fallback Off
//         SubShader 1/1 {
//           Tags { "LIGHTMODE"="Always" "QUEUE"="Transparent+10" "IGNOREPROJECTOR"="true" "RenderType"="Transparent" "PreviewType"="Plane" }
//           Pass 2/2 {
//             Name "LINEPASS"
//             Tags { "LIGHTMODE"="Always" "QUEUE"="Transparent+10" "IGNOREPROJECTOR"="true" "RenderType"="Transparent" "PreviewType"="Plane" }
//             ZWrite Off
//             Cull Off
//             Blend [_SrcBlendMode] [_DstBlendMode]
//             GpuProgramID 112635
//             Program "vp" {
//               SubProgram "d3d11_9x " {
// 1:              GpuProgramIndex 29
// 2:              GpuProgramIndex 35
//               }
//             }
//           }
//         }
//       }
//
//    Unity 5.3 headers extracted from LightningBoltShaderMesh.shader.decompressed:
//      API d3d11_9x
//      Shader model vs_4_0_level_9_1
//      undeciphered1: 201509030 62 0 0
// 2:   Keywords { "SOFTPARTICLES_ON" "ALPHA_BLEND_ON" }
// 1:   Keywords { "SOFTPARTICLES_ON" }
//      undeciphered2: 1 0 3 0 0
//      undeciphered3: 157 5 0 0 2 1 3 4 4 5 7 8
//      ConstBuffer "$Globals" 160
//      Float 100 [_JitterMultiplier]
//      Float 104 [_Turbulence]
//      Vector 112 [_TurbulenceVelocity]
//      Vector 128 [_TintColor]
//      ConstBuffer "UnityPerCamera" 144
//      Vector 0 [_Time]
//      Vector 64 [_WorldSpaceCameraPos] 3
//      Vector 80 [_ProjectionParams]
//      Vector 128 [unity_OrthoParams]
//      ConstBuffer "UnityPerDraw" 352
//      Matrix 0 [glstate_matrix_mvp]
//      Matrix 64 [glstate_matrix_modelview0]
//      BindCB "$Globals" 0
//      BindCB "UnityPerCamera" 1
//      BindCB "UnityPerDraw" 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:29:04 2017
cbuffer cb2 : register(b2)
{
  float4 cb2[22];
}

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

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,
  float4 v2 : COLOR0,
  float4 v3 : TEXCOORD0,
  float4 v4 : TEXCOORD1,
  float3 v5 : NORMAL0,
  out float2 o0 : TEXCOORD0,
  out float4 o1 : COLOR0,
  out float4 o2 : SV_POSITION0,
  out float4 o3 : TEXCOORD1)
{
  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 6f19cbe0c3f0d451-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;

  o0.xy = v3.xy;
  r0.x = cmp(cb1[0].y >= v4.y);
  r0.yzw = cb1[0].yyy + -v4.xxz;
  r1.xyz = v4.wyw + -v4.xxz;
  r0.yzw = r0.yzw / r1.xyz;
  r0.w = max(0, r0.w);
  r0.w = 1 + -r0.w;
  r0.x = r0.x ? r0.w : r0.z;
  r1.xyzw = cb0[8].xyzw * r0.xxxx;
  o1.xyzw = v2.xyzw * r1.xyzw;
  r0.x = dot(v1.xyz, v1.xyz);
  r0.x = rsqrt(r0.x);
  r0.xzw = v1.xyz * r0.xxx;
  r1.x = max(0.5, abs(v1.w));
  r1.x = cb0[6].z / r1.x;
  r1.x = r1.x * r0.y;
  r2.xyz = r1.xxx * r0.xzw;
  r2.w = 0;
  r2.xyzw = r0.yyyy * cb0[7].xyzw + r2.xyzw;
  r0.xy = cb0[7].xy * r0.yy;
  r1.yzw = _WorldSpaceCameraPos.yzx + -v0.yzx;
  r3.xyz = v1.zxy * r1.yzw;
  r1.yzw = v1.yzx * r1.zwy + -r3.xyz;
  r0.z = dot(r1.yzw, r1.yzw);
  r0.z = rsqrt(r0.z);
  r1.yzw = r1.yzw * r0.zzz;
  r1.yzw = v1.www * r1.yzw;
  r3.xyz = cb1[0].yzw * v0.xyz;
  r0.z = dot(r3.xyz, float3(12.9898005,78.2330017,45.5432014));
  r0.z = sin(r0.z);
  r0.z = 43758.5469 * r0.z;
  r0.z = frac(r0.z);
  r0.z = r0.z * cb0[6].y + 1;
  r3.xyz = r1.yzw * r0.zzz;
  r3.w = 0;
  r3.xyzw = v0.xyzw + r3.xyzw;
  r2.xyzw = r3.xyzw + r2.xyzw;
  r3.xyzw = cb2[1].xyzw * r2.yyyy;
  r3.xyzw = cb2[0].xyzw * r2.xxxx + r3.xyzw;
  r3.xyzw = cb2[2].xyzw * r2.zzzz + r3.xyzw;
  r2.xyzw = cb2[3].xyzw * r2.wwww + r3.xyzw;
  r0.w = dot(v1.xyzw, v1.xyzw);
  r0.w = rsqrt(r0.w);
  r1.yz = v1.xy * r0.ww;
  r1.xy = r1.yz * r1.xx + r0.xy;
  r0.xy = float2(-1,1) * v1.yx;
  r0.w = dot(r0.xy, r0.xy);
  r0.w = rsqrt(r0.w);
  r0.xy = r0.xy * r0.ww;
  r0.xy = v1.ww * r0.xy;
  r0.xy = r0.xy * r0.zz;
  r0.zw = float2(0,0);
  r0.xyzw = v0.xyzw + r0.xyzw;
  r1.zw = float2(0,0);
  r0.xyzw = r1.xyzw + r0.xyzw;
  r1.xyzw = cb2[1].xyzw * r0.yyyy;
  r1.xyzw = cb2[0].xyzw * r0.xxxx + r1.xyzw;
  r1.xyzw = cb2[2].xyzw * r0.zzzz + r1.xyzw;
  r0.xyzw = cb2[3].xyzw * r0.wwww + r1.xyzw;
  r1.x = cmp(cb1[8].w == 0.000000);
  r0.xyzw = r1.xxxx ? r2.xyzw : r0.xyzw;
  o2.xyzw = r0.xyzw;

// 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 6f19cbe0c3f0d451-vs_replace.txt
if (r0.w != 1.0) { r0.x += separation * (r0.w - convergence); }

  r0.y = cb1[5].x * r0.y;
  r1.xzw = float3(0.5,0.5,0.5) * r0.xwy;
  o3.w = r0.w;
  o3.xy = r1.xw + r1.zz;
  r0.x = cb2[5].z * v0.y;
  r0.x = cb2[4].z * v0.x + r0.x;
  r0.x = cb2[6].z * v0.z + r0.x;
  r0.x = cb2[7].z * v0.w + r0.x;
  o3.z = -r0.x;
  return;
}
