// 3DMigoto: 2917d6a2498642c6 | Matched 4 variants of 1 shaders: Hidden/Internal-ScreenSpaceShadows
//
//       Unity headers extracted from Hidden_Internal-ScreenSpaceShadows
//       Shader "Hidden/Internal-ScreenSpaceShadows" {
//    1:   SubShader 1/4 {
//    2:   SubShader 2/4 {
//    4:   SubShader 3/4 {
//    8:   SubShader 4/4 {
//    1:     Tags { "ShadowmapFilter"="HardShadow" }
//    2:     Tags { "ShadowmapFilter"="HardShadow_FORCE_INV_PROJECTION_IN_PS" }
//    4:     Tags { "ShadowmapFilter"="PCF_5x5" }
//    8:     Tags { "ShadowmapFilter"="PCF_5x5_FORCE_INV_PROJECTION_IN_PS" }
//           Pass 1/1 {
//    1:       Tags { "ShadowmapFilter"="HardShadow" }
//    2:       Tags { "ShadowmapFilter"="HardShadow_FORCE_INV_PROJECTION_IN_PS" }
//    4:       Tags { "ShadowmapFilter"="PCF_5x5" }
//    8:       Tags { "ShadowmapFilter"="PCF_5x5_FORCE_INV_PROJECTION_IN_PS" }
//             ZWrite Off
//             Program "vp" {
//               SubProgram "d3d11" {
//               }
//             }
//           }
//         }
//       }
//
//    Unity 5.3 headers extracted from Hidden_Internal-ScreenSpaceShadows:
//      API d3d11
//      Shader model vs_4_0
//      undeciphered1: 201609010 19 0 0
//      undeciphered1a: 2
// 4:   Keywords { "SHADOWS_SINGLE_CASCADE" }
// 8:   Keywords { "SHADOWS_SPLIT_SPHERES" "SHADOWS_SINGLE_CASCADE" }
// 2:   Keywords { "SHADOWS_SPLIT_SPHERES" }
//      undeciphered2: 1 0 4 0 0 0
//      undeciphered3: 25 3 0 0 3 4 4 5
//      ConstBuffer "UnityPerCamera" 144
//      Vector 80 [_ProjectionParams]
//      ConstBuffer "UnityPerCameraRare" 352
//      Matrix 160 [unity_CameraInvProjection]
//      ConstBuffer "UnityPerDraw" 160
//      Matrix 0 [unity_ObjectToWorld]
//      ConstBuffer "UnityPerFrame" 384
//      Matrix 272 [unity_MatrixVP]
//      BindCB "UnityPerCamera" 0
//      BindCB "UnityPerCameraRare" 1
//      BindCB "UnityPerDraw" 2
//      BindCB "UnityPerFrame" 3
//
// Headers extracted with DarkStarSword's extract_unity55_shaders.py
// https://github.com/DarkStarSword/3d-fixes

// ---- Created with 3Dmigoto v1.2.65 on Thu Jan 25 16:54:16 2018
cbuffer cb3 : register(b3)
{
  float4 cb3[21];
}

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

// UnityPerCameraRare contains the projection & inverse projection matrices
// that we need to fix the shadows. The headers extracted from the asset files
// show which constant buffer is UnityPerCameraRare, and then we just grab the
// actual definition of the buffer from the Unity Cg source code, and replace
// references to it as necessary.

// cbuffer cb1 : register(b1)
cbuffer UnityPerCameraRare : register(b1)
{
  // float4 cb1[14];
  uniform float4 unity_CameraWorldClipPlanes[6];

  // Projection matrices of the camera. Note that this might be different from projection matrix
  // that is set right now, e.g. while rendering shadows the matrices below are still the projection
  // of original camera.
  row_major uniform float4x4 unity_CameraProjection;	//  cb1[7] - cb1[10]
  row_major uniform float4x4 unity_CameraInvProjection;	// cb1[11] - cb1[14]
}

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




// 3Dmigoto declarations
#define cmp -
Texture1D<float4> IniParams : register(t120);
Texture2D<float4> StereoParams : register(t125);


void main( 
  float4 v0 : POSITION0,
  float4 v1 : TEXCOORD0,
  float3 v2 : TEXCOORD1,
  out float4 o0 : SV_POSITION0,
  out float4 o1 : TEXCOORD0,
  out float4 o2 : TEXCOORD1,
  out float4 o3 : TEXCOORD2,
  out float3 o4 : TEXCOORD3,
  out float fov : TEXCOORD4) // New output to pass FOV from inverse projection matrix to pixel shaders
{
  float4 r0,r1;
  uint4 bitmask, uiDest;
  float4 fDest;

  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 + r0.xyzw;
  r1.xyzw = cb3[18].xyzw * r0.yyyy;
  r1.xyzw = cb3[17].xyzw * r0.xxxx + r1.xyzw;
  r1.xyzw = cb3[19].xyzw * r0.zzzz + r1.xyzw;
  r0.xyzw = cb3[20].xyzw * r0.wwww + r1.xyzw;
  o0.xyzw = r0.xyzw;
  r0.y = cb0[5].x * r0.y;
  r1.xzw = float3(0.5,0.5,0.5) * r0.xwy;
  r0.yzw = unity_CameraInvProjection[0].xyz * r0.yyy;
  r0.xyz = unity_CameraProjection[3].xyz * r0.xxx + r0.yzw;
  o1.zw = r1.xw + r1.zz;
  o1.xy = v1.xy;
  o2.xyz = v2.xyz;
  r1.xyz = -unity_CameraInvProjection[1].xyz + r0.xyz;
  r0.xyz = unity_CameraInvProjection[1].xyz + r0.xyz;
  r0.xyz = unity_CameraInvProjection[2].xyz + r0.xyz;
  r1.xyz = unity_CameraInvProjection[2].xyz + r1.xyz;
  r1.w = -r1.z;
  o3.xyz = r1.xyw;
  r0.w = -r0.z;
  o4.xyz = r0.xyw;

fov = unity_CameraInvProjection[0].x;

  return;
}
