// hlsltool.py -I ../112 --auto-fix-vertex-halo --fix-unity-reflection --only-autofixed --no-validate --ignore-other-errors 7e586533ad5cde35-vs_replace.txt
// 3DMigoto: 7e586533ad5cde35 |    Unity headers extracted from PF_Snow.shader
//    Shader "ParticleField/Snow" {
//      Properties {
//       _Color ("Color", Color) = (1,1,1,1)
//       _MainTex ("Texture Image", 2D) = "white" { }
//      }
//      SubShader 1/1 {
//        Tags { "QUEUE"="Transparent" "IGNOREPROJECTOR"="true" "RenderType"="Transparent" }
//        Pass 1/1 {
//          Tags { "QUEUE"="Transparent" "IGNOREPROJECTOR"="true" "RenderType"="Transparent" }
//          ZWrite Off
//          Blend SrcAlpha OneMinusSrcAlpha
//          GpuProgramID 56599
//          Program "vp" {
//            SubProgram "d3d11 " {
//              GpuProgramIndex 1
//            }
//          }
//        }
//      }
//    }
//
// Unity 5.3 headers extracted from PF_Snow.shader.decompressed:
//   API d3d11
//   Shader model vs_4_0
//   undeciphered1: 201509030 123 0 0
//   undeciphered2: 1 0 4 0 0
//   undeciphered3: 31 5 0 0 2 1 1 2 3 4 4 5
//   ConstBuffer "$Globals" 608
//   Float 100 [_Editor]
//   Float 104 [_UserFacing]
//   Float 108 [_EdgeAlpha]
//   Float 112 [_EdgeScale]
//   Vector 116 [_ParticleSize] 2
//   Vector 128 [_FieldSize] 3
//   Vector 144 [_Speed] 3
//   Float 156 [_SpinSpeed]
//   Vector 160 [_Force] 3
//   Float 176 [_UOffset]
//   Vector 180 [_EdgeThreshold] 3
//   Vector 192 [_FaceDirection] 3
//   Vector 208 [_UpDirection] 3
//   Float 224 [_CountMask]
//   Float 284 [_NearFadeDistance]
//   Float 288 [_NearFadeOffset]
//   Vector 496 [_ExclusionThreshold0] 3
//   Vector 512 [_ExclusionThreshold1] 3
//   Vector 528 [_ExclusionThreshold2] 3
//   Matrix 304 [_ExclusionMatrix0]
//   Matrix 368 [_ExclusionMatrix1]
//   Matrix 432 [_ExclusionMatrix2]
//   ConstBuffer "UnityPerCamera" 144
//   Vector 0 [_Time]
//   Vector 64 [_WorldSpaceCameraPos] 3
//   ConstBuffer "UnityPerDraw" 352
//   Matrix 192 [_Object2World]
//   ConstBuffer "UnityPerFrame" 256
//   Matrix 144 [unity_MatrixVP]
//   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:29:46 2017
cbuffer cb3 : register(b3)
{
  float4 cb3[13];
}

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

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

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




