// hlsltool.py -I ../.. --auto-fix-vertex-halo --fix-unity-reflection --fix-unity-frustum-world --only-autofixed --fxc /home/Ryan/fxc.exe 980bf44be09397cf-vs_replace.txt
// 3DMigoto: 980bf44be09397cf |    Unity headers extracted from HeightDepthOfField.shader
//    Shader "Hidden/HeightDepthOfField" {
//      Properties {
//       _MainTex ("Base", 2D) = "" { }
//       _TapLowBackground ("TapLowBackground", 2D) = "" { }
//       _TapLowForeground ("TapLowForeground", 2D) = "" { }
//       _TapMedium ("TapMedium", 2D) = "" { }
//      }
//      Fallback Off
//      SubShader 1/1 {
//        Pass 4/7 {
//          ZTest Always
//          ZWrite Off
//          Cull Off
//          ColorMask A
//          GpuProgramID 218241
//          Program "vp" {
//            SubProgram "d3d11 " {
//              GpuProgramIndex 13
//            }
//          }
//        }
//      }
//    }
//
// Unity 5.3 headers extracted from HeightDepthOfField.shader.decompressed:
//   API d3d11
//   Shader model vs_4_0
//   undeciphered1: 7 0 0
//   undeciphered2: 1 0 2 0 0
//   undeciphered3: 9 2 0 0 3 4
//   ConstBuffer "$Globals" 224
//   Matrix 112 [_FrustumCornersWS]
//   ConstBuffer "UnityPerDraw" 352
//   Matrix 0 [glstate_matrix_mvp]
//   BindCB "$Globals" 0
//   BindCB "UnityPerDraw" 1
//
// 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.30 on Thu Aug 18 03:38:37 2016
cbuffer cb1 : register(b1)
{
  float4 cb1[4];
}

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




// 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
}


cbuffer UnityPerCamera : register(b13)
{
	// Time (t = time since current level load) values from Unity
	uniform float4 _Time; // (t/20, t, t*2, t*3)
	uniform float4 _SinTime; // sin(t/8), sin(t/4), sin(t/2), sin(t)
	uniform float4 _CosTime; // cos(t/8), cos(t/4), cos(t/2), cos(t)
	uniform float4 unity_DeltaTime; // dt, 1/dt, smoothdt, 1/smoothdt

	uniform float3 _WorldSpaceCameraPos;

	// x = 1 or -1 (-1 if projection is flipped)
	// y = near plane
	// z = far plane
	// w = 1/far plane
	uniform float4 _ProjectionParams;

	// x = width
	// y = height
	// z = 1 + 1.0/width
	// w = 1 + 1.0/height
	uniform float4 _ScreenParams;

	// Values used to linearize the Z buffer (http://www.humus.name/temp/Linearize%20depth.txt)
	// x = 1-far/near
	// y = far/near
	// z = x/far
	// w = y/far
	uniform float4 _ZBufferParams;

	// x = orthographic camera's width
	// y = orthographic camera's height
	// z = unused
	// w = 1.0 if camera is ortho, 0.0 if perspective
	uniform float4 unity_OrthoParams;
}


#include <matrix.hlsl>

void main( 
  float4 v0 : POSITION0,
  float2 v1 : TEXCOORD0,
  out float4 o0 : SV_Position0,
  out float4 o1 : TEXCOORD0,
  out float3 o2 : TEXCOORD1)
{
  const float4 icb[] = { { 1.000000, 0, 0, 0},
                              { 0, 1.000000, 0, 0},
                              { 0, 0, 1.000000, 0},
                              { 0, 0, 0, 1.000000} };
  float4 r0;
  uint4 bitmask, uiDest;
  float4 fDest;

float4 stereo = StereoParams.Load(0);
float separation = stereo.x, convergence = stereo.y, eye = stereo.z;

// Unity _FrustumCornersWS fix inserted with DarkStarSword's hlsltool.py:
// hlsltool.py -I ../.. --auto-fix-vertex-halo --fix-unity-reflection --fix-unity-frustum-world --only-autofixed --fxc /home/Ryan/fxc.exe 980bf44be09397cf-vs_replace.txt
float far = 1 / (_ZBufferParams.z + _ZBufferParams.w);
float4 clip_space_adj = float4(separation * (far - 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);
// GOTCHA: _FrustumCornersWS is TRANSPOSED vs DX9!
float4x4 _FrustumCornersWS = matrix(cb0[7], cb0[8], cb0[9], cb0[10]);
_FrustumCornersWS[0].xyz -= world_space_adj.x;
_FrustumCornersWS[1].xyz -= world_space_adj.y;
_FrustumCornersWS[2].xyz -= world_space_adj.z;

  r0.xyzw = cb1[1].xyzw * v0.yyyy;
  r0.xyzw = cb1[0].xyzw * v0.xxxx + r0.xyzw;
  r0.xyzw = cb1[2].xyzw * float4(0.100000001,0.100000001,0.100000001,0.100000001) + r0.xyzw;
  o0.xyzw = cb1[3].xyzw * v0.wwww + r0.xyzw;
  o1.xy = v1.xy;
  r0.x = (int)v0.z;
  o2.x = dot(_FrustumCornersWS[0].xyzw, icb[r0.x+0].xyzw);
  o2.y = dot(_FrustumCornersWS[1].xyzw, icb[r0.x+0].xyzw);
  o2.z = dot(_FrustumCornersWS[2].xyzw, icb[r0.x+0].xyzw);
  return;
}

/****************************** COMPILE WARNINGS ******************************
X:\SteamLibrary\steamapps\common\I am weapon Revival\ShaderFixes\980bf44be09397cf-vs_replace.txt(122,14-15): warning X3578: Output value 'o1' is not completely initialized

****************************** COMPILE WARNINGS ******************************/
