// hlsltool.py -I ../112 --auto-fix-vertex-halo --fix-unity-reflection --only-autofixed --no-validate --ignore-other-errors d4dae06ce4abeb2e-vs_replace.txt
// 3DMigoto: d4dae06ce4abeb2e | Matched 4 variants of 1 shaders: MyParticles/Lit MultiLight Soft
//
//       Unity headers extracted from Particles_Lit_MultiLightSoft.shader
//       Shader "MyParticles/Lit MultiLight Soft" {
//         Properties {
//          _TintColor ("Tint Color", Color) = (0.5,0.5,0.5,0.5)
//          _MainTex ("Base (RGB)", 2D) = "white" { }
//          _InvFade ("Soft Particles Factor", Range(0.01,3)) = 1
//          _Thickness ("Thickness Factor", Range(0,1)) = 0.05
//          _BackLight ("Backlight Power", Range(0.5,6)) = 2
//          _Cutoff ("Alpha cutoff", Range(0,1)) = 0.5
//          _FadeStart ("Distance fade start", Float) = 10
//          _FadeEnd ("Distance fade end", Float) = 50
//          _FadeMin ("Distance fade min", Range(0,1)) = 0.1
//         }
//         Fallback "Hidden/MyParticles/Lit Alpha Blend Shadow Fallback"
//         SubShader 1/1 {
//           Tags { "QUEUE"="Transparent" "IGNOREPROJECTOR"="true" "RenderType"="Transparent" }
//           Pass 2/2 {
//             Name "FORWARD"
//             Tags { "LIGHTMODE"="ForwardAdd" "QUEUE"="Transparent" "IGNOREPROJECTOR"="true" "RenderType"="Transparent" }
//             ZWrite Off
//             Blend SrcAlpha One
//             ColorMask RGB
//             GpuProgramID 91147
//             Program "vp" {
//               SubProgram "d3d11_9x " {
// 1:              GpuProgramIndex 11
// 2:              GpuProgramIndex 17
// 4:              GpuProgramIndex 20
// 8:              GpuProgramIndex 23
//               }
//             }
//           }
//         }
//       }
//
//    Unity 5.3 headers extracted from Particles_Lit_MultiLightSoft.shader.decompressed:
//      API d3d11_9x
//      Shader model vs_4_0_level_9_1
//      undeciphered1: 201509030 38 0 0
// 8:   Keywords { "DIRECTIONAL_COOKIE" }
// 1:   Keywords { "POINT" }
// 4:   Keywords { "POINT_COOKIE" }
// 2:   Keywords { "SPOT" }
//      undeciphered2: 1 0 3 0 0
//      undeciphered3: 15 4 0 0 2 1 1 2 3 4
//      ConstBuffer "$Globals" 336
//      Float 272 [_FadeStart]
//      Float 276 [_FadeEnd]
//      Float 280 [_FadeMin]
//      Vector 320 [_MainTex_ST]
//      ConstBuffer "UnityPerCamera" 144
//      Vector 64 [_WorldSpaceCameraPos] 3
//      Vector 80 [_ProjectionParams]
//      ConstBuffer "UnityPerDraw" 352
//      Matrix 0 [glstate_matrix_mvp]
//      Matrix 64 [glstate_matrix_modelview0]
//      Matrix 192 [_Object2World]
//      Matrix 256 [_World2Object]
//      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:33:48 2017
cbuffer cb2 : register(b2)
{
  float4 cb2[22];
}

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

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




// 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 float p1 : TEXCOORD5,
  out float4 o2 : TEXCOORD1,
  out float3 o3 : TEXCOORD2,
  out float4 o4 : COLOR0,
  out float4 o5 : TEXCOORD3,
  out float4 o6 : TEXCOORD4)
{
  float4 r0,r1,r2;
  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 d4dae06ce4abeb2e-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.xyzw = cb2[1].xyzw * v0.yyyy;
  r0.xyzw = cb2[0].xyzw * v0.xxxx + r0.xyzw;
  r0.xyzw = cb2[2].xyzw * v0.zzzz + r0.xyzw;
  r0.xyzw = cb2[3].xyzw * v0.wwww + r0.xyzw;
  o0.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 d4dae06ce4abeb2e-vs_replace.txt
if (r0.w != 1.0) { r0.x += separation * (r0.w - convergence); }

  r1.xyz = cb2[13].xyz * v0.yyy;
  r1.xyz = cb2[12].xyz * v0.xxx + r1.xyz;
  r1.xyz = cb2[14].xyz * v0.zzz + r1.xyz;
  r1.xyz = cb2[15].xyz * v0.www + r1.xyz;
  r2.xyz = _WorldSpaceCameraPos.xyz + -r1.xyz;
  o3.xyz = r1.xyz;
  r1.x = dot(r2.xyz, r2.xyz);
  r1.x = sqrt(r1.x);
  r1.x = -cb0[17].y + r1.x;
  r1.y = cb0[17].x + -cb0[17].y;
  r1.x = saturate(r1.x / r1.y);
  p1.x = max(cb0[17].z, r1.x);
  o1.xy = v3.xy * cb0[20].xy + cb0[20].zw;
  r1.x = cb2[16].x * v2.x;
  r1.y = cb2[17].x * v2.x;
  r1.z = cb2[18].x * v2.x;
  r2.x = cb2[16].y * v2.y;
  r2.y = cb2[17].y * v2.y;
  r2.z = cb2[18].y * v2.y;
  r1.xyz = r2.xyz + r1.xyz;
  r2.x = cb2[16].z * v2.z;
  r2.y = cb2[17].z * v2.z;
  r2.z = cb2[18].z * v2.z;
  r1.xyz = r2.xyz + r1.xyz;
  r1.w = dot(r1.xyz, r1.xyz);
  r1.w = rsqrt(r1.w);
  o2.xyz = r1.xyz * r1.www;
  o4.xyzw = v7.xyzw;
  o5.xyzw = r0.xyzw;
  r0.y = cb1[5].x * r0.y;
  r1.xzw = float3(0.5,0.5,0.5) * r0.xwy;
  o6.w = r0.w;
  o6.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;
  o6.z = -r0.x;
  return;
}