// 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 float2 o2 : TEXCOORD1,
  out float4 o3 : COLOR0)
{
  float4 r0,r1,r2,r3,r4,r5,r6;
  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 7e586533ad5cde35-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.xyz = float3(1,1,1) + -cb0[32].xyz;
  r0.w = dot(v0.xyz, v0.xyz);
  r0.w = rsqrt(r0.w);
  r1.xyz = v0.xyz * r0.www;
  r1.xyz = v2.xxx * r1.xyz;
  r1.xyz = r1.xyz * cb0[9].xyz + cb0[10].xyz;
  r0.w = -1 + cb1[0].y;
  r0.w = cb0[6].y * r0.w + 1;
  r1.xyz = r1.xyz * r0.www + v0.xyz;
  r0.w = cb0[9].w * r0.w;
  r0.w = v2.y * r0.w;
  sincos(r0.w, r2.x, r3.x);
  r2.yzw = cb2[15].xyz / cb0[8].xyz;
  r1.xyz = r2.yzw + r1.xyz;
  r1.xyz = frac(r1.xyz);
  r1.xyz = float3(0.5,0.5,0.5) + -r1.xyz;
  r2.yzw = r1.xyz * cb0[8].xyz + cb2[15].xyz;
  r3.yzw = cb0[24].xyz * r2.zzz;
  r3.yzw = cb0[23].xyz * r2.yyy + r3.yzw;
  r3.yzw = cb0[25].xyz * r2.www + r3.yzw;
  r3.yzw = cb0[26].xyz + r3.yzw;
  r3.yzw = -cb0[32].xyz + abs(r3.yzw);
  r3.yzw = -cb0[32].xyz + r3.yzw;
  r0.xyz = r3.yzw / r0.xyz;
  r0.xyz = float3(1,1,1) + -r0.xyz;
  r0.x = min(1, r0.x);
  r0.x = min(r0.y, r0.x);
  r0.x = min(r0.z, r0.x);
  r0.x = max(0, r0.x);
  r0.yzw = cb0[20].xyz * r2.zzz;
  r0.yzw = cb0[19].xyz * r2.yyy + r0.yzw;
  r0.yzw = cb0[21].xyz * r2.www + r0.yzw;
  r0.yzw = cb0[22].xyz + r0.yzw;
  r0.yzw = -cb0[31].xyz + abs(r0.yzw);
  r3.yzw = float3(1,1,1) + -cb0[31].xyz;
  r0.yzw = r0.yzw / r3.yzw;
  r0.xyzw = float4(1,1,1,1) + -r0.xyzw;
  r0.y = min(1, r0.y);
  r0.y = min(r0.z, r0.y);
  r0.y = min(r0.w, r0.y);
  r0.y = max(0, r0.y);
  r0.y = 1 + -r0.y;
  r0.x = min(r0.x, r0.y);
  r0.yzw = cb0[28].xyz * r2.zzz;
  r0.yzw = cb0[27].xyz * r2.yyy + r0.yzw;
  r0.yzw = cb0[29].xyz * r2.www + r0.yzw;
  r0.yzw = cb0[30].xyz + r0.yzw;
  r0.yzw = -cb0[33].xyz + abs(r0.yzw);
  r3.yzw = float3(1,1,1) + -cb0[33].xyz;
  r0.yzw = r0.yzw / r3.yzw;
  r0.yzw = float3(1,1,1) + -r0.yzw;
  r0.y = min(1, r0.y);
  r0.y = min(r0.z, r0.y);
  r0.y = min(r0.w, r0.y);
  r0.y = max(0, r0.y);
  r0.y = 1 + -r0.y;
  r0.x = min(r0.y, r0.x);
  r0.yz = abs(r1.xz) + abs(r1.xz);
  r0.w = abs(r1.y) * 2 + -cb0[11].z;
  r0.y = dot(r0.yz, r0.yz);
  r0.y = sqrt(r0.y);
  r0.y = -cb0[11].y + r0.y;
  r1.xy = float2(1,1) + -cb0[11].yz;
  r0.yz = r0.yw / r1.xy;
  r0.yz = float2(1,1) + -r0.yz;
  r0.y = min(1, r0.y);
  r0.y = min(r0.z, r0.y);
  r0.y = max(0, r0.y);
  r0.z = r0.y * r0.x;
  r0.x = r0.y * r0.x + -1;
  r0.y = ceil(r0.z);
  r0.z = cb0[7].x * r0.x + 1;
  r0.x = cb0[6].w * r0.x + 1;
  r0.x = v7.w * r0.x;
  r0.y = r0.z * r0.y;
  r0.z = cb0[14].x + v2.z;
  r0.z = floor(r0.z);
  r0.y = r0.y * r0.z;
  r1.xyz = _WorldSpaceCameraPos.zxy + -r2.wyz;
  r0.z = dot(r1.xyz, r1.xyz);
  r0.z = rsqrt(r0.z);
  r3.yzw = r1.xyz * r0.zzz;
  r1.xyz = -r1.xyz * r0.zzz + cb0[12].zxy;
  r1.xyz = cb0[6].zzz * r1.xyz + r3.yzw;
  r3.yzw = cb0[13].yzx * r1.xyz;
  r3.yzw = r1.zxy * cb0[13].zxy + -r3.yzw;
  r4.xyz = r1.xyz * r2.xxx;
  r5.xyz = r4.yzx * r3.wyz;
  r5.xyz = r4.xyz * r3.yzw + -r5.xyz;
  r5.xyz = r3.xxx * r3.zwy + r5.xyz;
  r6.xyz = r5.xyz * r4.xyz;
  r4.xyz = r4.zxy * r5.yzx + -r6.xyz;
  r3.xyz = r4.xyz * float3(2,2,2) + r3.yzw;
  r4.xyz = r3.yzx * r1.xyz;
  r1.xyz = r1.zxy * r3.zxy + -r4.xyz;
  r0.z = dot(r1.xyz, r1.xyz);
  r0.w = rsqrt(r0.z);
  r0.z = sqrt(r0.z);
  r1.xyz = r1.xyz * r0.www;
  r0.w = min(cb0[7].y, cb0[7].z);
  r4.xy = r0.ww / cb0[7].yz;
  r0.z = max(r4.y, r0.z);
  r1.xyz = r1.xyz * r0.zzz;
  r1.xyz = r1.xyz * r0.yyy;
  r1.xyz = cb0[7].zzz * r1.xyz;
  r0.z = dot(r3.xyz, r3.xyz);
  r0.w = rsqrt(r0.z);
  r0.z = sqrt(r0.z);
  r0.z = max(r0.z, r4.x);
  r3.xyz = r3.xyz * r0.www;
  r3.xyz = r3.xyz * r0.zzz;
  r0.yzw = r3.xyz * r0.yyy;
  r0.yzw = cb0[7].yyy * r0.yzw;
  r1.w = -0.5 + v4.x;
  r0.yzw = r0.yzw * r1.www + r2.yzw;
  r1.w = 0.5 + -v4.y;
  r0.yzw = r1.xyz * r1.www + r0.yzw;
  r1.xyzw = cb3[10].xyzw * r0.zzzz;
  r1.xyzw = cb3[9].xyzw * r0.yyyy + r1.xyzw;
  r1.xyzw = cb3[11].xyzw * r0.wwww + r1.xyzw;
  o1.xyz = r0.yzw;
  r1.xyzw = cb3[12].xyzw + r1.xyzw;
  o0.xyzw = r1.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 7e586533ad5cde35-vs_replace.txt
if (r1.w != 1.0) { r1.x += separation * (r1.w - convergence); }

  r0.y = saturate(r1.z * cb0[17].w + -cb0[18].x);
  o3.w = r0.x * r0.y;
  o1.w = 1;
  o2.x = cb0[11].x + v3.x;
  o2.y = v3.y;
  o3.xyz = v7.xyz;
  return;
}
