// 3DMigoto: 28a7271021d7155a | Matched 4 variants of 1 shaders: Hidden/ShadowSoftener-ScreenSpaceShadows
//
//       Unity headers extracted from Internal-PrePassCollectShadows.shader
//       Shader "Hidden/ShadowSoftener-ScreenSpaceShadows" {
//         Properties {
//          _ShadowMapTexture ("", any) = "" { }
//         }
//         Fallback "Hidden/Internal-ScreenSpaceShadows"
//         SubShader 1/4 {
//           Tags { "ShadowmapFilter"="HardShadow" }
//           Pass 1/1 {
//             Tags { "ShadowmapFilter"="HardShadow" }
//             ZTest Always
//             ZWrite Off
//             Cull Off
//             GpuProgramID 26885
//             Program "vp" {
//               SubProgram "d3d11 " {
// 1:              GpuProgramIndex 1
// 2:              GpuProgramIndex 3
// 4:              GpuProgramIndex 5
// 8:              GpuProgramIndex 7
//               }
//             }
//           }
//         }
//       }
//
//    Unity 5.3 headers extracted from Internal-PrePassCollectShadows.shader.decompressed:
//      API d3d11
//      Shader model vs_4_0
//      undeciphered1: 201510240 16 0 0
// 4:   Keywords { "SHADOWS_SINGLE_CASCADE" }
// 8:   Keywords { "SHADOWS_SPLIT_SPHERES" "SHADOWS_SINGLE_CASCADE" }
// 2:   Keywords { "SHADOWS_SPLIT_SPHERES" }
//      undeciphered2: 1 0 3 0 0 0
//      undeciphered3: 11 3 0 0 1 2 3 4
//      ConstBuffer "UnityPerCamera" 144
//      Vector 80 [_ProjectionParams]
//      ConstBuffer "UnityPerCameraRare" 352
//      Matrix 160 [unity_CameraInvProjection]
//      ConstBuffer "UnityPerDraw" 352
//      Matrix 0 [glstate_matrix_mvp]
//      BindCB "UnityPerCamera" 0
//      BindCB "UnityPerCameraRare" 1
//      BindCB "UnityPerDraw" 2
//
// Headers extracted with DarkStarSword's extract_unity53_shaders.py
// https://github.com/DarkStarSword/3d-fixes

// ---- Created with 3Dmigoto v1.2.61 on Thu Aug 17 01:04:41 2017
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,
  float2 v1 : TEXCOORD0,
  float3 v2 : NORMAL0,
  out float4 o0 : TEXCOORD0,
  out float4 o1 : TEXCOORD1,
  out float4 o2 : TEXCOORD2,
  out float3 o3 : TEXCOORD3,
  out float4 o4 : SV_POSITION0,
  out float fov : TEXCOORD4) // New output to pass FOV from inverse projection matrix to pixel shaders
{
  float4 r0,r1,r2;
  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.xz = float2(0.5,0.5) * r0.xw;
  r1.y = cb0[5].x * r0.y;
  r1.w = 0.5 * r1.y;
  r2.xyz = unity_CameraInvProjection[0].xyz * r1.yyy;
  r2.xyz = unity_CameraProjection[3].xyz * r0.xxx + r2.xyz;
  o4.xyzw = r0.xyzw;
  o0.zw = r1.xw + r1.zz;
  o0.xy = v1.xy;
  o1.xyz = v2.xyz;
  r0.xyz = -unity_CameraInvProjection[1].xyz + r2.xyz;
  r1.xyz = unity_CameraInvProjection[1].xyz + r2.xyz;
  r1.xyz = unity_CameraInvProjection[2].xyz + r1.xyz;
  r0.xyz = unity_CameraInvProjection[2].xyz + r0.xyz;
  r0.w = -r0.z;
  o2.xyz = r0.xyw;
  r1.w = -r1.z;
  o3.xyz = r1.xyw;

fov = unity_CameraInvProjection[0].x;

  return;
}
